( result: DocumentSymbol[] | SymbolInformation[] | null, cwd?: string, )
| 338 | * per LSP spec which allows textDocument/documentSymbol to return either format |
| 339 | */ |
| 340 | export 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) |
no test coverage detected