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)") {