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

Function tryKernelExtract

src/extraction/kernel/index.ts:315–352  ·  view source on GitHub ↗
(
  filePath: string,
  source: string,
  language: Language
)

Source from the content-addressed store, hash-verified

313 * only that file's speedup.
314 */
315export function tryKernelExtract(
316 filePath: string,
317 source: string,
318 language: Language
319): ExtractionResult | null {
320 if (!kernelRoutes(language)) return null;
321 const kernel = getKernel();
322 if (!kernel) return null;
323 if (takeDeferredPreParse(filePath, source, language) !== null) return null; // already deferred
324 const t0 = Date.now();
325 const pre = preParsedSource(filePath, source, language);
326 try {
327 const buffers = kernel.extractFile(filePath, pre, language);
328 const result = decodeExtractBuffers(buffers, filePath, language);
329 if (keepsReExportsAsWritten(source, pre, language)) restoreReExportSignatures(result, source);
330 POST_PASSES[language]?.(result, source);
331 // Read beside the tables, as TreeSitterExtractor does (a CommonJS `require`).
332 result.unresolvedReferences.push(...commonJsRequireRefs(filePath, source, language));
333 result.durationMs = Date.now() - t0;
334 return result;
335 } catch (err) {
336 const message = err instanceof Error ? err.message : String(err);
337 // `defer:` is the kernel's expected-routing signal (files with parse
338 // errors take the wasm path — its error RECOVERY is the canonical one;
339 // recovery differs between UTF-8 and UTF-16 parsing). Silent by design.
340 if (message.includes('defer:')) {
341 deferSlot = { filePath, source, language, pre };
342 return null;
343 }
344 if (!warned.has(language)) {
345 warned.add(language);
346 process.stderr.write(
347 `[codegraph-kernel] ${language} extraction failed (${message}) — falling back to the wasm path\n`
348 );
349 }
350 return null;
351 }
352}

Callers 15

extractFromSourceFunction · 0.90
extractFunction · 0.90
extractFunction · 0.90
extractFunction · 0.90
extractFunction · 0.90
extractFunction · 0.90
extractFunction · 0.90
assertParityFunction · 0.90
assertParityFunction · 0.90
extractFunction · 0.90

Calls 13

getKernelFunction · 0.90
decodeExtractBuffersFunction · 0.90
commonJsRequireRefsFunction · 0.90
kernelRoutesFunction · 0.85
takeDeferredPreParseFunction · 0.85
preParsedSourceFunction · 0.85
keepsReExportsAsWrittenFunction · 0.85
extractFileMethod · 0.80
pushMethod · 0.80
hasMethod · 0.80
writeMethod · 0.65

Tested by 15

extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
assertParityFunction · 0.72
assertParityFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72
extractFunction · 0.72