summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Hahn <hahn.kev@gmail.com>2022-08-01 23:32:13 +0700
committerKevin Hahn <hahn.kev@gmail.com>2022-08-02 10:07:22 +0700
commitb3589ccaaa3729ff8d2c05142a4a1bb2c847522f (patch)
treeb80dc1311fbbe40685f6edda20f5037db0f3e202
parenteecbfae0e6d846f20bc836b5ee8a706501b2db40 (diff)
downloadlua-language-server-b3589ccaaa3729ff8d2c05142a4a1bb2c847522f.zip
allow table fields assigned to local functions to show as functions in autocomplete
-rw-r--r--script/core/completion/completion.lua5
-rw-r--r--script/vm/vm.lua14
2 files changed, 17 insertions, 2 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 2b806314..53919f51 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -485,7 +485,7 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP
end
local function checkFieldThen(state, name, src, word, startPos, position, parent, oop, results)
- local value = vm.getObjectValue(src) or src
+ local value = vm.getObjectFunctionValue(src) or src
local kind = define.CompletionItemKind.Field
if value.type == 'function'
or value.type == 'doc.type.function' then
@@ -565,7 +565,8 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o
end
local funcLabel
if config.get(state.uri, 'Lua.completion.showParams') then
- local value = vm.getObjectValue(src) or src
+ --- TODO determine if getlocal should be a function here too
+ local value = vm.getObjectFunctionValue(src) or src
if value.type == 'function'
or value.type == 'doc.type.function' then
funcLabel = name .. getParams(value, oop)
diff --git a/script/vm/vm.lua b/script/vm/vm.lua
index 8117d311..b9eccfa3 100644
--- a/script/vm/vm.lua
+++ b/script/vm/vm.lua
@@ -64,6 +64,20 @@ function m.getObjectValue(source)
return nil
end
+---@param source parser.object
+---@return parser.object?
+function m.getObjectFunctionValue(source)
+ local value = m.getObjectValue(source)
+ if value == nil then return end
+ if value.type == 'function' or value.type == 'doc.type.function' then
+ return value
+ end
+ if value.type == 'getlocal' then
+ return m.getObjectFunctionValue(value.node)
+ end
+ return nil
+end
+
m.cacheTracker = setmetatable({}, weakMT)
function m.flushCache()