MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / buildTokenCallers

Function buildTokenCallers

packages/code-map/src/parse.ts:280–317  ·  view source on GitHub ↗
(
  tokenScores: Record<string, Record<string, number>>,
  fileCallsMap: Map<string, string[]>,
)

Source from the content-addressed store, hash-verified

278}
279
280function buildTokenCallers(
281 tokenScores: Record<string, Record<string, number>>,
282 fileCallsMap: Map<string, string[]>,
283): TokenCallerMap {
284 const tokenDefinitionMap = new Map<string, string>()
285 const highestScores = new Map<string, number>()
286
287 for (const [filePath, scores] of Object.entries(tokenScores)) {
288 for (const [token, score] of Object.entries(scores)) {
289 const currentHighestScore = highestScores.get(token) ?? -Infinity
290 if (score > currentHighestScore) {
291 highestScores.set(token, score)
292 tokenDefinitionMap.set(token, filePath)
293 }
294 }
295 }
296
297 const tokenCallers: TokenCallerMap = {}
298 for (const [callingFile, calls] of fileCallsMap.entries()) {
299 for (const call of calls) {
300 const definingFile = tokenDefinitionMap.get(call)
301 if (!definingFile || callingFile === definingFile || call in {}) {
302 continue
303 }
304
305 const callersByToken = (tokenCallers[definingFile] ??= {})
306 const callerFiles = (callersByToken[call] ??= [])
307 if (
308 callerFiles.length < MAX_CALLERS &&
309 !callerFiles.includes(callingFile)
310 ) {
311 callerFiles.push(callingFile)
312 }
313 }
314 }
315
316 return tokenCallers
317}
318
319function boostScoresByExternalCalls(
320 tokenScores: Record<string, Record<string, number>>,

Callers 1

getFileTokenScoresFunction · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected