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 | |
parent | 614dda013272a56d5370b387df69622a168090a4 (diff) | |
download | lua-language-server-c87edd45eaeb810d251f082995477e52ae8b28b2.zip |
如果跨文件后没有其他定义,则将return值作为定义
Diffstat (limited to 'script-beta/vm')
-rw-r--r-- | script-beta/vm/eachDef.lua | 46 | ||||
-rw-r--r-- | script-beta/vm/guideInterface.lua | 36 |
2 files changed, 62 insertions, 20 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 diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index db576032..e9fe4084 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -4,21 +4,22 @@ local ws = require 'workspace' local m = {} -function m.searchFileReturn(results, ast) +function m.searchFileReturn(results, ast, index) local returns = ast.returns for _, ret in ipairs(returns) do - if ret[1] then - if ret[1].type == 'table' then - vm.mergeResults(results, { ret[1] }) + local exp = ret[index] + if exp then + if exp.type == 'table' then + vm.mergeResults(results, { exp }) else - local newRes = vm.getDefs(ret[1]) + local newRes = vm.getDefs(exp) vm.mergeResults(results, newRes) end end end end -function m.require(args) +function m.require(args, index) local reqName = args[1] and args[1][1] if not reqName then return nil @@ -28,7 +29,23 @@ function m.require(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 + return results +end + +function m.dofile(args, index) + local reqName = args[1] and args[1][1] + if not reqName then + return + end + local results = {} + 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 return results @@ -42,6 +59,9 @@ function vm.interface.call(func, args, index) return nil end if lib.name == 'require' and index == 1 then - return m.require(args) + return m.require(args, index) + end + if lib.name == 'dofile' then + return m.dofile(args, index) end end |