saecki / crates.nvim

A neovim plugin that helps managing crates.io dependencies
MIT License
872 stars 29 forks source link

Crate versions are lexicographically sorted in completion #69

Open ten3roberts opened 1 year ago

ten3roberts commented 1 year ago

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 ```
saecki commented 1 year ago

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 commented 1 year ago

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

fabolous005 commented 11 months ago

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

saecki commented 11 months ago

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 commented 11 months ago

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

saecki commented 11 months ago

It's actually already linked above