Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle nil line #429

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lua/blink/cmp/sources/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ local function get_buf_text(bufnr)
local line_number = vim.api.nvim_win_get_cursor(0)[1]
local column = vim.api.nvim_win_get_cursor(0)[2]
local line = lines[line_number]
local start_col = column
while start_col > 1 do
local char = line:sub(start_col, start_col)
if char:match('[%w_\\-]') == nil then
start_col = start_col + 1
break
if line ~= nil then
local start_col = column
while start_col > 1 do
local char = line:sub(start_col, start_col)
if char:match('[%w_\\-]') == nil then
start_col = start_col + 1
break
end
start_col = start_col - 1
end
start_col = start_col - 1
end
local end_col = column
while end_col < #line do
local char = line:sub(end_col + 1, end_col + 1)
if char:match('[%w_\\-]') == nil then break end
end_col = end_col + 1
local end_col = column
while end_col < #line do
local char = line:sub(end_col + 1, end_col + 1)
if char:match('[%w_\\-]') == nil then break end
end_col = end_col + 1
end
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)
end
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)

return table.concat(lines, '\n')
end
Expand Down