Skip to content

Commit

Permalink
Add back the fixed_input detection
Browse files Browse the repository at this point in the history
Ignore fixed_input and use arglead directly in the case of a magic file
match. This unbreaks `%:.:h:h`, while still handling fixed_input
correctly in the non magic_file case.
  • Loading branch information
iteratee committed Apr 24, 2024
1 parent 8cb39fd commit 589b31f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/cmp_cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ local definitions = {
-- In this case, the `vim.fn.getcompletion` will return only `get_query` for `vim.treesitter.get_|`.
-- We should detect `vim.treesitter.` and `get_query` separately.
-- TODO: The `\h\w*` was choosed by huristic. We should consider more suitable detection.
local fixed_input = arglead
local fixed_input
do
local suffix_pos = vim.regex([[\h\w*$]]):match_str(arglead)
fixed_input = string.sub(arglead, 1, suffix_pos or #arglead)
end

-- The `vim.fn.getcompletion` does not return `*no*cursorline` option.
-- cmp-cmdline corrects `no` prefix for option name.
Expand Down Expand Up @@ -150,7 +154,7 @@ local definitions = {
if is_magic_file then
local replace_range = {
start = {
character = cmdline_length - #fixed_input - 1
character = cmdline_length - #arglead - 1
},
['end'] = {
character = cmdline_length - 1
Expand All @@ -161,7 +165,7 @@ local definitions = {
range = replace_range,
newText = item.label
}
item.label = fixed_input .. '' .. item.label
item.label = arglead .. '' .. item.label
end
end
return items
Expand Down

0 comments on commit 589b31f

Please sign in to comment.