Fully utilize autocompletion ordering for hrsh7th/nvim-cmp #539
rochala
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks a lot for this @rochala! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone!
As you know,
nvim-metals
uses Language Server Protocol to provide IDE capabilities.The one I'm going to create discussion about is
completion
with specifications available here.nvim-metals
plugin is not responsible for displaying the tooltips, only fetching them from the server. This is where things get interesting. LSP provides a way to return completion order by setting thesortText
string value. If it is undefined, all ordering and sorting is handled by the client, in this case byhrsh7th/nvim-cmp
plugin.The default sorting configuration matches the completions in the following way:
As you see, the
sort_text
is present in this configuration and by default it should work as intended... but it isn't.As an example, we will check the completion is
build.sbt
file:And here the
package
is a preselected value. If we check the ordering returned from metals we can see that it returnspackage
withsortText
="00000"
so it should be our first result.So let's get a quick summary before going further:
Let's fix this, so we can have the correct ordering from the server:
For this, we can't easily order only by
sortText
as metals optimizes the calls to the server.In short, to not recompute file on every letter typed, the response from completion also contains the
isIncomplete
field. It only does recompute when it is true, and usually 3 letters are enough to get all available completions and further letters typed no longer are sorted by server...This is what happens after the 4th letter:
Screen.Recording.2023-02-27.at.17.13.07.mov
As you can see, our selection randomly jumped to the middle of the list. This is caused because our ordering has higher precedence of
compare.offset
than ourcompare.sort_text
and it doesn't refresh preselect!The fix is to add the following lines to your
nvim-cmp
configuration (it will affect other LSP configurations, but I leave it to you to figure out how to enable it only for metals):In my opinion, this is not a bug in
hrsh7th/nvim-cmp
but rather a problem with the unique metals client implementation. This should improve your completions.Beta Was this translation helpful? Give feedback.
All reactions