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

Function formatDocumentSymbolResult

src/tools/LSPTool/formatters.ts:340–366  ·  view source on GitHub ↗
(
  result: DocumentSymbol[] | SymbolInformation[] | null,
  cwd?: string,
)

Source from the content-addressed store, hash-verified

338 * per LSP spec which allows textDocument/documentSymbol to return either format
339 */
340export function formatDocumentSymbolResult(
341 result: DocumentSymbol[] | SymbolInformation[] | null,
342 cwd?: string,
343): string {
344 if (!result || result.length === 0) {
345 return 'No symbols found in document. This may occur if the file is empty, not supported by the LSP server, or if the server has not fully indexed the file.'
346 }
347
348 // Detect format: DocumentSymbol has 'range' directly, SymbolInformation has 'location.range'
349 // Check the first valid element to determine format
350 const firstSymbol = result[0]
351 const isSymbolInformation = firstSymbol && 'location' in firstSymbol
352
353 if (isSymbolInformation) {
354 // Delegate to workspace symbol formatter which handles SymbolInformation[]
355 return formatWorkspaceSymbolResult(result as SymbolInformation[], cwd)
356 }
357
358 // Handle DocumentSymbol[] format (hierarchical)
359 const lines: string[] = ['Document symbols:']
360
361 for (const symbol of result as DocumentSymbol[]) {
362 lines.push(...formatDocumentSymbolNode(symbol))
363 }
364
365 return lines.join('\n')
366}
367
368/**
369 * Formats workspaceSymbol result (flat list of symbols)

Callers 1

formatResultFunction · 0.85

Calls 3

formatDocumentSymbolNodeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected