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

Function getFileTokenScores

packages/code-map/src/parse.ts:63–133  ·  view source on GitHub ↗
(
  projectRoot: string,
  filePaths: string[],
  readFile?: SourceReader,
)

Source from the content-addressed store, hash-verified

61}
62
63export async function getFileTokenScores(
64 projectRoot: string,
65 filePaths: string[],
66 readFile?: SourceReader,
67): Promise<FileTokenData> {
68 const startTime = Date.now()
69 const tokenScores: Record<string, Record<string, number>> = {}
70 const externalCalls: Record<string, number> = {}
71 const fileCallsMap = new Map<string, string[]>()
72 let parsedFiles = 0
73 let totalParsedBytes = 0
74
75 for (const filePath of filePaths) {
76 if (
77 parsedFiles >= MAX_PARSE_FILES ||
78 totalParsedBytes >= MAX_TOTAL_PARSE_BYTES
79 ) {
80 break
81 }
82
83 const fullPath = path.join(projectRoot, filePath)
84 const languageConfig = await getLanguageConfig(fullPath)
85 if (!languageConfig) continue
86
87 const parsed = await parseTokensForScoring({
88 filePath,
89 fullPath,
90 languageConfig,
91 readFile,
92 remainingBytes: MAX_TOTAL_PARSE_BYTES - totalParsedBytes,
93 })
94 if (parsed.skipped) continue
95
96 parsedFiles++
97 totalParsedBytes += parsed.bytes
98
99 const { scores, calls } = scoreFileTokens(fullPath, parsed)
100 tokenScores[filePath] = scores
101 fileCallsMap.set(filePath, calls)
102
103 for (const call of calls) {
104 if (!scores[call]) {
105 externalCalls[call] = (externalCalls[call] ?? 0) + 1
106 }
107 }
108 }
109
110 const tokenCallers = buildTokenCallers(tokenScores, fileCallsMap)
111 boostScoresByExternalCalls(tokenScores, externalCalls)
112
113 if (DEBUG_PARSING) {
114 const endTime = Date.now()
115 console.log(`Parsed ${filePaths.length} files in ${endTime - startTime}ms`)
116
117 try {
118 fs.writeFileSync(
119 '../debug/debug-parse.json',
120 JSON.stringify({

Callers 4

parse.test.tsFile · 0.90
computeProjectIndexFunction · 0.90
getProjectFileContextFunction · 0.90

Calls 6

getLanguageConfigFunction · 0.90
parseTokensForScoringFunction · 0.85
scoreFileTokensFunction · 0.85
buildTokenCallersFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected