diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-07-22 20:06:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-07-22 20:06:57 +0800 |
commit | c87edd45eaeb810d251f082995477e52ae8b28b2 (patch) | |
tree | 1a70bc6d51649f09e207d9eb57906918ebf097df /script-beta/vm/eachDef.lua | |
parent | 614dda013272a56d5370b387df69622a168090a4 (diff) | |
download | lua-language-server-c87edd45eaeb810d251f082995477e52ae8b28b2.zip |
如果跨文件后没有其他定义,则将return值作为定义
Diffstat (limited to 'script-beta/vm/eachDef.lua')
-rw-r--r-- | script-beta/vm/eachDef.lua | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 423b9e8d..deb44174 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -5,21 +5,21 @@ local files = require 'files' local m = {} -function m.searchFileReturn(results, ast) +function m.searchFileReturn(results, ast, index) local returns = ast.returns for _, ret in ipairs(returns) do - local first = ret[1] - if first then - local newRes = m.eachDef(ret[1]) + local exp = ret[index] + if exp then + local newRes = m.eachDef(ret[index]) if #newRes == 0 then - newRes[1] = first + newRes[1] = exp end vm.mergeResults(results, newRes) end end end -function m.require(results, args) +function m.require(results, args, index) local reqName = args[1] and args[1][1] if not reqName then return @@ -28,7 +28,21 @@ function m.require(results, args) for _, uri in ipairs(uris) do local ast = files.getAst(uri) if ast then - m.searchFileReturn(results, ast.ast) + m.searchFileReturn(results, ast.ast, index) + end + end +end + +function m.dofile(results, args, index) + local reqName = args[1] and args[1][1] + if not reqName then + return + end + local uris = ws.findUrisByFilePath(reqName, true) + for _, uri in ipairs(uris) do + local ast = files.getAst(uri) + if ast then + m.searchFileReturn(results, ast.ast, index) end end end @@ -36,12 +50,20 @@ end function m.searchDefAcrossRequire(results) for _, source in ipairs(results) do local func, args, index = guide.getCallValue(source) - if func and index == 1 then - local lib = vm.getLibrary(func) - if lib and lib.name == 'require' then - m.require(results, args) - end + if not func then + goto CONTINUE + end + local lib = vm.getLibrary(func) + if not lib then + goto CONTINUE + end + if lib.name == 'require' and index == 1 then + m.require(results, args, index) + end + if lib.name == 'dofile' then + m.dofile(results, args, index) end + ::CONTINUE:: end end |