Skip to content

feat(graph): add Go language extractor - #133

Open
0xmohit wants to merge 1 commit into
mex-memory:mainfrom
0xmohit:feat/go-code-graph-extractor
Open

0xmohit wants to merge 1 commit into
mex-memory:mainfrom
0xmohit:feat/go-code-graph-extractor

Conversation

@0xmohit

@0xmohit 0xmohit commented Aug 22, 2026 •

Copy link
Copy Markdown

Add code-graph extraction support for Go, wired through the contributor
seam in docs/extractors.md: a GoWalker over the tree-sitter-go grammar,
registered in the extractor registry and the grammar map.

  • Extract structs (class), interfaces, type aliases, functions,
    methods, generics, imports, calls, struct instantiations, and struct
    field types, with signatures, docstrings, visibility, and export state.
  • Methods bind to their receiver type through a deferred second pass, so
    a method resolves to a type declared later in the file with a single
    containment parent and a receiver-stable identity.
  • Vendor the grammar's own published wasm, tree-sitter-go@0.25.0
    (https://github.com/tree-sitter/tree-sitter-go), at
    src/graph/wasm/tree-sitter-go.wasm.
  • Add fixture sample.go and 12 tests covering declarations, containment,
    references, generics, docstrings, multi-name declarations, and
    declaration-order independence.
  • Retarget the coverage-histogram fixtures to .java now that .go is an
    indexed source extension, so unindexed-source examples stay accurate.
  • Document Go support in docs/code-graph-support.md and the grammar
    provenance in docs/extractors.md.

Fixes #93


What

Add code-graph extraction support for Go. A new GoWalker (in src/graph/extraction/languages/go.ts) parses .go files with the tree-sitter-go@0.25.0 grammar and emits:

  • file, class (structs), interface, type_alias, function, method, property, variable, and constant nodes
  • contains, imports, calls, instantiates, and type_of edges
  • Signatures, docstrings, visibility/export state, return types, and type parameters

Methods bind to their receiver type via a deferred second pass, so a method resolves to a type declared later in the same file with a single containment parent and a receiver-stable identity.

The extractor is registered in src/graph/extraction/languages/index.ts and src/graph/extraction/grammars.ts (.go extension), and the grammar's own published tree-sitter-go.wasm (v0.25.0) is vendored under src/graph/wasm/.

Why

Closes #93. Go is one of the highest-demand languages for the code-graph; this is the first extractor for it, following the contributor workflow in docs/extractors.md.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Docs
  • CI/Tooling

How to test

  1. npm run typecheck
  2. npm test (full suite, 4188 passing)
  3. npm run build
  4. Focused tests: npx vitest run src/graph/__tests__/extractor-go.test.ts — 12 tests covering structs, interfaces, type aliases, functions, methods, generics, imports, calls, struct field types, docstrings, multi-name declarations, and declaration-order independence.
  5. Real-project run: mex graph rebuild on a 526-file Go repository (not public code) indexed 5826 files (5826/5826 parse ok, 0 failed), creating 262,054 nodes / 297,812 edges; mex graph query where-defined resolves project-internal functions exactly, and mex graph scope returns source-backed symbols with resolved calls/instantiates flows at confidence 1.

Checklist

  • Tests pass (npm test)
  • No breaking changes (or documented below)
  • Tested locally with a real project

Code-graph changes

  • This PR targets main
  • A linked issue agrees on the bounded extractor/resolver scope
  • The change follows the frozen LanguageExtractor or FrameworkResolver interface
  • A focused fixture and assertions for the expected node/edge shape are included
  • Any new grammar WASM, extension mapping, extractor, or resolver is registered
  • No graph identity, reconciliation, schema, or drift-semantics changes are included, or a core / discuss-first issue is linked above

@0xmohit
0xmohit force-pushed the feat/go-code-graph-extractor branch from b18cd05 to ce98025 Compare September 23, 2026 02:15
@0xmohit 0xmohit mentioned this pull request Sep 23, 2026
9 tasks
Add code-graph extraction support for Go, wired through the contributor
seam in docs/extractors.md: a GoWalker over the tree-sitter-go grammar,
registered in the extractor registry and the grammar map.

- Extract structs (class), interfaces, type aliases, functions,
  methods, generics, imports, calls, struct instantiations, and struct
  field types, with signatures, docstrings, visibility, and export state.
- Methods bind to their receiver type through a deferred second pass, so
  a method resolves to a type declared later in the file with a single
  containment parent and a receiver-stable identity.
- Vendor the grammar's own published wasm, tree-sitter-go@0.25.0
  (https://github.com/tree-sitter/tree-sitter-go), at
  src/graph/wasm/tree-sitter-go.wasm.
- Add fixture sample.go and 12 tests covering declarations, containment,
  references, generics, docstrings, multi-name declarations, and
  declaration-order independence.
- Retarget the coverage-histogram fixtures to .java now that .go is an
  indexed source extension, so unindexed-source examples stay accurate.
- Document Go support in docs/code-graph-support.md and the grammar
  provenance in docs/extractors.md.

Fixes mex-memory#93
@0xmohit
0xmohit force-pushed the feat/go-code-graph-extractor branch from ce98025 to 8e54feb Compare September 23, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] Add code-graph extractor

1 participant