Commit b5ff3f9
authored
feat(native): port Objective-C extractor to Rust (#1106)
* feat(native): port Objective-C extractor to Rust
Mirrors `src/extractors/objc.ts` in `crates/codegraph-core/src/extractors/objc.rs`.
Adds the `tree-sitter-objc` dependency, wires `LanguageKind::ObjC` (`.m`) in
the Rust `parser_registry` and `file_collector`, adds `.m` to
`NATIVE_SUPPORTED_EXTENSIONS` on the JS side, and registers
`OBJC_AST_TYPES` / `OBJC_AST_CONFIG` so the native and WASM engines extract
identical `ast_nodes` for Objective-C source.
Handles class interfaces / implementations (with `: Superclass`), protocols,
instance and class method declarations/definitions with multi-part selectors
assembled from leading identifiers and `method_parameter` children, C-level
function declarations/definitions, `#import`/`@import` imports, and message
expression call extraction.
* fix(extractors): address ObjC review feedback
- Use `module` field (not `path`) for `@import` in Rust to mirror the JS
extractor and match the tree-sitter-objc `module_import` grammar field.
- Drop the unreachable `implementation_definition` branch from
`collect_class_members` — it is only invoked from `handle_class_interface`
and `class_interface` nodes do not contain `implementation_definition`
children.
- Qualify category methods with `(Category)` in the JS extractor so its
output matches Rust for `@interface Foo (Cat)` / `@implementation Foo (Cat)`
when the grammar emits `class_interface`/`class_implementation` rather
than dedicated `category_interface` nodes. Two categories can declare
same-named methods, so the qualified parent disambiguates the symbols.
- Document the `.m` extension collision with MATLAB/Octave in the file
collector since `.m` files are unconditionally routed to the ObjC parser.
* fix: correct expected count after merge dropped two entries (#1106)
The native-drop-classification test asserts the count of WASM-only
languages. The Clojure PR (#1097) removed src/c.clj and decremented
the count from 11 to 10. This PR removes src/k.m (now natively
supported via ObjC). After the merge both entries are removed, so
the assertion needs to be 9, not 10.
* fix(extractors): align JS ObjC engine with native for @import and calls
Three engine-parity gaps Greptile flagged on the WASM side that broke the
"identical output" goal:
- @import statements: tree-sitter-objc v3 emits `module_import` not
`import_declaration`, so the JS dispatch arm never matched and every
`@import Foundation;` was silently dropped. Accept both node types.
- C-style calls (printf, CGContextFillRect, …): the grammar lacks a
`function` field on `call_expression`, so the named-field lookup always
misses. Rust falls back to the first identifier child; JS did not, so
every C call was dropped. Add the same fallback.
- Message expressions: the grammar tags each keyword identifier with the
`method` field rather than exposing a `selector` field, so the JS
selector lookup misfired for multi-keyword selectors. Assemble the
selector from `method` children with `:` joining, matching
`build_message_selector` in the Rust extractor.
Also expose `fieldNameForChild` on the `TreeSitterNode` type and add three
JS extractor tests covering the new parity behaviour.
* fix: bump EXPECTED_LEN after merging Solidity LanguageKind (#1106)
* fix(extractors): align JS ObjC engine with native for v3 grammar (#1106)
The v3 tree-sitter-objc grammar emits flat 'identifier' + 'method_parameter'
children directly under method nodes (no 'keyword_selector' wrapper) and
nests property names under 'struct_declaration > struct_declarator >
[pointer_declarator >] identifier' rather than exposing a 'name' field. The
JS extractor was still following the old grammar shape, which silently
dropped multi-keyword method definitions, never populated parameter
children, and omitted all '@Property' members from class children.
- buildSelector: assemble selector from flat 'identifier'+'method_parameter'
children directly under the method node, matching build_selector in
crates/codegraph-core/src/extractors/objc.rs.
- extractMethodParams: iterate 'method_parameter' children directly and use
the last 'identifier' child as the parameter name (mirrors
extract_method_params in the Rust extractor).
- collectClassMembers: extract '@Property' names via a deep identifier walk
under 'struct_declaration > struct_declarator' (mirrors
extract_property_name in the Rust extractor).
Added three regression tests covering keyword method definitions with
parameters, and pointer + non-pointer '@Property' member names.
* fix(extractors): handle parameterized_arguments for ObjC protocol adoption (#1106)
The JS extractor was looking up 'protocol_qualifiers' which doesn't exist in
tree-sitter-objc v3 (the grammar wraps adopted protocols in
'parameterized_arguments' instead). As a result every '@interface Foo : NSObject
<Bar, Baz>' silently dropped its 'implements' relations on the JS side, while
the Rust extractor correctly extracted them. Mirror handle_class_interface in
crates/codegraph-core/src/extractors/objc.rs (parameterized_arguments + the
type_name > type_identifier nesting) and add a regression test.1 parent 06b6536 commit b5ff3f9
13 files changed
Lines changed: 1061 additions & 53 deletions
File tree
- crates/codegraph-core
- src
- extractors
- src
- ast-analysis/rules
- domain
- extractors
- tests/parsers
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
377 | 390 | | |
378 | 391 | | |
379 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| |||
0 commit comments