diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-07-23 16:53:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-07-23 16:53:37 +0800 |
commit | 7a9c274c01e50684d4c094c7d5db45670336ff2f (patch) | |
tree | f09f902e779c8cfaafccec85f190d91766e8c19c | |
parent | a27677a6d4beca0e898d691e36d94df498ffb1d1 (diff) | |
download | lua-language-server-7a9c274c01e50684d4c094c7d5db45670336ff2f.zip |
简化 require 实现
-rw-r--r-- | script-beta/parser/guide.lua | 9 | ||||
-rw-r--r-- | script-beta/vm/eachDef.lua | 63 | ||||
-rw-r--r-- | script-beta/vm/guideInterface.lua | 6 |
3 files changed, 14 insertions, 64 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index f3224e4c..b10490dc 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1219,6 +1219,7 @@ function m.checkSameSimpleInCall(status, ref, start, queue) obj = obj, start = start, force = true, + call = true, } end end @@ -1288,6 +1289,9 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) results[#results+1] = ref end end + if data.call then + results[#results+1] = ref + end else if ref.type == 'setfield' or ref.type == 'getfield' @@ -1330,12 +1334,17 @@ function m.searchSameFields(status, simple, mode) end if first and first.tag ~= '_ENV' then m.checkSameSimpleInBranch(status, first, 0, queue) + m.checkSameSimpleInCall(status, first, 0, queue) + m.checkSameSimpleInGlobal(status, first, 0, queue) end else queue[#queue+1] = { obj = first, start = 1, } + if first then + m.checkSameSimpleInCall(status, first, 1, queue) + end end for i = 1, 999 do local data = queue[i] diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index deb44174..ad844759 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -5,68 +5,6 @@ local files = require 'files' local m = {} -function m.searchFileReturn(results, ast, index) - local returns = ast.returns - for _, ret in ipairs(returns) do - local exp = ret[index] - if exp then - local newRes = m.eachDef(ret[index]) - if #newRes == 0 then - newRes[1] = exp - end - vm.mergeResults(results, newRes) - end - end -end - -function m.require(results, args, index) - local reqName = args[1] and args[1][1] - if not reqName then - return - end - local uris = ws.findUrisByRequirePath(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 - -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 - -function m.searchDefAcrossRequire(results) - for _, source in ipairs(results) do - local func, args, index = guide.getCallValue(source) - 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 - function m.searchLibrary(source, results) if not source then return @@ -86,7 +24,6 @@ function m.eachDef(source, results) end local myResults = guide.requestDefinition(source, vm.interface) - m.searchDefAcrossRequire(myResults) vm.mergeResults(results, myResults) m.searchLibrary(source, results) m.searchLibrary(guide.getObjectValue(source), results) diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index 454390dc..37d47c35 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -13,7 +13,11 @@ function m.searchFileReturn(results, ast, index) vm.mergeResults(results, { exp }) else local newRes = vm.getDefs(exp) - vm.mergeResults(results, newRes) + if #newRes > 0 then + vm.mergeResults(results, newRes) + else + vm.mergeResults(results, { exp }) + end end end end |