From 99525ad0eec6c69c60f4f96700d2481e5fa92cc4 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Sat, 2 May 2026 20:13:05 -0400 Subject: [PATCH] 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. --- index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index a3cd603..c7a1083 100644 --- a/index.ts +++ b/index.ts @@ -194,7 +194,7 @@ function formatDocumentSymbols(result: unknown): string { } // Format Diagnostics - Turn diagnostic messages into readable text. -function formatDiagnostics(result: unknown): string { +function formatDiagnostics(result: unknown, limit = 20): string { if ( !result || typeof result !== "object" || @@ -212,7 +212,8 @@ function formatDiagnostics(result: unknown): string { 4: "Hint", }; - return diags + const shown = diags.slice(0, limit); + const formatted = shown .map((d: any, i: number) => { const sev = severityNames[d.severity] ?? `sev:${d.severity}`; const range = d.range; @@ -222,6 +223,11 @@ function formatDiagnostics(result: unknown): string { return `${i + 1}. [${sev}] ${d.message} (line ${line}, col ${col})`; }) .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 @@ -505,7 +511,7 @@ export default function (pi: ExtensionAPI) { try { // Run LSP diagnostics const result = await runDiagnostics(absolutePath); - const formatted = formatDiagnostics(result); + const formatted = formatDiagnostics(result, 10); // Only send a message if there are actual diagnostics if (formatted !== "(no diagnostics)") {