Skip to content

Commit 7e31674

Browse files
committed
Add back the fixed_input detection
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.
1 parent 691b37f commit 7e31674

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lua/cmp_cmdline/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ local definitions = {
122122
-- In this case, the `vim.fn.getcompletion` will return only `get_query` for `vim.treesitter.get_|`.
123123
-- We should detect `vim.treesitter.` and `get_query` separately.
124124
-- TODO: The `\h\w*` was choosed by huristic. We should consider more suitable detection.
125-
local fixed_input = arglead
125+
local fixed_input
126+
do
127+
local suffix_pos = vim.regex([[\h\w*$]]):match_str(arglead)
128+
fixed_input = string.sub(arglead, 1, suffix_pos or #arglead)
129+
end
126130

127131
-- The `vim.fn.getcompletion` does not return `*no*cursorline` option.
128132
-- cmp-cmdline corrects `no` prefix for option name.
@@ -158,7 +162,7 @@ local definitions = {
158162
if is_magic_file then
159163
local replace_range = {
160164
start = {
161-
character = cmdline_length - #fixed_input - 1
165+
character = cmdline_length - #arglead - 1
162166
},
163167
['end'] = {
164168
character = cmdline_length - 1
@@ -169,7 +173,7 @@ local definitions = {
169173
range = replace_range,
170174
newText = item.label
171175
}
172-
item.label = fixed_input .. '' .. item.label
176+
item.label = arglead .. '' .. item.label
173177
end
174178
end
175179

0 commit comments

Comments
 (0)