fix: DB completion path parsing, array-of-UDT resolution, blink source registration

- Fix path extraction pattern (missing closing quote, extra capture group)
- Add Array[..] of "UdtName" detection for nested member resolution
- Remove vim.schedule_wrap from DB member callback (causes blink.cmp timeout)
- Add built-in instruction parameter fallback (IEC_TIMER IN/PT/Q/ET)
- Ensure DB cache is populated on demand in completion source
- Make try_register() succeed without cmp.add_source_provider API
- docs: add blink.cmp source config steps to installation guide
This commit is contained in:
2026-07-22 20:26:16 +02:00
parent 3776ce33ff
commit 0a0b5c9bf1
3 changed files with 86 additions and 26 deletions
+46 -13
View File
@@ -239,10 +239,16 @@ function M:get_completions(context, callback)
local db_parser = require("tia.db_parser")
local db_name = active_portion:match('"([%w_]+)"')
-- Ensure cache is populated
if db_name and db_parser.get_cache_count() == 0 then
local ws = require("tia.workspace_types")
ws.scan_project_dbs(bufnr)
end
if db_name then
local db = db_parser.get_db(db_name)
if db then
local path = active_portion:match('"[^"]+%"%.([%w_.]*)')
local path = active_portion:match('"[^"]+"%.([%w_.]*)$')
-- Resolve nested path through DB members
local current_type = nil
@@ -269,15 +275,23 @@ function M:get_completions(context, callback)
if found_member then
resolved_path = part
local nested_type = nil
if found_member.is_udt then
-- This member is a UDT type, continue resolving
nested_type = found_member.type
else
-- Check for array of UDT: Array[..] of "TypeName"
local array_udt = found_member.raw_type:match('Array%b[]%s*of%s*"([^"]+)"')
if array_udt then
nested_type = array_udt
end
end
if nested_type then
local udt_parser = require("tia.udt_parser")
current_members = udt_parser.get_udt_members(found_member.type)
current_type = found_member.type
current_members = udt_parser.get_udt_members(nested_type)
current_type = nested_type
else
-- This is a basic type, can't continue
if i < #path_parts then
-- There are more parts but this isn't a UDT
found = false
break
end
@@ -319,14 +333,11 @@ function M:get_completions(context, callback)
detail = m.raw_type,
})
end
local wrapped_callback = vim.schedule_wrap(function(response)
callback({
items = response.items,
is_incomplete_backward = false,
is_incomplete_forward = false,
})
end)
wrapped_callback({ items = items })
callback({
items = items,
is_incomplete_backward = false,
is_incomplete_forward = false,
})
return
end
end
@@ -959,6 +970,28 @@ function M:get_completions(context, callback)
end
if not is_udt and not is_fb then
-- Check built-in instructions (IEC_TIMER, TON, etc.)
local builtin = require("tia.builtin_instructions")
local builtin_params = builtin.get_parameters(var_type)
if builtin_params then
local items = {}
for _, inp in ipairs(builtin_params.inputs or {}) do
table.insert(items, {
label = inp.name,
kind = vim.lsp.protocol.CompletionItemKind.Field,
detail = (inp.type or "ANY") .. " (Input)",
})
end
for _, out in ipairs(builtin_params.outputs or {}) do
table.insert(items, {
label = out.name,
kind = vim.lsp.protocol.CompletionItemKind.Field,
detail = (out.type or "ANY") .. " (Output)",
})
end
wrapped_callback({ items = items })
return
end
wrapped_callback({ items = {} })
return
end