* Groups items by their file URI. * Generic helper that works with both Location[] and SymbolInformation[]
( items: T[], cwd?: string, )
| 76 | * Generic helper that works with both Location[] and SymbolInformation[] |
| 77 | */ |
| 78 | function groupByFile<T extends { uri: string } | { location: { uri: string } }>( |
| 79 | items: T[], |
| 80 | cwd?: string, |
| 81 | ): Map<string, T[]> { |
| 82 | const byFile = new Map<string, T[]>() |
| 83 | for (const item of items) { |
| 84 | const uri = 'uri' in item ? item.uri : item.location.uri |
| 85 | const filePath = formatUri(uri, cwd) |
| 86 | const existingItems = byFile.get(filePath) |
| 87 | if (existingItems) { |
| 88 | existingItems.push(item) |
| 89 | } else { |
| 90 | byFile.set(filePath, [item]) |
| 91 | } |
| 92 | } |
| 93 | return byFile |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Formats a Location with file path and line/character position |
no test coverage detected