diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-21 20:45:23 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-21 20:45:23 +0800 |
commit | 317bced17780ebdeed67ed17590b7e2598b2b55a (patch) | |
tree | faa924c96bfbe9305434de0ca70e6649fd0d8113 /script/vm/compiler.lua | |
parent | bb1244fa62c0158490d2e54da0a19f28f16fe994 (diff) | |
download | lua-language-server-317bced17780ebdeed67ed17590b7e2598b2b55a.zip |
update
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 515a8ebe..ff1e3a15 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -554,29 +554,32 @@ local function getReturn(func, index, args) end return vm.compileNode(ast) end - local funcs = vm.getMatchedFunctions(func, args) + local funcNode = vm.compileNode(func) ---@type vm.node? local result - for _, mfunc in ipairs(funcs) do - local returnObject = vm.getReturnOfFunction(mfunc, index) - if returnObject then - local returnNode = vm.compileNode(returnObject) - for rnode in returnNode:eachObject() do - if rnode.type == 'generic' then - returnNode = rnode:resolve(guide.getUri(func), args) - break - end - end - if returnNode then + for mfunc in funcNode:eachObject() do + if mfunc.type == 'function' + or mfunc.type == 'doc.type.function' then + local returnObject = vm.getReturnOfFunction(mfunc, index) + if returnObject then + local returnNode = vm.compileNode(returnObject) for rnode in returnNode:eachObject() do - -- TODO: narrow type - if rnode.type ~= 'doc.generic.name' then - result = result or vm.createNode() - result:merge(rnode) + if rnode.type == 'generic' then + returnNode = rnode:resolve(guide.getUri(func), args) + break end end - if result and returnNode:isOptional() then - result:addOptional() + if returnNode then + for rnode in returnNode:eachObject() do + -- TODO: narrow type + if rnode.type ~= 'doc.generic.name' then + result = result or vm.createNode() + result:merge(rnode) + end + end + if result and returnNode:isOptional() then + result:addOptional() + end end end end @@ -1821,6 +1824,36 @@ local function compileByGlobal(source) end end +---@param source parser.object +local function compileByCall(source) + local call = source.parent + if not call + or call.type ~= 'call' + or call.node ~= source then + return + end + local funcs = vm.getMatchedFunctions(source, call.args) + local myNode = vm.getNode(source) + if not myNode then + return + end + local needRemove + for n in myNode:eachObject() do + if n.type == 'function' + or n.type == 'doc.type.function' then + if not util.arrayHas(funcs, n) then + if not needRemove then + needRemove = vm.createNode() + end + needRemove:merge(n) + end + end + end + if needRemove then + myNode:removeNode(needRemove) + end +end + ---@param source vm.object ---@return vm.node function vm.compileNode(source) @@ -1845,6 +1878,7 @@ function vm.compileNode(source) vm.setNode(source, node, true) compileByGlobal(source) compileByNode(source) + compileByCall(source) node = vm.getNode(source) |