-
Notifications
You must be signed in to change notification settings - Fork 10
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
Sorting of output #11
Comments
Hi @hinell , Thanks, would you be willing to open a PR? |
I have tried to implement this with And because it filters by filename so should have minimal impact to cmp overall. ---@param entry1 cmp.Entry
---@param entry2 cmp.Entry
local function package_json_npm(entry1, entry2)
local filename = vim.fn.expand('%:t')
if filename == 'package.json' then
local source1 = entry1.source.name
local source2 = entry2.source.name
-- make source npm has higher priority
if source1 == 'npm' and source2 ~= 'npm' then
return true
end
if source1 ~= 'npm' and source2 == 'npm' then
return false
end
-- if both source are npm, sort by version
if source1 == 'npm' and source2 == 'npm' then
local label1 = entry1.completion_item.label
local label2 = entry2.completion_item.label
local major1, minor1, patch1 = string.match(label1, '(%d+)%.(%d+)%.(%d+)')
local major2, minor2, patch2 = string.match(label2, '(%d+)%.(%d+)%.(%d+)')
if major1 ~= major2 then
return tonumber(major1) > tonumber(major2)
end
if minor1 ~= minor2 then
return tonumber(minor1) > tonumber(minor2)
end
if patch1 ~= patch2 then
return tonumber(patch1) > tonumber(patch2)
end
end
end
return false
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a way to write sorting functions for
nvim-cmp
.Checkout examples:
Please, add info on caching. Thanks!
The text was updated successfully, but these errors were encountered: