fix: add filterText so variables match when typing without # prefix

Variable labels use # prefix (#instTestTimer) but users type without #
(instTestTimer). Without filterText, the client filters using the label
and #instTestTimer doesn't match instTestTimer, so the variable never
appears in autocomplete. Setting filterText to the bare variable name
fixes this.

Also removed aggressive fallback in else branch that treated any word
typed as function call context even without a ( in the line.
This commit is contained in:
2026-07-22 14:19:02 +02:00
parent eb62107066
commit a33d15d238
+3 -3
View File
@@ -838,6 +838,7 @@ function handlers.textDocument_completion(params)
if prefix == "" or name:upper():find("^" .. prefix:upper(), 1, true) then if prefix == "" or name:upper():find("^" .. prefix:upper(), 1, true) then
table.insert(items, { table.insert(items, {
label = "#" .. name, label = "#" .. name,
filterText = name,
kind = 13, kind = 13,
detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"), detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"),
insertText = "#" .. name, insertText = "#" .. name,
@@ -933,9 +934,6 @@ function handlers.textDocument_completion(params)
else else
-- Check if we're inside a function call (e.g., after instTestTimer() -- Check if we're inside a function call (e.g., after instTestTimer()
local call_name = get_call_context(line, col) local call_name = get_call_context(line, col)
if not call_name and col > 0 then
call_name = line:sub(1, col):match("([%w_]+)%s*$")
end
local call_params = call_name and resolve_call_params(call_name, doc.variables, doc.types) local call_params = call_name and resolve_call_params(call_name, doc.variables, doc.types)
-- Check context before cursor -- Check context before cursor
@@ -977,6 +975,7 @@ function handlers.textDocument_completion(params)
if word_prefix == "" or name:upper():find("^" .. word_prefix:upper(), 1, true) then if word_prefix == "" or name:upper():find("^" .. word_prefix:upper(), 1, true) then
table.insert(items, { table.insert(items, {
label = "#" .. name, label = "#" .. name,
filterText = name,
kind = 13, kind = 13,
detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"), detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"),
insertText = "#" .. name, insertText = "#" .. name,
@@ -1010,6 +1009,7 @@ function handlers.textDocument_completion(params)
if word_prefix == "" or name:upper():find("^" .. word_prefix:upper(), 1, true) then if word_prefix == "" or name:upper():find("^" .. word_prefix:upper(), 1, true) then
table.insert(items, { table.insert(items, {
label = "#" .. name, label = "#" .. name,
filterText = name,
kind = 13, kind = 13,
detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"), detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"),
insertText = "#" .. name, insertText = "#" .. name,