fix: . trigger prefix extraction broken when . not yet in document

When nvim-cmp sends completion before didChange commits the ., the
cursor col is at the word end, but the old code always scanned from
col-1, cutting off the variable's last character (instTestTime vs
instTestTimer). Now checks if the character at col is . or empty;
if so, scans from col-1; otherwise scans from col.
This commit is contained in:
2026-07-22 17:55:52 +02:00
parent cce4059b7e
commit 8b400054c6
+10 -2
View File
@@ -848,11 +848,19 @@ function handlers.textDocument_completion(params)
end
end
elseif trigger == "." then
local prefix_start = col - 1
-- Extract word before cursor, handling both cases:
-- 1) . IS in doc: cursor is after ., scan from col-1
-- 2) . NOT in doc yet: cursor is at word end, scan from col
local scan_end = col
local c = col > 0 and line:sub(col, col) or ""
if c == "" or c == "." then
scan_end = col - 1
end
local prefix_start = scan_end
while prefix_start > 0 and line:sub(prefix_start, prefix_start):match("[%w_]") do
prefix_start = prefix_start - 1
end
local prefix = line:sub(prefix_start + 1, col - 1)
local prefix = scan_end > prefix_start and line:sub(prefix_start + 1, scan_end) or ""
if prefix ~= "" then
local var_name = prefix:gsub("^#", "")