MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parseWithinBudget

Function parseWithinBudget

src/extraction/parse-budget.ts:66–73  ·  view source on GitHub ↗
(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS)

Source from the content-addressed store, hash-verified

64 * of whatever file that is.
65 */
66export function parseWithinBudget(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS): Tree | null {
67 const deadline = Date.now() + budgetMs;
68 // The runtime hands the callback's return value to the parser: `true` cancels.
69 const cancel = (() => Date.now() > deadline) as unknown as () => void;
70 const tree = parser.parse(source, null, { progressCallback: cancel }) ?? null;
71 if (!tree) parser.reset();
72 return tree;
73}
74
75/** The message a parse that ran past its budget records, as the parse pool words its own timeout. */
76export function parseTimeoutMessage(budgetMs: number): string {

Callers 5

extractTagBasedMethod · 0.90
extractMethod · 0.90
tokenizeRegionFunction · 0.90
parseFunction · 0.90
guardsForFileSyncFunction · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected