Summary
An Objective-C header can fail with Failed to get parser for language: objc when a project contains no .m/.mm file.
CodeGraph initially classifies .h files as C and preloads the C and C++ grammars. After the worker pool has been initialized, content-aware detection correctly reclassifies the header as Objective-C, but the worker has no Objective-C grammar loaded.
This was originally observed in OpenCV's opencv2/videoio/cap_ios.h, but the reproducer below has no dependencies or imports.
Environment
- CodeGraph 1.6.0
- Linux 5.15 x86_64
Minimal reproduction
Create an otherwise empty directory containing exactly this file:
repro.h
@interface CGRepro
- (void)run;
@end
Run:
Actual result:
Indexing failed — all 1 files had errors
1 parser initialization failures
.codegraph/errors.log:
1 files with errors
repro.h: Failed to get parser for language: objc
codegraph status --json reports fileCount: 1, nodeCount: 0, languages: ["objc"], and state: "failed".
The same failure reproduces with a subsequent codegraph index.
Expected result
repro.h should be parsed as Objective-C and its class/method should be indexed, without requiring a sibling .m or .mm file.
Control experiment
Adding this second file causes both files to index successfully:
grammar_seed.m
void codegraph_objc_grammar_seed(void) {}
With that file present, codegraph index reports:
Indexed 2 files
4 nodes, 2 edges
Removing grammar_seed.m and rebuilding restores the parser initialization failure.
Diagnosis
The failure is deterministic:
path-only detection: repro.h -> c
preloaded grammars: c, cpp
content-aware detection: repro.h -> objc
getParser("objc"): null
Loading the Objective-C grammar explicitly changes getParser("objc") from null to a valid parser, so the shipped tree-sitter-objc.wasm is present and loadable.
The preload logic currently derives neededLanguages without file contents and adds cpp when c is present, but not objc:
https://github.com/colbymchenry/codegraph/blob/main/src/extraction/index.ts#L1665-L1669
Later, parsing performs content-aware detection and sends the resulting objc language to the already initialized worker.
Possible fixes
- When
.h/C is present, preload both cpp and objc; or
- lazily load the final content-detected grammar in the worker.
Either approach should preserve the current content-aware .h detection while ensuring the selected parser is available.
Summary
An Objective-C header can fail with
Failed to get parser for language: objcwhen a project contains no.m/.mmfile.CodeGraph initially classifies
.hfiles as C and preloads the C and C++ grammars. After the worker pool has been initialized, content-aware detection correctly reclassifies the header as Objective-C, but the worker has no Objective-C grammar loaded.This was originally observed in OpenCV's
opencv2/videoio/cap_ios.h, but the reproducer below has no dependencies or imports.Environment
Minimal reproduction
Create an otherwise empty directory containing exactly this file:
repro.hRun:
$ codegraph init --yesActual result:
.codegraph/errors.log:codegraph status --jsonreportsfileCount: 1,nodeCount: 0,languages: ["objc"], andstate: "failed".The same failure reproduces with a subsequent
codegraph index.Expected result
repro.hshould be parsed as Objective-C and its class/method should be indexed, without requiring a sibling.mor.mmfile.Control experiment
Adding this second file causes both files to index successfully:
grammar_seed.mWith that file present,
codegraph indexreports:Removing
grammar_seed.mand rebuilding restores the parser initialization failure.Diagnosis
The failure is deterministic:
Loading the Objective-C grammar explicitly changes
getParser("objc")from null to a valid parser, so the shippedtree-sitter-objc.wasmis present and loadable.The preload logic currently derives
neededLanguageswithout file contents and addscppwhencis present, but notobjc:https://github.com/colbymchenry/codegraph/blob/main/src/extraction/index.ts#L1665-L1669
Later, parsing performs content-aware detection and sends the resulting
objclanguage to the already initialized worker.Possible fixes
.h/C is present, preload bothcppandobjc; orEither approach should preserve the current content-aware
.hdetection while ensuring the selected parser is available.