Skip to content

Commit

Permalink
feat: sort cmdline items starting with special characters last
Browse files Browse the repository at this point in the history
Closes #818
  • Loading branch information
Saghen committed Jan 3, 2025
1 parent e831cab commit ae3bf0d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lua/blink/cmp/sources/cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,24 @@ function cmdline:get_completions(context, callback)
:map(function(completions)
local items = {}
for _, completion in ipairs(completions) do
-- remove prefix from the filter text for lua
local has_prefix = string.find(completion, current_arg_prefix, 1, true) == 1

-- remove prefix from the filter text
local filter_text = completion
if string.find(completion, current_arg_prefix, 1, true) == 1 then
filter_text = completion:sub(#current_arg_prefix + 1)
end
if has_prefix then filter_text = completion:sub(#current_arg_prefix + 1) end

-- for lua, use the filter text as the label since it doesn't include the prefix
local label = arguments[1] == 'lua' and filter_text or completion

-- add prefix to the newText
local new_text = completion
if string.find(new_text, current_arg_prefix, 1, true) ~= 1 then new_text = current_arg_prefix .. completion end
if has_prefix then new_text = current_arg_prefix .. completion end

table.insert(items, {
label = label,
filterText = filter_text,
sortText = label:lower(),
-- move items starting with special characters to the end of the list
sortText = label:lower():gsub('^([!-@\\[-`])', '~%1'),
textEdit = {
newText = new_text,
range = {
Expand Down

0 comments on commit ae3bf0d

Please sign in to comment.