From 01ab10a7d97458c4b7c36406ced2308730e6304f Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Sat, 2 May 2026 20:24:27 -0400 Subject: [PATCH] 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. --- index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index c7a1083..fd070f3 100644 --- a/index.ts +++ b/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.