From 7a9c274c01e50684d4c094c7d5db45670336ff2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 23 Jul 2020 16:53:37 +0800 Subject: =?UTF-8?q?=E7=AE=80=E5=8C=96=20require=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/parser/guide.lua | 9 ++++++ script-beta/vm/eachDef.lua | 63 --------------------------------------- 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 -- cgit v1.2.3