Skip to content

fix(go): resolve method names from field_identifier in method_declaration#166

Open
singh-aashutosh wants to merge 1 commit intotirth8205:mainfrom
singh-aashutosh:singh-aashutosh/go-method-field-identifier-fix
Open

fix(go): resolve method names from field_identifier in method_declaration#166
singh-aashutosh wants to merge 1 commit intotirth8205:mainfrom
singh-aashutosh:singh-aashutosh/go-method-field-identifier-fix

Conversation

@singh-aashutosh
Copy link
Copy Markdown

Summary

Go methods were often missing from the knowledge graph or stored under the wrong name (for example int64, string, error) because _get_name() did not match how tree-sitter-go models method names.

Root cause

For method_declaration, the method name is a field_identifier child, not an identifier. The generic loop only matches identifier, type_identifier, and similar. That leads to:

  • Methods without a result type: no matching name → the method is skipped entirely.
  • Methods with a named result type (e.g. int64): the first type_identifier after the parameter lists is the return type, which was incorrectly used as the function name.

Change

In _get_name(), add a Go-specific branch for method_declaration that returns the field_identifier text, placed before the generic child loop (same ordering idea as the existing C/C++ handling so return types are not mistaken for names).

Verification

  • Parse a small file with func (s *T) Foo() {} and func (s *T) Bar() int64 { return 0 }; both should emit Function nodes named Foo and Bar, not int64.
  • Parse a large service.go with many receiver methods; Function count should match expectations and bogus int64 / string / error “functions” from return types should disappear.

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.

2 participants