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:
+10
-2
@@ -848,11 +848,19 @@ function handlers.textDocument_completion(params)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif trigger == "." then
|
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
|
while prefix_start > 0 and line:sub(prefix_start, prefix_start):match("[%w_]") do
|
||||||
prefix_start = prefix_start - 1
|
prefix_start = prefix_start - 1
|
||||||
end
|
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
|
if prefix ~= "" then
|
||||||
local var_name = prefix:gsub("^#", "")
|
local var_name = prefix:gsub("^#", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user