( filePath: string, source: string, language: Language )
| 250 | * restores. |
| 251 | */ |
| 252 | export function tryKernelExtractRaw( |
| 253 | filePath: string, |
| 254 | source: string, |
| 255 | language: Language |
| 256 | ): KernelRawResult | null { |
| 257 | if (!kernelRoutes(language) || POST_PASSES[language]) return null; |
| 258 | const kernel = getKernel(); |
| 259 | if (!kernel) return null; |
| 260 | if (takeDeferredPreParse(filePath, source, language) !== null) return null; // already deferred |
| 261 | if (takeTimedOut(filePath, source, language) !== null) return null; // already timed out |
| 262 | const pre = preParsedSource(filePath, source, language); |
| 263 | // Its signatures come from the source as written, which needs the decoded path. |
| 264 | if (keepsReExportsAsWritten(source, pre, language)) return null; |
| 265 | const budgetMs = indexParseBudgetMs(pre.length); |
| 266 | try { |
| 267 | const buffers = kernel.extractFile(filePath, pre, language, budgetMs); |
| 268 | const meta = buffers.meta; |
| 269 | if (meta.readUInt8(LAYOUT_META.version) !== LAYOUT_ABI) { |
| 270 | throw new Error(`kernel buffer ABI ${meta.readUInt8(0)} != expected ${LAYOUT_ABI}`); |
| 271 | } |
| 272 | const counts = { |
| 273 | nodes: meta.readUInt32LE(LAYOUT_META.nodeCount), |
| 274 | edges: meta.readUInt32LE(LAYOUT_META.edgeCount), |
| 275 | refs: meta.readUInt32LE(LAYOUT_META.refCount), |
| 276 | }; |
| 277 | let errors: ExtractionResult['errors'] = []; |
| 278 | const errorsOff = meta.readUInt32LE(LAYOUT_META.errorsOff); |
| 279 | if (errorsOff !== LAYOUT_NONE) { |
| 280 | const errorsLen = meta.readUInt32LE(LAYOUT_META.errorsLen); |
| 281 | errors = JSON.parse( |
| 282 | buffers.arena.toString('utf8', errorsOff, errorsOff + errorsLen) |
| 283 | ) as ExtractionResult['errors']; |
| 284 | } |
| 285 | return { buffers, counts, errors }; |
| 286 | } catch (err) { |
| 287 | const message = err instanceof Error ? err.message : String(err); |
| 288 | if (message.includes('defer:')) { |
| 289 | deferSlot = { filePath, source, language, pre }; |
| 290 | return null; |
| 291 | } |
| 292 | // The decoded path (extractFromSource) records the timeout from the slot. |
| 293 | if (message.startsWith('timeout:')) { |
| 294 | timeoutSlot = { filePath, source, language, budgetMs }; |
| 295 | return null; |
| 296 | } |
| 297 | if (!warned.has(language)) { |
| 298 | warned.add(language); |
| 299 | process.stderr.write( |
| 300 | `[codegraph-kernel] ${language} extraction failed (${message}) — falling back to the wasm path\n` |
| 301 | ); |
| 302 | } |
| 303 | return null; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Decode a buffer-carrying result (see ExtractionResult.kernelBuffers) into a |
no test coverage detected