Skip to content

Conversation

@m4rch3n1ng
Copy link
Contributor

@m4rch3n1ng m4rch3n1ng commented Nov 23, 2025

i noticed this while trying to improve the go and rust tags and noticed, that the go tags had some @name queries, that didn't seem to do anything, while the rust did not. when querying for the go syntax the picker showed the whole definition: (or at least the first line of it), while the rust picker (correctly) only displayed the name.

screenshots image image

the go lsp only shows the name:
image

while the rust syntax picker showed the correct name, when selecting a symbol, only selected the name of the definition is selected, while the lsp symbol picker selects the entire definition.

screenshots (after selecting the `Thing` struct in the picker): image image

this pr fixes that by just trying to find a @name in the definition capture and falling back to displaying whole match if none is found. i am not quite sure with my implementatio

with this pr i can also update the rust tags, so that the syntax query matches the whole definition, which i did in the second commit.

additional notes: the currently ignored @name captures are already used by quite a few grammars, including go, ts/js, python, c# and elisp to name a few.

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for a @name capture in a match of a @definition.* capture is correct (we should aim to follow https://tree-sitter.github.io/tree-sitter/4-code-navigation.html). The range of the symbol should be the entire @definition.* capture though. Ideally the tags.scm query should capture the entire definition with @definition.* and the @name should be used for display purposes, for example in the picker.

let start = text.byte_to_char(mat.node.start_byte() as usize);
let end = text.byte_to_char(mat.node.end_byte() as usize);

let mut inner_iter = syntax.tags(text, loader, mat.node.byte_range());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never need to invoke a new query within a match of that same query. That's working around tags iterator returned captured nodes rather than entire matches. This probably needs work in tree-house to add an iterator over matches rather than captures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i expected as much. not quite sure where to start in tree-house, but i'll see what i can come up with ...

@m4rch3n1ng
Copy link
Contributor Author

m4rch3n1ng commented Nov 23, 2025

updated the implementation here to use helix-editor/tree-house#29 and converted to draft, while depending on my git branch for the tree-house dependency.

@m4rch3n1ng m4rch3n1ng changed the title fix(tags): search for @name inside of tags fix(tags): search for @name inside of tags Nov 23, 2025
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