Skip to content

Commit e8f6fd3

Browse files
authored
Merge pull request #1427 from FAForever/function-field-show-params
allow table fields assigned to local functions to show as functions
2 parents 0f0c1c5 + e1c6b80 commit e8f6fd3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

script/core/completion/completion.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP
485485
end
486486

487487
local function checkFieldThen(state, name, src, word, startPos, position, parent, oop, results)
488-
local value = vm.getObjectValue(src) or src
488+
local value = vm.getObjectFunctionValue(src) or src
489489
local kind = define.CompletionItemKind.Field
490490
if value.type == 'function'
491491
or value.type == 'doc.type.function' then
@@ -565,7 +565,8 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o
565565
end
566566
local funcLabel
567567
if config.get(state.uri, 'Lua.completion.showParams') then
568-
local value = vm.getObjectValue(src) or src
568+
--- TODO determine if getlocal should be a function here too
569+
local value = vm.getObjectFunctionValue(src) or src
569570
if value.type == 'function'
570571
or value.type == 'doc.type.function' then
571572
funcLabel = name .. getParams(value, oop)

script/vm/vm.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ function m.getObjectValue(source)
6464
return nil
6565
end
6666

67+
---@param source parser.object
68+
---@return parser.object?
69+
function m.getObjectFunctionValue(source)
70+
local value = m.getObjectValue(source)
71+
if value == nil then return end
72+
if value.type == 'function' or value.type == 'doc.type.function' then
73+
return value
74+
end
75+
if value.type == 'getlocal' then
76+
return m.getObjectFunctionValue(value.node)
77+
end
78+
return value
79+
end
80+
6781
m.cacheTracker = setmetatable({}, weakMT)
6882

6983
function m.flushCache()

0 commit comments

Comments
 (0)