Compare commits
3 Commits
04fd520438
...
f811efef68
| Author | SHA1 | Date | |
|---|---|---|---|
| f811efef68 | |||
| 01ab10a7d9 | |||
| 99525ad0ee |
25
index.ts
25
index.ts
@@ -68,13 +68,20 @@ function formatReferences(result: unknown): string {
|
||||
if (!result || !Array.isArray(result)) 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) => {
|
||||
const file = uriToPath(loc.uri);
|
||||
const range = loc.range;
|
||||
return `${i + 1}. ${file} (${range.start.line + 1}:${range.start.character + 1})`;
|
||||
})
|
||||
.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.
|
||||
@@ -194,7 +201,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 +219,12 @@ function formatDiagnostics(result: unknown): string {
|
||||
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) => {
|
||||
const sev = severityNames[d.severity] ?? `sev:${d.severity}`;
|
||||
const range = d.range;
|
||||
@@ -222,6 +234,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 +522,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)") {
|
||||
|
||||
Reference in New Issue
Block a user