From ae8041708639bb4f316eb43a5e2ce67411928f92 Mon Sep 17 00:00:00 2001 From: Maddison Hellstrom Date: Mon, 2 Dec 2024 16:34:02 -0800 Subject: [PATCH] fix: handle nil line --- lua/blink/cmp/sources/buffer.lua | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lua/blink/cmp/sources/buffer.lua b/lua/blink/cmp/sources/buffer.lua index 0878c7ac..b3a25e6f 100644 --- a/lua/blink/cmp/sources/buffer.lua +++ b/lua/blink/cmp/sources/buffer.lua @@ -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