Compare commits

...

3 Commits

Author SHA1 Message Date
f811efef68 fix(diagnostics): sort by severity before truncating
Errors appear first, then warnings, info, hints. Ensures the most
actionable issues survive the cap instead of being pushed out by
low-priority hints.
2026-05-02 20:24:35 -04:00
01ab10a7d9 feat(references): cap formatted references at 30 with truncation notice
Prevents flooding the context window when a common symbol has hundreds
of references. Shows the first 30 and appends a count of the remainder.
2026-05-02 20:24:27 -04:00
99525ad0ee 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.
2026-05-02 20:13:05 -04:00

View File

@@ -68,13 +68,20 @@ function formatReferences(result: unknown): string {
if (!result || !Array.isArray(result)) return "(no references found)"; if (!result || !Array.isArray(result)) return "(no references found)";
if (result.length === 0) return "(no references found)"; if (result.length === 0) return "(no references found)";
return result const limit = 30;
const shown = result.slice(0, limit);
const formatted = shown
.map((loc: any, i: number) => { .map((loc: any, i: number) => {
const file = uriToPath(loc.uri); const file = uriToPath(loc.uri);
const range = loc.range; const range = loc.range;
return `${i + 1}. ${file} (${range.start.line + 1}:${range.start.character + 1})`; return `${i + 1}. ${file} (${range.start.line + 1}:${range.start.character + 1})`;
}) })
.join("\n"); .join("\n");
if (result.length > limit) {
return `${formatted}\n\n... and ${result.length - limit} more references (showing first ${limit})`;
}
return formatted;
} }
// Format Completions - Turn completion items into readable text. // Format Completions - Turn completion items into readable text.
@@ -194,7 +201,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 +219,12 @@ function formatDiagnostics(result: unknown): string {
4: "Hint", 4: "Hint",
}; };
return diags // Sort By Severity - Errors first, then warnings, info, hints. Ensures
// the most actionable issues survive truncation.
diags.sort((a: any, b: any) => (a.severity ?? 99) - (b.severity ?? 99));
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 +234,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 +522,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)") {