-
Notifications
You must be signed in to change notification settings - Fork 859
Add scores to completion items #348
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
Comments
Oops, forgot to mention the motivating use case: I'm working on the clangd LSP server for C++, and we want to support completion at global scope, for huge codebases, including symbols you haven't imported yet. |
On jdt.ls we try to calculate a relevancy rank for sortText but that does not allow us to support some of the cases. A solution for this should consider ranking/sorting completionItems from multiple LSPs though. |
FWIW It seems VSCode largely ignores this part of the spec anyway, even in the absence of client-side filtering. (Or possibly interprets it in a way I don't understand). For the query 's' we compute scores std::string > absl::StrCat > ::strcat and return matching sortText, but VSCode renders the results as std::string > ::strcat > absl::StrCat. |
@dbaeumer I'm assuming this isn't being worked on ("backlog"). Is this something that could get review attention if someone was willing to contribute work/patches to the spec/client/vscode? This is an increasingly pressing issue for clangd, we have more VSCode users now and this hurts code completion quality on large codebases a lot vs other clients. We're investigating adding a proprietary extension and trying to hack this into our VSCode plugin (unclear if possible). Happy to redirect this effort if you think it might lead somewhere. On a pure technical side, I think the hardest part is adapting vscode's fuzzy-matcher to give a score on a well-defined scale. |
In this scheme, it is possible that two editors, A and B, always agree on the relative ordering of the fuzzy matches, but compute their The problem here is that the scoring criteria of the editor is unknown to the server and vice versa, so their product can interact in complicated ways. In a way, this is just a reflection of the fact that that fuzzy-match sorting is not canonical. But I'm not sure it's a good idea to spec a system that allows those random interactions. |
Since this doesn't seem to be going onywhere, clangd is going to add |
I think you should have a look to #898 which is about the same topic. A score would not really help as the score, just like the initial sorting of elements, may become irrelevant whenever user type a keystroke, and would drive the client to decide whether to do fuzzy matching (some server like it) or to respect the LS ordering (some other servers do that). In #898, I suggest that we add some semantics on |
I'm aware of #898, the discussion there isn't going in a useful direction for us. We need a way to produce a final ranking based on a numeric combination of fuzzy-match factors and server-specific factors that are not exposed via LSP.
The score in the extension excludes any fuzzy-match component. Therefore clients that re-rank based on client-side fuzzy match can use this score as a multiplier. Clients that don't do that can ignore it. |
Client-side filtering and ranking of LSP results is great for latency, but can't take into account server-side signals such as popularity, type-matches-context etc. This extension lets the server provide a numeric score multiplier. It's documented here: https://clangd.github.io/extensions.html clangd implements it at trunk and in the pending 10.0 release. This is the main blocker for recommending coc.nvim for clangd. (currently we recommend YCM and just turn all client-side filtering off). clangd/clangd#284 My attempt to get something like this standardized doesn't seem to be moving: microsoft/language-server-protocol#348
Isn't the ordering of the completion list enough information? |
There is nothing that states that, and there are language servers that assume the client does some filtering. More examples about it in #898 . |
No. Consider a completion list for If That said, if clients were willing to filter only and sort purely by |
(I'm sure it seems like I'm obsessing over obscure cases - we frequently get bug reports about ranking from VSCode users) |
Client-side filtering and ranking of LSP results is great for latency, but can't take into account server-side signals such as popularity, type-matches-context etc. This extension lets the server provide a numeric score multiplier. It's documented here: https://clangd.github.io/extensions.html clangd implements it at trunk and in the pending 10.0 release. This is the main blocker for recommending coc.nvim for clangd. (currently we recommend YCM and just turn all client-side filtering off). clangd/clangd#284 My attempt to get something like this standardized doesn't seem to be moving: microsoft/language-server-protocol#348
@sam-mccall thanks for your willingness to work on this. I added a comment here #898 (comment) explaining how I think that should already work today. Can you please have a look. |
Sure this can happen, but does it, in practice? It seems unlikely there isn't going to be some intermediate candidates in between these two (assuming here that number of refs is a relevant attribute and the server takes it into account for its own ranking). My suggestion above was to try to come up with a formula using |
I will close the issues since I don't see us implementing this anytime soon especially since the LSP model leaves sorting and filtering to the client. |
Many things can affect the quality of a CompletionItem suggestion.
Currently the server can control ranking via sortText, but the interactions with client-side fuzzy-matching are unclear:
One way this could be addressed is to define
score = matchScore * resultScore
, wherematchScore
is a 0-1 number describing the fuzzy-match quality of (filter, ci.filterText).The server would rank/truncate results by
score
, and also provideresultScore
to the client. This makes it explicit that the server has already ranked the results according to filterText, and allows the client to re-rank them when the filter changes without losing information - it computes the newmatchScore
and multiplies byresultScore
.(In practice, I don't think this requires the client and server to have identical fuzzy-match scorers, just as the current fuzzy-filter semantics are not precisely spelled out).
Obviously this is a complex change that would require client/server support, and some back-compat story. Maybe for v4?
The text was updated successfully, but these errors were encountered: