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.
This commit is contained in:
9
index.ts
9
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.
|
||||
|
||||
Reference in New Issue
Block a user