Optimize Lua complete

pull/1224/head
Zef Hemel 2025-01-26 09:00:10 +01:00
parent 71a414d1d4
commit 9f47c3df30
1 changed files with 33 additions and 31 deletions

View File

@ -68,46 +68,47 @@ event.listen {
failed = true failed = true
end end
end end
if failed then
return
end
local last_prop = prop_parts[#prop_parts] local last_prop = prop_parts[#prop_parts]
if table.includes(LUA_KEYWORDS, last_prop) then if table.includes(LUA_KEYWORDS, last_prop) then
return return
end end
if not failed then local options = {}
local options = {} for key, val in pairs(current_value) do
for key, val in pairs(current_value) do if string.startswith(key, last_prop) and val then
if string.startswith(key, last_prop) and val then if val.call then
if val.call then -- We got a function
-- We got a function if val.body then
if val.body then -- Function defined in Lua
-- Function defined in Lua
table.insert(options, {
label = key .. "(" .. table.concat(val.body.parameters, ", ") ..")",
apply = key .. "(",
detail = "Lua function"
})
else
-- Builtin
table.insert(options, {
label = key .. "()",
apply = key .. "(",
detail = "Lua built-in"
})
end
else
-- Table
table.insert(options, { table.insert(options, {
label = key, label = key .. "(" .. table.concat(val.body.parameters, ", ") ..")",
detail = "Lua table" apply = key .. "(",
detail = "Lua function"
})
else
-- Builtin
table.insert(options, {
label = key .. "()",
apply = key .. "(",
detail = "Lua built-in"
}) })
end end
else
-- Table
table.insert(options, {
label = key,
detail = "Lua table"
})
end end
end end
if #options > 0 then end
return { if #options > 0 then
from = pos - string.len(last_prop), return {
options = options from = pos - string.len(last_prop),
} options = options
end }
end end
end end
} }
@ -139,6 +140,7 @@ template.define_slash_command {
template = template.new 'query[[from index.tag "|^|"]]' template = template.new 'query[[from index.tag "|^|"]]'
} }
-- A query embedded in ${} -- A query embedded in ${}
template.define_slash_command { template.define_slash_command {
name = "query", name = "query",