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

Function groupByFile

src/tools/LSPTool/formatters.ts:78–94  ·  view source on GitHub ↗

* Groups items by their file URI. * Generic helper that works with both Location[] and SymbolInformation[]

(
  items: T[],
  cwd?: string,
)

Source from the content-addressed store, hash-verified

76 * Generic helper that works with both Location[] and SymbolInformation[]
77 */
78function 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

Callers 2

Calls 4

formatUriFunction · 0.70
getMethod · 0.65
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected