From b3589ccaaa3729ff8d2c05142a4a1bb2c847522f Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Mon, 1 Aug 2022 23:32:13 +0700 Subject: allow table fields assigned to local functions to show as functions in autocomplete --- script/core/completion/completion.lua | 5 +++-- script/vm/vm.lua | 14 ++++++++++++++ 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() -- cgit v1.2.3