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

Function parseTokensWithLimits

packages/code-map/src/parse.ts:182–235  ·  view source on GitHub ↗
(
  filePath: string,
  languageConfig: LanguageConfig,
  readFile: ((filePath: string) => string | null) | undefined,
  options: ParseTokensOptions,
)

Source from the content-addressed store, hash-verified

180}
181
182function parseTokensWithLimits(
183 filePath: string,
184 languageConfig: LanguageConfig,
185 readFile: ((filePath: string) => string | null) | undefined,
186 options: ParseTokensOptions,
187): ParsedTokensForScoring {
188 const { parser, query } = languageConfig
189
190 try {
191 const maxBytes = options.maxBytes ?? MAX_PARSE_FILE_BYTES
192 const remainingBytes = options.remainingBytes ?? MAX_TOTAL_PARSE_BYTES
193 if (remainingBytes <= 0) {
194 return emptyParsedTokens(true)
195 }
196
197 const source = loadSourceWithinLimits({
198 filePath,
199 readFile,
200 maxBytes,
201 remainingBytes,
202 })
203 if (!source) {
204 return emptyParsedTokens(true)
205 }
206
207 if (!parser || !query) {
208 throw new Error('Parser or query not found')
209 }
210
211 const parseResults = parseFile(parser, query, source.code)
212 const identifiers = Array.from(new Set(parseResults.identifier))
213 const calls = Array.from(new Set(parseResults['call.identifier']))
214
215 if (DEBUG_PARSING) {
216 console.log(`\nParsing ${filePath}:`)
217 console.log('Identifiers:', identifiers)
218 console.log('Calls:', calls)
219 }
220
221 return {
222 numLines: countLines(source.code),
223 identifiers: identifiers ?? [],
224 calls: calls ?? [],
225 bytes: source.bytes,
226 skipped: false,
227 }
228 } catch (e) {
229 if (DEBUG_PARSING) {
230 console.error(`Error parsing query: ${e}`)
231 console.log(filePath)
232 }
233 return emptyParsedTokens(false)
234 }
235}
236
237function loadSourceWithinLimits(params: {
238 filePath: string

Callers 2

parseTokensFunction · 0.85
parseTokensForScoringFunction · 0.85

Calls 5

emptyParsedTokensFunction · 0.85
loadSourceWithinLimitsFunction · 0.85
parseFileFunction · 0.85
countLinesFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected