( filePath: string, source: string, language: Language )
| 234 | * restores. |
| 235 | */ |
| 236 | export function tryKernelExtractRaw( |
| 237 | filePath: string, |
| 238 | source: string, |
| 239 | language: Language |
| 240 | ): KernelRawResult | null { |
| 241 | if (!kernelRoutes(language) || POST_PASSES[language]) return null; |
| 242 | const kernel = getKernel(); |
| 243 | if (!kernel) return null; |
| 244 | if (takeDeferredPreParse(filePath, source, language) !== null) return null; // already deferred |
| 245 | const pre = preParsedSource(filePath, source, language); |
| 246 | // Its signatures come from the source as written, which needs the decoded path. |
| 247 | if (keepsReExportsAsWritten(source, pre, language)) return null; |
| 248 | try { |
| 249 | const buffers = kernel.extractFile(filePath, pre, language); |
| 250 | const meta = buffers.meta; |
| 251 | if (meta.readUInt8(LAYOUT_META.version) !== LAYOUT_ABI) { |
| 252 | throw new Error(`kernel buffer ABI ${meta.readUInt8(0)} != expected ${LAYOUT_ABI}`); |
| 253 | } |
| 254 | const counts = { |
| 255 | nodes: meta.readUInt32LE(LAYOUT_META.nodeCount), |
| 256 | edges: meta.readUInt32LE(LAYOUT_META.edgeCount), |
| 257 | refs: meta.readUInt32LE(LAYOUT_META.refCount), |
| 258 | }; |
| 259 | let errors: ExtractionResult['errors'] = []; |
| 260 | const errorsOff = meta.readUInt32LE(LAYOUT_META.errorsOff); |
| 261 | if (errorsOff !== LAYOUT_NONE) { |
| 262 | const errorsLen = meta.readUInt32LE(LAYOUT_META.errorsLen); |
| 263 | errors = JSON.parse( |
| 264 | buffers.arena.toString('utf8', errorsOff, errorsOff + errorsLen) |
| 265 | ) as ExtractionResult['errors']; |
| 266 | } |
| 267 | return { buffers, counts, errors }; |
| 268 | } catch (err) { |
| 269 | const message = err instanceof Error ? err.message : String(err); |
| 270 | if (message.includes('defer:')) { |
| 271 | deferSlot = { filePath, source, language, pre }; |
| 272 | return null; |
| 273 | } |
| 274 | if (!warned.has(language)) { |
| 275 | warned.add(language); |
| 276 | process.stderr.write( |
| 277 | `[codegraph-kernel] ${language} extraction failed (${message}) — falling back to the wasm path\n` |
| 278 | ); |
| 279 | } |
| 280 | return null; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Decode a buffer-carrying result (see ExtractionResult.kernelBuffers) into a |
no test coverage detected