crates.nvim icon indicating copy to clipboard operation
crates.nvim copied to clipboard

Crate versions are lexicographically sorted in completion

Open ten3roberts opened this issue 2 years ago • 6 comments

Current behavior

The crates versions supplied to the completion are sorted lexicographically, which causes 0.1.9 to be given higher priority over 0.1.11 which is buries underneath the 0.1.1 version.

Expected behavior

The crates versions are returned in semantic version order, as the user most likely want't the most recent version when adding a crate.

E.g; 0.1.11, 0.1.10, 0.1.9 etc

Additional context/Screenshots

Screenshot 2023-05-30 at 11 43 35

Neovim version

nvim --version
NVIM v0.10.0-dev-1769+g9dd48f783-Homebrew
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/HEAD-9dd48f7/share/nvim"

Run :checkhealth for more info

ten3roberts avatar May 30 '23 09:05 ten3roberts

I've also noticed that, but I'm not exactly sure what's the cause. We set sortText on versions and the client/completion provider is supposed to respect them. That used to work when I implemented it, but some time ago something broke.

Here is the line we set sortText: https://github.com/Saecki/crates.nvim/blob/3648f8787656d7572740560331553abdaa8cb982/teal/crates/src/common.tl#L39

Here is the line nvim-cmp uses it to sort CompletionItems: https://github.com/hrsh7th/nvim-cmp/blob/fc0f694af1a742ada77e5b1c91ff405c746f4a26/lua/cmp/config/compare.lua#L74

This needs some more investigation, I'll look into it sometime.

saecki avatar May 30 '23 12:05 saecki

Found the issue, seems like the default config excludes scoring/sorting by sort_text: https://github.com/hrsh7th/nvim-cmp/blob/fc0f694af1a742ada77e5b1c91ff405c746f4a26/lua/cmp/config/default.lua#L71

saecki avatar May 30 '23 13:05 saecki

So whats the conclusion of this? Would it possible to patch cmp to enable sort_text or is there an other way?

fabolous005 avatar Dec 07 '23 17:12 fabolous005

I don't know, there is no answer to the issue I opened on the nvim-cmp repository. For now it seems like users will have to manually enable the sort_text comparator, if desired.

saecki avatar Dec 08 '23 02:12 saecki

Thank you. Do you mind pasting the issue link in nvim-cmp here? Just for future reference

fabolous005 avatar Dec 08 '23 13:12 fabolous005

It's actually already linked above

saecki avatar Dec 08 '23 13:12 saecki