Skip to content

Commit b2380a0

Browse files
committed
fix: fuzzy get query returning extra characters
closes #170 closes #172 closes #176
1 parent 1e6dcbf commit b2380a0

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lua/blink/cmp/accept/text-edits.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function text_edits.guess_text_edit(item)
8080
-- convert to 0-index
8181
return {
8282
range = {
83-
start = { line = current_line - 1, character = range[1] },
83+
start = { line = current_line - 1, character = range[1] - 1 },
84+
-- don't - 1 on the end col since it's exclusive while get_regex_around_cursor assumes inclusive
8485
['end'] = { line = current_line - 1, character = range[2] },
8586
},
8687
newText = word,

lua/blink/cmp/fuzzy/init.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ function fuzzy.get_query()
6767
)
6868
-- Since sub(1, 1) returns a single char string, we need to check if that single char matches
6969
-- and otherwise return an empty string
70-
if range[1] == range[2] and line:sub(range[1] + 1, range[1] + 1):match(cmp_config.keyword_regex) == nil then
71-
return ''
72-
end
73-
return string.sub(line, range[1] + 1, range[2] + 1)
70+
if range[1] == range[2] and line:sub(range[1], range[1]):match(cmp_config.keyword_regex) == nil then return '' end
71+
vim.print(string.sub(line, range[1], range[2]))
72+
return string.sub(line, range[1], range[2])
7473
end
7574

7675
return fuzzy

lua/blink/cmp/utils.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ end
152152
--- @return number[]
153153
--- TODO: switch to return start_col, length to simplify downstream logic
154154
function utils.get_regex_around_cursor(range, regex, exclude_from_prefix_regex)
155-
local current_col = vim.api.nvim_win_get_cursor(0)[2]
155+
local current_col = vim.api.nvim_win_get_cursor(0)[2] + 1
156156
local line = vim.api.nvim_get_current_line()
157157

158158
-- Search backward for the start of the word
159159
local start_col = current_col
160160
while start_col > 0 do
161-
local char = line:sub(start_col, start_col)
161+
local char = line:sub(start_col - 1, start_col - 1)
162162
if char:match(regex) == nil then break end
163163
start_col = start_col - 1
164164
end
165165

166-
local end_col = current_col
166+
local end_col = current_col - 1
167167

168168
-- Search forward for the end of the word if configured
169169
if range == 'full' then
170170
while end_col < #line do
171-
local char = line:sub(end_col + 1, end_col + 1)
171+
local char = line:sub(end_col, end_col)
172172
if char:match(regex) == nil then break end
173173
end_col = end_col + 1
174174
end

0 commit comments

Comments
 (0)