Skip to content

Commit 38b3ad6

Browse files
authored
fix: handle nil line (#429)
1 parent 7ceff61 commit 38b3ad6

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lua/blink/cmp/sources/buffer.lua

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@ local function get_buf_text(bufnr)
1313
local line_number = vim.api.nvim_win_get_cursor(0)[1]
1414
local column = vim.api.nvim_win_get_cursor(0)[2]
1515
local line = lines[line_number]
16-
local start_col = column
17-
while start_col > 1 do
18-
local char = line:sub(start_col, start_col)
19-
if char:match('[%w_\\-]') == nil then
20-
start_col = start_col + 1
21-
break
16+
if line ~= nil then
17+
local start_col = column
18+
while start_col > 1 do
19+
local char = line:sub(start_col, start_col)
20+
if char:match('[%w_\\-]') == nil then
21+
start_col = start_col + 1
22+
break
23+
end
24+
start_col = start_col - 1
2225
end
23-
start_col = start_col - 1
24-
end
25-
local end_col = column
26-
while end_col < #line do
27-
local char = line:sub(end_col + 1, end_col + 1)
28-
if char:match('[%w_\\-]') == nil then break end
29-
end_col = end_col + 1
26+
local end_col = column
27+
while end_col < #line do
28+
local char = line:sub(end_col + 1, end_col + 1)
29+
if char:match('[%w_\\-]') == nil then break end
30+
end_col = end_col + 1
31+
end
32+
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)
3033
end
31-
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)
3234

3335
return table.concat(lines, '\n')
3436
end

0 commit comments

Comments
 (0)