-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Syntax symbol pickers #12275
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
Conversation
9fdc127
to
b895ec4
Compare
I'm having trouble getting this to work. I pulled down the branch, but when I try to load the symbol picker, without having lsp enabled, I get an error that Any ideas? |
There are only a few languages with |
I added symbols for typst: #12793 |
}; | ||
|
||
use arc_swap::ArcSwapAny; | ||
use dashmap::DashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dashmap can be very slow to free memory (though it's fast on all other operations).
In my personal experience, scc
is better at memory reclamation, which is probably good for a picker (avoid lingering effects from mapping the whole workspace for example).
Of course, we probably want benchmarking results, it may not be an issue at all in practice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I like dashmap just because it's already a transitive dependency. It'd be good to check if it's being wasteful in terms of memory and switch to something else. It's already a little bit overkill for what it's used for here
As another use case or data point, I just tried this branch in a large cross-platform C++ project on Windows, where the project doesn't compile with clang itself and thus clangd is fairly cumbersome to set up for it. This tree-sitter based symbol lookup works pretty great and is surprisingly fast, given the size of the project. I found one inconsistency compared to the LSP-based symbol picker: The tree-sitter based one seems to be always case sensitive, where the LSP picker uses smart case. |
378bb8c
to
057bc91
Compare
Yeah I find it mostly useful for C codebases so far -
I think I had seen this as well, should be fixed in the most recent push. |
057bc91
to
5ea92d1
Compare
Co-authored-by: cgahr <[email protected]> Co-authored-by: eh <[email protected]>
Neither language server robustly supports workspace symbol search. `erlang-ls`'s symbol picker takes a long time to open successfully on boot. `elp`'s is faster but not faster than the tags query.
5ea92d1
to
4418e33
Compare
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 leveragestags.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 likegd
andgr
- 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:
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
).