From 8b400054c659a2beb700cb8ca3d33aea93ee5c5c Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Wed, 22 Jul 2026 17:55:52 +0200 Subject: [PATCH] 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. --- src/main.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.lua b/src/main.lua index 5b888b0..fb8a951 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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("^#", "")