feat(diagnostics): cap diagnostic output with truncation notice
Add a limit parameter to formatDiagnostics (default 20 for explicit lsp_diagnostics calls, 10 for auto-check after edit/write). When truncated, a summary line indicates how many more diagnostics exist.
This commit is contained in:
12
index.ts
12
index.ts
@@ -194,7 +194,7 @@ function formatDocumentSymbols(result: unknown): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format Diagnostics - Turn diagnostic messages into readable text.
|
// Format Diagnostics - Turn diagnostic messages into readable text.
|
||||||
function formatDiagnostics(result: unknown): string {
|
function formatDiagnostics(result: unknown, limit = 20): string {
|
||||||
if (
|
if (
|
||||||
!result ||
|
!result ||
|
||||||
typeof result !== "object" ||
|
typeof result !== "object" ||
|
||||||
@@ -212,7 +212,8 @@ function formatDiagnostics(result: unknown): string {
|
|||||||
4: "Hint",
|
4: "Hint",
|
||||||
};
|
};
|
||||||
|
|
||||||
return diags
|
const shown = diags.slice(0, limit);
|
||||||
|
const formatted = shown
|
||||||
.map((d: any, i: number) => {
|
.map((d: any, i: number) => {
|
||||||
const sev = severityNames[d.severity] ?? `sev:${d.severity}`;
|
const sev = severityNames[d.severity] ?? `sev:${d.severity}`;
|
||||||
const range = d.range;
|
const range = d.range;
|
||||||
@@ -222,6 +223,11 @@ function formatDiagnostics(result: unknown): string {
|
|||||||
return `${i + 1}. [${sev}] ${d.message} (line ${line}, col ${col})`;
|
return `${i + 1}. [${sev}] ${d.message} (line ${line}, col ${col})`;
|
||||||
})
|
})
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
|
if (diags.length > limit) {
|
||||||
|
return `${formatted}\n\n... and ${diags.length - limit} more diagnostics (showing first ${limit})`;
|
||||||
|
}
|
||||||
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is Expected Error - Returns true if the error is an expected condition
|
// Is Expected Error - Returns true if the error is an expected condition
|
||||||
@@ -505,7 +511,7 @@ export default function (pi: ExtensionAPI) {
|
|||||||
try {
|
try {
|
||||||
// Run LSP diagnostics
|
// Run LSP diagnostics
|
||||||
const result = await runDiagnostics(absolutePath);
|
const result = await runDiagnostics(absolutePath);
|
||||||
const formatted = formatDiagnostics(result);
|
const formatted = formatDiagnostics(result, 10);
|
||||||
|
|
||||||
// Only send a message if there are actual diagnostics
|
// Only send a message if there are actual diagnostics
|
||||||
if (formatted !== "(no diagnostics)") {
|
if (formatted !== "(no diagnostics)") {
|
||||||
|
|||||||
Reference in New Issue
Block a user