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("^#", "")