summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-08-03 15:10:31 +0800
committerGitHub <noreply@github.com>2022-08-03 15:10:31 +0800
commite8f6fd3522b99e627ed953bb6c68d79cf27ac827 (patch)
tree167aff63c6bc3d181649b57a2155078190f9c5e2
parent0f0c1c517f9ba14dcb6f947166b980a93ccb69d3 (diff)
parente1c6b8037f59b93257f540f97d2b94a46202cb4c (diff)
downloadlua-language-server-e8f6fd3522b99e627ed953bb6c68d79cf27ac827.zip
Merge pull request #1427 from FAForever/function-field-show-params
allow table fields assigned to local functions to show as functions
-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 76c8ba2e..8f28e450 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..5437b632 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 value
+end
+
m.cacheTracker = setmetatable({}, weakMT)
function m.flushCache()