MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatFindReferencesResult

Function formatFindReferencesResult

src/tools/LSPTool/formatters.ts:174–218  ·  view source on GitHub ↗
(
  result: Location[] | null,
  cwd?: string,
)

Source from the content-addressed store, hash-verified

172 * Formats findReferences result
173 */
174export function formatFindReferencesResult(
175 result: Location[] | null,
176 cwd?: string,
177): string {
178 if (!result || result.length === 0) {
179 return 'No references found. This may occur if the symbol has no usages, or if the LSP server has not fully indexed the workspace.'
180 }
181
182 // Log and filter out any locations with undefined uris
183 const invalidLocations = result.filter(loc => !loc || !loc.uri)
184 if (invalidLocations.length > 0) {
185 logForDebugging(
186 `formatFindReferencesResult: Filtering out ${invalidLocations.length} invalid location(s) - this should have been caught earlier`,
187 { level: 'warn' },
188 )
189 }
190
191 const validLocations = result.filter(loc => loc && loc.uri)
192
193 if (validLocations.length === 0) {
194 return 'No references found. This may occur if the symbol has no usages, or if the LSP server has not fully indexed the workspace.'
195 }
196
197 if (validLocations.length === 1) {
198 return `Found 1 reference:\n ${formatLocation(validLocations[0]!, cwd)}`
199 }
200
201 // Group references by file
202 const byFile = groupByFile(validLocations, cwd)
203
204 const lines: string[] = [
205 `Found ${validLocations.length} references across ${byFile.size} files:`,
206 ]
207
208 for (const [filePath, locations] of byFile) {
209 lines.push(`\n${filePath}:`)
210 for (const loc of locations) {
211 const line = loc.range.start.line + 1
212 const character = loc.range.start.character + 1
213 lines.push(` Line ${line}:${character}`)
214 }
215 }
216
217 return lines.join('\n')
218}
219
220/**
221 * Extracts text content from MarkupContent or MarkedString

Callers 1

formatResultFunction · 0.85

Calls 4

logForDebuggingFunction · 0.85
formatLocationFunction · 0.85
groupByFileFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected