Skip to content

feat(go): basic Go language support - #55

Merged
lexasub merged 1 commit into
mainfrom
feat/go-support
Aug 1, 2026
Merged

feat(go): basic Go language support#55
lexasub merged 1 commit into
mainfrom
feat/go-support

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #17

Adds tree-sitter-go and a GO_QUERIES module covering structs, interfaces, functions, methods, struct fields, imports and calls.

$ ast-rag  # supported languages
cpp (.c, .cc, .cpp, .cxx, .h, .hh, .hpp, .hxx), go (.go), java (.java),
python (.py), rust (.rs), tsx (.jsx, .tsx), typescript (.ts)

Two things Go does differently

Types aren't a dedicated node. Go models them as type_declaration -> type_spec with the concrete shape hanging off the type field, so structs and interfaces are matched on the type_spec (filtered by struct_type / interface_type) rather than on a struct_defs-style node like Rust has.

Methods are a distinct node type. method_declaration carries a receiver; function_declaration doesn't. So Area() lands as METHOD while describe() and main() land as FUNCTION — there's a test asserting Area is not also reported as a function.

The calls query handles both shapes Go uses — a bare identifier (describe()) and a selector (fmt.Println()), capturing the method name for the latter.

I derived all of the node types and field names by probing the grammar rather than guessing, then pinned them with tests.

No dispatch changes needed

Query names reuse the existing generic name → NodeKind mapping in node_extractor, so Go needed no per-language branching — only registration in LANGUAGE_QUERIES, EXT_TO_LANG, the Language enum and the grammar table.

Verified

On a sample with an interface, a struct, a method, two functions and both call shapes:

INTERFACE Shape
STRUCT    Rect
FUNCTION  describe, main
METHOD    Area
FIELD     W, H
edges: CONTAINS_CLASS 2, CONTAINS_FUNCTION 3, CONTAINS_FIELD 2, IMPORTS 1

On call edges: they additionally require the _extract_call_edges fix from #50 — on main no CALLS edge is emitted for any language. With that fix applied locally, this sample yields exactly the two intra-file edges describe -> Area and main -> describe, and correctly excludes external calls like fmt.Println. That fix is not in this PR — the calls query here is asserted at the query level instead (both call shapes produce a callee_name), so this PR stands alone and the edges start working once #50 lands.

Tests

14 in tests/test_go_parsing.py: registration, extension detection, struct/interface extraction, function-vs-method distinction, fields, imports, both call shapes, and a parametrised check that every Go query compiles against the grammar.

One existing test needed updating: test_unsupported_language.py used .go as its example of an unsupported extension, which is no longer true. Switched to .rb. That test failing was the correct signal, not a regression.

Verification

ruff check ast_rag/ tests/     All checks passed!
ruff format --check            77 files already formatted
pytest tests/                  3 failed, 188 passed, 2 xfailed

Baseline on main is 3 failed, 174 passed — same three pre-existing failures (fixed in #51), plus 14 new tests.

CI here will be red at Lint with ruff until #51 lands; that's the pre-existing breakage, not this change.

Adds tree-sitter-go and a GO_QUERIES module covering structs, interfaces,
functions, methods, struct fields, imports and calls.

Go models types as `type_declaration -> type_spec` with the concrete shape on
the `type` field, so structs and interfaces are matched on the type_spec
rather than on a dedicated node. Methods carry a `receiver` and are a separate
node type (method_declaration) from plain functions, so Area() lands as METHOD
while describe()/main() land as FUNCTION.

The calls query handles both shapes Go uses -- a bare identifier (describe())
and a selector (fmt.Println()) -- capturing the method name for the latter.
Query names reuse the existing generic mapping in node_extractor, so no
per-language dispatch was needed.

Verified on a sample with an interface, struct, method, two functions and both
call shapes:

  INTERFACE Shape / STRUCT Rect / FUNCTION describe, main / METHOD Area
  FIELD W, H / IMPORTS 1

Call edges additionally require the _extract_call_edges fix from #50; with that
applied locally this sample yields exactly the two intra-file edges
(describe -> Area, main -> describe) and correctly excludes external calls such
as fmt.Println. This PR does not include that fix.

test_unsupported_language.py used .go as its example of an unsupported
extension, which is no longer true -- switched to .rb.

Suite: 3 failed, 188 passed (baseline on main: 3 failed, 174 passed) -- same
three pre-existing failures, fixed separately in #51.
@lexasub

lexasub commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Good pr!

@lexasub
lexasub merged commit b4404e3 into main Aug 1, 2026
1 check failed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in raged kanban Aug 1, 2026
@lexasub
lexasub deleted the feat/go-support branch August 1, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add Basic Go Support

2 participants