MCPcopy
hub / github.com/codeaashu/claude-code / formatGoToDefinitionResult

Function formatGoToDefinitionResult

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

Source from the content-addressed store, hash-verified

125 * Can return Location, LocationLink, or arrays of either
126 */
127export function formatGoToDefinitionResult(
128 result: Location | Location[] | LocationLink | LocationLink[] | null,
129 cwd?: string,
130): string {
131 if (!result) {
132 return 'No definition found. This may occur if the cursor is not on a symbol, or if the definition is in an external library not indexed by the LSP server.'
133 }
134
135 if (Array.isArray(result)) {
136 // Convert LocationLinks to Locations for uniform handling
137 const locations: Location[] = result.map(item =>
138 isLocationLink(item) ? locationLinkToLocation(item) : item,
139 )
140
141 // Log and filter out any locations with undefined uris
142 const invalidLocations = locations.filter(loc => !loc || !loc.uri)
143 if (invalidLocations.length > 0) {
144 logForDebugging(
145 `formatGoToDefinitionResult: Filtering out ${invalidLocations.length} invalid location(s) - this should have been caught earlier`,
146 { level: 'warn' },
147 )
148 }
149
150 const validLocations = locations.filter(loc => loc && loc.uri)
151
152 if (validLocations.length === 0) {
153 return 'No definition found. This may occur if the cursor is not on a symbol, or if the definition is in an external library not indexed by the LSP server.'
154 }
155 if (validLocations.length === 1) {
156 return `Defined in ${formatLocation(validLocations[0]!, cwd)}`
157 }
158 const locationList = validLocations
159 .map(loc => ` ${formatLocation(loc, cwd)}`)
160 .join('\n')
161 return `Found ${validLocations.length} definitions:\n${locationList}`
162 }
163
164 // Single result - convert LocationLink if needed
165 const location = isLocationLink(result)
166 ? locationLinkToLocation(result)
167 : result
168 return `Defined in ${formatLocation(location, cwd)}`
169}
170
171/**
172 * Formats findReferences result

Callers 1

formatResultFunction · 0.85

Calls 4

locationLinkToLocationFunction · 0.85
logForDebuggingFunction · 0.85
formatLocationFunction · 0.85
isLocationLinkFunction · 0.70

Tested by

no test coverage detected