Replies: 3 comments 4 replies
-
There is a draft PR partially addressing your question (which I forgot to continue) here: #832 But I did implement rust-analyzer's Workspace Symbols Filtering in eglot-x.el. Do you think that has the functionality you are looking for? To decide it is enough to search for "Workspace Symbols Filtering" and look at relevant screenshots at https://github.com/nemethf/eglot-x |
Beta Was this translation helpful? Give feedback.
-
No, it doesn't. 😃 Or at least it shouldn't. In fact I agree with just about everything you wrote and I am familiar with this problem generally. It doesn't happen just for workspace symbols, it also happens for completions (which is an even older problem, AFAIK, and there it's moderately solved by the So, last time I looked into this (which was somewhat long ago), I tweaked Eglot's
Right, and I agree.
Have a look at the starting commentary of Emacs's Eglot makes use of this, precisely to support your use case. But maybe that use is broken in some specific case. So, ideally, you would provide a MRE example that a mostly Rust-ignorant person like me can follow, containing with your expectations and observations for each command. Follow the steps in https://joaotavora.github.io/eglot/#Troubleshooting-Eglot to show such a recipe. You probably can skip step 3, as I have a moderately recent version of rust-analyzer installed. |
Beta Was this translation helpful? Give feedback.
-
Yup, confirmed that its working now! And thanks for the tip about |
Beta Was this translation helpful? Give feedback.
-
If I open rust-analyzer's own code base in Emacs with
eglot
, and useC-u M-.
, it would miss a lot of symbols (eg,handle_workspace_symbol
), which more or less completely breaks the feature from the user's perspective.What happens here is that
eglot
sendsworkspace/symbol
with an empty query, expecting to get all the results there are. However, rust-analyzer manually limits the number of the results returned. There's a disagreement about semantics ofworkspace/symbol
, which leads to missing symbols.Now, it is 100% true that eglot follows the LSP spec, and rust-analyzer is in violation of it. However, from the perspective of rust-analyzer that's intenional violation, because following the spec here leads to fundamentally suboptimal behavior, which significantly impacts user experience for one of the most important features.
If, from eglot's perspective, following the spec is a top priority above all else, then it's fair to just close this as a won't fix, and put the blame on rust-analyzer.
From the perspective of delivering optimal user experience, I think a change in Emacs' behavior (and the spec) is warranted, and the former seems easier, and also in some sense orthogonal to LSP. Non-LSP based backend for
C-u M-.
would see the same problem, because, as far as i understand it, the limitation is in the Emacs' xref API.Here's my explanation of design of rust-analyzer here:
Getting all symbols is a fundamentally global operation. As it is global, the size of the result is unbounded, and this can be arbitrary slow (eg, worst case is querying google's code indexer for the list of all symbols in google's codebase).
At the same time, getting all results is useless for the user. The user can see only a handful of results on the screen, anything else is a waste. Even if you stream results, that still creates latency bloat and burns the CPU needlessly. The response which allows for minimizing latency is "here are the first 128 results for your query, please refine it to see more", and that's exactly what rust-analyzer implements.
Although this violates the spec, this actually works fine with most clients, because the LSP API is setup in such a way that the client is supposed to send updated query string to the server on user's typing. Eglot is the exception here. My understanding is that this stems from the fact Emacs' API does not allow incremental refining of the result via talking to an external entity.
TL;DR: Emacs assumes that it is possible to get "the list of all symbols in the project". This assumption doesn't match reality, for performance reasons, the full list might be unknowable. I feel like Emacs' core API should be extended to support "server side" fuzzy matching.
Beta Was this translation helpful? Give feedback.
All reactions