Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax symbol pickers #12275

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Syntax symbol pickers #12275

wants to merge 4 commits into from

Conversation

the-mikedavis
Copy link
Member

This adds two new symbol picker commands that use tree-sitter rather than LSP. We run a new symbols.scm query across the file and extract tagged things like function definitions, types, classes, etc. For languages with unambiguous syntax this behaves roughly the same as the LSP symbol picker (<space>s). It's less precise though since we don't have semantic info about the language. For example it can easily produce false positives for C/C++ because of preprocessor magic. Prior art for this feature is GitHub's imprecise code navigation which I believe works the same way and leverages tags.scm queries. (I have no internal GitHub knowledge so this is an educated guess.) It should be possible to find definitions and references as well like gd and gr - this is left as a follow-up.

The hope is to start introducing LSP-like features for navigation that can work without installing or running a language server. I made these two pickers in particular because I don't like LSP equivalents in ErlangLS or ELP - the document symbol picker can take a long time to show up during boot and the workspace symbol picker only searches for module names. The other motivation is to have some navigation features in cases when running a language server is too cumbersome - either to install or because of resource constraints. For example clangd needs a fair amount of setup (compile_commands.json) that you might not want to do when quickly reading through a codebase.

This PR also adds commands that either open the LSP symbol picker or the syntax one if a language server is not available. This way you can customize a language to not use the LSP symbol pickers, for example:

[[language]]
name = "erlang"
language-servers = [{ name = "erlang-ls", except-features = ["document-symbols", "workspace-symbols"] }]

and <space>s will use the syntax symbol picker, while <space>s on a Rust file will still prefer the language server.

Some prior discussion of a feature like this is in #3518 talking about Ctags support. The idea here is similar but extracts tags/symbols with tree-sitter instead.

Outstanding question: how closely should we try to match LSP symbol kind? Not at all? Should we have markup specific symbol kinds? (For example see markdown's symbols.scm).

@the-mikedavis the-mikedavis added A-tree-sitter Area: Tree-sitter E-medium Call for participation: Experience needed to fix: Medium / intermediate A-command Area: Commands labels Dec 16, 2024
nikvoid added a commit to nikvoid/helix that referenced this pull request Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands A-tree-sitter Area: Tree-sitter E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant