From 8d5bf9f99f02c3fd63b74915f03be0961ea75587 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Wed, 22 Jul 2026 15:30:30 +0200 Subject: [PATCH] fix: return full item set on ( trigger to survive auto-close When LazyVim auto-close inserts () after (, nvim-cmp sees ) as the last character and may suppress the popup. By returning variables, builtins, and data types alongside the function params, the response is rich enough that the next keystroke (e.g. typing I after auto-close) triggers a fresh TextChanged completion that re-detects the call context via get_call_context in the else branch. --- src/main.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main.lua b/src/main.lua index e196d4e..5b888b0 100644 --- a/src/main.lua +++ b/src/main.lua @@ -920,17 +920,31 @@ function handlers.textDocument_completion(params) local params = call_name and resolve_call_params(call_name, doc.variables, doc.types) if params then add_param_items(items, params, "") - elseif doc.functions then - for _, func in ipairs(doc.functions) do + end + + -- Also add variables and builtins so completion popup stays rich + -- even if auto-close ( or client-side filtering interferes + if doc.variables then + for name, info in pairs(doc.variables) do table.insert(items, { - label = func.name, - kind = 3, - detail = func.kind:upper(), - insertText = func.name .. "()", - insertTextFormat = 2, + label = "#" .. name, + filterText = "#" .. name, + kind = 13, + detail = "Variable (" .. (info.type or "VAR") .. "): " .. (info.data_type or "unknown"), + insertText = "#" .. name, + insertTextFormat = 1, }) end end + for type_name, _ in pairs(builtin.DATA_TYPES) do + table.insert(items, { label = type_name, kind = 7, detail = "Data type", insertText = type_name, insertTextFormat = 1 }) + end + for fb_name, _ in pairs(builtin.FUNCTION_BLOCKS) do + table.insert(items, { label = fb_name, kind = 6, detail = "Function block", insertText = fb_name, insertTextFormat = 1 }) + end + for func_name, _ in pairs(builtin.FUNCTIONS) do + table.insert(items, { label = func_name, kind = 3, detail = "Function", insertText = func_name, insertTextFormat = 1 }) + end else -- Check if we're inside a function call (e.g., after instTestTimer() local call_name = get_call_context(line, col)