( result: SymbolInformation[] | null, cwd?: string, )
| 369 | * Formats workspaceSymbol result (flat list of symbols) |
| 370 | */ |
| 371 | export function formatWorkspaceSymbolResult( |
| 372 | result: SymbolInformation[] | null, |
| 373 | cwd?: string, |
| 374 | ): string { |
| 375 | if (!result || result.length === 0) { |
| 376 | return 'No symbols found in workspace. This may occur if the workspace is empty, or if the LSP server has not finished indexing the project.' |
| 377 | } |
| 378 | |
| 379 | // Log and filter out any symbols with undefined location.uri |
| 380 | const invalidSymbols = result.filter( |
| 381 | sym => !sym || !sym.location || !sym.location.uri, |
| 382 | ) |
| 383 | if (invalidSymbols.length > 0) { |
| 384 | logForDebugging( |
| 385 | `formatWorkspaceSymbolResult: Filtering out ${invalidSymbols.length} invalid symbol(s) - this should have been caught earlier`, |
| 386 | { level: 'warn' }, |
| 387 | ) |
| 388 | } |
| 389 | |
| 390 | const validSymbols = result.filter( |
| 391 | sym => sym && sym.location && sym.location.uri, |
| 392 | ) |
| 393 | |
| 394 | if (validSymbols.length === 0) { |
| 395 | return 'No symbols found in workspace. This may occur if the workspace is empty, or if the LSP server has not finished indexing the project.' |
| 396 | } |
| 397 | |
| 398 | const lines: string[] = [ |
| 399 | `Found ${validSymbols.length} ${plural(validSymbols.length, 'symbol')} in workspace:`, |
| 400 | ] |
| 401 | |
| 402 | // Group by file |
| 403 | const byFile = groupByFile(validSymbols, cwd) |
| 404 | |
| 405 | for (const [filePath, symbols] of byFile) { |
| 406 | lines.push(`\n${filePath}:`) |
| 407 | for (const symbol of symbols) { |
| 408 | const kind = symbolKindToString(symbol.kind) |
| 409 | const line = symbol.location.range.start.line + 1 |
| 410 | let symbolLine = ` ${symbol.name} (${kind}) - Line ${line}` |
| 411 | |
| 412 | // Add container name if available |
| 413 | if (symbol.containerName) { |
| 414 | symbolLine += ` in ${symbol.containerName}` |
| 415 | } |
| 416 | |
| 417 | lines.push(symbolLine) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | return lines.join('\n') |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Formats a CallHierarchyItem with its location |
no test coverage detected