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 || !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)") {
|
||||||
|
|||||||
Reference in New Issue
Block a user