feat(go): basic Go language support - #55
Merged
Merged
Conversation
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.
Owner
|
Good pr! |
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.
Closes #17
Adds
tree-sitter-goand aGO_QUERIESmodule covering structs, interfaces, functions, methods, struct fields, imports and calls.Two things Go does differently
Types aren't a dedicated node. Go models them as
type_declaration -> type_specwith the concrete shape hanging off thetypefield, so structs and interfaces are matched on thetype_spec(filtered bystruct_type/interface_type) rather than on astruct_defs-style node like Rust has.Methods are a distinct node type.
method_declarationcarries areceiver;function_declarationdoesn't. SoArea()lands asMETHODwhiledescribe()andmain()land asFUNCTION— there's a test assertingAreais not also reported as a function.The
callsquery 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 →
NodeKindmapping innode_extractor, so Go needed no per-language branching — only registration inLANGUAGE_QUERIES,EXT_TO_LANG, theLanguageenum and the grammar table.Verified
On a sample with an interface, a struct, a method, two functions and both call shapes:
On call edges: they additionally require the
_extract_call_edgesfix from #50 — onmainnoCALLSedge is emitted for any language. With that fix applied locally, this sample yields exactly the two intra-file edgesdescribe -> Areaandmain -> describe, and correctly excludes external calls likefmt.Println. That fix is not in this PR — thecallsquery here is asserted at the query level instead (both call shapes produce acallee_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.pyused.goas 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
Baseline on
mainis3 failed, 174 passed— same three pre-existing failures (fixed in #51), plus 14 new tests.CI here will be red at
Lint with ruffuntil #51 lands; that's the pre-existing breakage, not this change.