( filePath: string, source: string, language: Language )
| 205 | * languages keep the decoded path). |
| 206 | */ |
| 207 | export function tryKernelExtractRaw( |
| 208 | filePath: string, |
| 209 | source: string, |
| 210 | language: Language |
| 211 | ): KernelRawResult | null { |
| 212 | if (!kernelRoutes(language) || POST_PASSES[language]) return null; |
| 213 | const kernel = getKernel(); |
| 214 | if (!kernel) return null; |
| 215 | if (takeDeferredPreParse(filePath, source, language) !== null) return null; // already deferred |
| 216 | const pre = preParsedSource(filePath, source, language); |
| 217 | try { |
| 218 | const buffers = kernel.extractFile(filePath, pre, language); |
| 219 | const meta = buffers.meta; |
| 220 | if (meta.readUInt8(LAYOUT_META.version) !== LAYOUT_ABI) { |
| 221 | throw new Error(`kernel buffer ABI ${meta.readUInt8(0)} != expected ${LAYOUT_ABI}`); |
| 222 | } |
| 223 | const counts = { |
| 224 | nodes: meta.readUInt32LE(LAYOUT_META.nodeCount), |
| 225 | edges: meta.readUInt32LE(LAYOUT_META.edgeCount), |
| 226 | refs: meta.readUInt32LE(LAYOUT_META.refCount), |
| 227 | }; |
| 228 | let errors: ExtractionResult['errors'] = []; |
| 229 | const errorsOff = meta.readUInt32LE(LAYOUT_META.errorsOff); |
| 230 | if (errorsOff !== LAYOUT_NONE) { |
| 231 | const errorsLen = meta.readUInt32LE(LAYOUT_META.errorsLen); |
| 232 | errors = JSON.parse( |
| 233 | buffers.arena.toString('utf8', errorsOff, errorsOff + errorsLen) |
| 234 | ) as ExtractionResult['errors']; |
| 235 | } |
| 236 | return { buffers, counts, errors }; |
| 237 | } catch (err) { |
| 238 | const message = err instanceof Error ? err.message : String(err); |
| 239 | if (message.includes('defer:')) { |
| 240 | deferSlot = { filePath, source, language, pre }; |
| 241 | return null; |
| 242 | } |
| 243 | if (!warned.has(language)) { |
| 244 | warned.add(language); |
| 245 | process.stderr.write( |
| 246 | `[codegraph-kernel] ${language} extraction failed (${message}) — falling back to the wasm path\n` |
| 247 | ); |
| 248 | } |
| 249 | return null; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Decode a buffer-carrying result (see ExtractionResult.kernelBuffers) into a |
no test coverage detected