Skip to content

Feature request: Objective-C / Objective-C++ / Metal support #1121

Description

@FluxKo

Feature request: Objective-C / Objective-C++ / Metal support

Currently .m, .mm, and .metal files are not in EXTENSION_MAP (src/extraction/grammars.ts), so they resolve to language: 'unknown' and are silently skipped during indexing — no error, no warning, they're just absent from the graph.

This matters for Apple-platform codebases (AVFoundation/VideoToolbox/Metal-heavy projects), where .m/.mm is often where the interesting call graph lives.

What I found while prototyping a fix locally

  • tree-sitter-objc.wasm is already a transitive dependencytree-sitter-wasms (a direct dependency of codegraph) ships it, but nothing wires it up. Adding objc: 'tree-sitter-objc.wasm' to WASM_GRAMMAR_FILES + .mobjc in EXTENSION_MAP is enough to load it.
  • No field names for class/method identifiers in the objc grammar (class_interface/class_implementation/method_declaration/method_definition all carry the name as a positional, unlabeled identifier child), and @implementation methods nest two levels deep (class_implementationimplementation_definitionmethod_definition). The generic nameField-based extraction machinery can't drive this — it needs a visitNode-based extractor (same pattern as pascal.ts), building the full colon-separated selector (doA:andB:) from the identifier/method_parameter sequence.
  • message_expression ([obj foo:1 bar:2]) needs custom handling too — it has no function field, so the generic extractCall falls back to node.namedChild(0) and picks up the receiver as the callee name. Has a method: field that repeats once per keyword segment.
  • I built and tested a working extractor locally (~200 lines, modeled on c-cpp.ts/pascal.ts) against real .m fixtures (including #import <VideoToolbox/VideoToolbox.h> usage) — classes, selectors (unary/keyword/multi-keyword), and message-send call edges all extract correctly and resolve in the graph.
  • .mm (Objective-C++): no grammar covers the actual mix. Empirically parsing representative .mm samples, tree-sitter-objc produces fewer ERROR nodes than tree-sitter-cpp — it's the better of two imperfect defaults, but embedded C++ class bodies inside .mm files still misparse. Worth flagging as a known limitation rather than pretending it's exact.
  • .metal: no dedicated grammar exists (Metal Shading Language ≈ C++14 + attribute syntax). Mapping .metal → the existing cpp extractor works surprisingly well out of the box — functions and structs extract correctly; only the [[buffer(0)]]-style attribute annotations trip up the parser locally, without derailing the rest of the file.

Happy to share the local diff/extractor if useful as a starting point — not submitting as a PR since I only have the compiled dist/ output to work from locally, not your src/ layout/conventions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions