fix(extraction): preload the Objective-C grammar for C-family headers (#1628) - #1634
Open
maxmilian wants to merge 1 commit into
Open
fix(extraction): preload the Objective-C grammar for C-family headers (#1628)#1634maxmilian wants to merge 1 commit into
maxmilian wants to merge 1 commit into
Conversation
…colbymchenry#1628) A .h file is classified from its path as C, so the preload set that the parse workers receive contains c (and cpp, added explicitly for exactly this reason). Parse-time detection then reads the source and can return objc — a grammar no worker holds, so the file fails outright with 'Failed to get parser for language: objc' and nothing in it is indexed. A project with any .m file happened to work, because that pulled objc into the set by path. Preload objc alongside cpp whenever c is present: both are readings that content-aware .h detection can produce, so both have to be available before the workers start. The same three lines existed twice (full index and changed-file reindex), and only one of them would have been easy to remember to change, so this extracts preloadLanguagesForFiles() and uses it in both places. Verified end to end against the reporter's reproduction — a directory holding only an Objective-C .h file: before: 1 parser initialization failures / 'Failed to get parser for language: objc' in .codegraph/errors.log after: Indexed 1 files, 2 nodes, 1 edges Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1628.
A
.hfile is classified from its path alone as C, so the preload set handed to the parse workers containsc— pluscpp, added explicitly because a header might turn out to be C++. Parse-time detection then reads the source and can also returnobjc(detectLanguage's.hbranch checkslooksLikeCppandlooksLikeObjc), and no worker holds that grammar. The file fails outright withFailed to get parser for language: objcand nothing in it reaches the index.That is why the failure looked arbitrary: any
.mfile in the project pullsobjcinto the set by path, so the very same header indexes fine. @Juddd's control experiment — adding a one-linegrammar_seed.mand watching both files index — pins it exactly.So
objcis preloaded alongsidecppwhenevercis present: both are readings that content-aware.hdetection can produce, and both have to be available before the workers start.Verified against the reporter's reproduction
A directory containing only:
Before (
codegraph init --yeson currentmain):After:
One refactor, and why it's in scope
The three lines that build this set existed twice — once for the full index, once for the changed-file reindex — and fixing only the copy the issue points at leaves the other one carrying the same bug for incremental runs. Both now call
preloadLanguagesForFiles(), which also makes the rule unit-testable instead of buried inside a 200-line method.Tests
__tests__/preload-languages.test.ts, four cases: both ambiguous readings of a.hare covered; a project with no C-family header gets neither grammar added; a language the files already need isn't duplicated; extension overrides still drive the base set.Confirmed red by reverting just the
objchalf of the change (expected [ 'c', 'cpp' ] to include 'objc'), so the test pins this fix rather than restating the implementation.Full suite: 179 files / 3056 tests passing (3052 on
mainplus these four).tsc --noEmitclean.Reported and diagnosed by @Juddd.