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