Skip to content
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

Crate versions are lexicographically sorted in completion #69

Open
ten3roberts opened this issue May 30, 2023 · 6 comments
Open

Crate versions are lexicographically sorted in completion #69

ten3roberts opened this issue May 30, 2023 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@ten3roberts
Copy link
Contributor

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 ten3roberts added the bug Something isn't working label May 30, 2023
@Saecki
Copy link
Owner

Saecki commented May 30, 2023

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:

sortText = string.format("%04d", i),

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
Copy link
Owner

Saecki commented May 30, 2023

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 Saecki added question Further information is requested and removed bug Something isn't working labels Sep 1, 2023
@fabolous005
Copy link

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

@Saecki
Copy link
Owner

Saecki commented Dec 8, 2023

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.

@fabolous005
Copy link

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

@Saecki
Copy link
Owner

Saecki commented Dec 8, 2023

It's actually already linked above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants