diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-11 19:47:36 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-11 19:47:36 +0800 |
commit | 0e4da86a34a4162b2d094390e1dc3a6d89f3e7e9 (patch) | |
tree | 7d20fe9231ac8c0532886bb713f0188c285e9c79 | |
parent | f6af139891a40eaadc8197202b198a3965a05c3b (diff) | |
download | lua-language-server-0e4da86a34a4162b2d094390e1dc3a6d89f3e7e9.zip |
暂存
-rw-r--r-- | script-beta/parser/guide.lua | 56 | ||||
-rw-r--r-- | script-beta/provider/diagnostic.lua | 11 | ||||
-rw-r--r-- | script-beta/vm/eachRef.lua | 2 | ||||
-rw-r--r-- | script-beta/vm/getLinks.lua | 27 | ||||
-rw-r--r-- | script-beta/vm/guideInterface.lua | 2 | ||||
-rw-r--r-- | script-beta/vm/init.lua | 1 |
6 files changed, 59 insertions, 40 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index fbbd154b..d276d822 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1434,7 +1434,7 @@ function m.searchSameFields(status, simple, mode) end end -function m.getCallerInSameFile(status, func, index) +function m.getCallerInSameFile(status, func) -- 搜索所有所在函数的调用者 local funcRefs = m.status(status) m.searchRefOfValue(funcRefs, func) @@ -1449,27 +1449,14 @@ function m.getCallerInSameFile(status, func, index) calls[#calls+1] = call end end - -- 搜索调用者的返回值 - if #calls == 0 then - return - end - local selects = {} - for i = 1, #calls do - local parent = calls[i].parent - if parent.type == 'select' and parent.index == index then - selects[#selects+1] = parent.parent - end - local extParent = calls[i].extParent - if extParent then - for j = 1, #extParent do - local ext = extParent[j] - if ext.type == 'select' and ext.index == index then - selects[#selects+1] = ext.parent - end - end - end + return calls +end + +function m.getCallerCrossFiles(status, main) + if status.interface.link then + return status.interface.link(main.uri) end - return selects + return {} end function m.searchRefsAsFunctionReturn(status, obj, mode) @@ -1497,16 +1484,33 @@ function m.searchRefsAsFunctionReturn(status, obj, mode) if not index then return end - local selects + local calls if currentFunc.type == 'main' then - selects = m.getCallerCrossFiles(status, currentFunc, index) + calls = m.getCallerCrossFiles(status, currentFunc) else - selects = m.getCallerInSameFile(status, currentFunc, index) + calls = m.getCallerInSameFile(status, currentFunc) end - -- 搜索调用者的引用 - if not selects then + -- 搜索调用者的返回值 + if #calls == 0 then return end + local selects = {} + for i = 1, #calls do + local parent = calls[i].parent + if parent.type == 'select' and parent.index == index then + selects[#selects+1] = parent.parent + end + local extParent = calls[i].extParent + if extParent then + for j = 1, #extParent do + local ext = extParent[j] + if ext.type == 'select' and ext.index == index then + selects[#selects+1] = ext.parent + end + end + end + end + -- 搜索调用者的引用 for i = 1, #selects do m.searchRefs(status, selects[i]) end diff --git a/script-beta/provider/diagnostic.lua b/script-beta/provider/diagnostic.lua index 87b8cb26..92aa01c2 100644 --- a/script-beta/provider/diagnostic.lua +++ b/script-beta/provider/diagnostic.lua @@ -179,7 +179,7 @@ function m.refresh(uri) return files.globalVersion end) if uri then - m.doDiagnostic(uri, true, true) + m.doDiagnostic(uri) end if not m._start then return @@ -189,7 +189,7 @@ function m.refresh(uri) end) local clock = os.clock() if uri then - m.doDiagnostic(uri, true, false) + m.doDiagnostic(uri) end for destUri in files.eachFile() do if destUri ~= uri then @@ -219,7 +219,12 @@ files.watch(function (env, uri) if env == 'remove' then m.clear(uri) elseif env == 'update' then - m.doDiagnostic(uri) + await.create(function () + await.delay(function () + return files.globalVersion + end) + m.doDiagnostic(uri) + end) end end) diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua index 270a6875..232cb237 100644 --- a/script-beta/vm/eachRef.lua +++ b/script-beta/vm/eachRef.lua @@ -8,7 +8,7 @@ local function eachRef(source, results) return results end - local myResults = guide.requestReference(source) + local myResults = guide.requestReference(source, vm.interface) vm.mergeResults(results, myResults) lock() diff --git a/script-beta/vm/getLinks.lua b/script-beta/vm/getLinks.lua index 41318e1c..6a19fbc8 100644 --- a/script-beta/vm/getLinks.lua +++ b/script-beta/vm/getLinks.lua @@ -1,6 +1,7 @@ local guide = require 'parser.guide' local vm = require 'vm.vm' local files = require 'files' +local ws = require 'workspace' local function getFileLinks(uri) local links = {} @@ -13,22 +14,30 @@ local function getFileLinks(uri) if not call or call.type ~= 'call' then return end + local args = call.args + if type(args[1]) ~= 'string' then + return + end + local uris = ws.findUrisByRequirePath(args[1], true) + for _, u in ipairs(uris) do + u = files.asKey(u) + if not links[u] then + links[u] = {} + end + links[u][#links[u]+1] = call + end end) return links end local function getLinksTo(uri) + uri = files.asKey(uri) local links = {} - local mark = {} for u in files.eachFile() do - local l = vm.getFileLinks(u) - for _, lu in ipairs(l) do - if files.eq(uri, lu) then - local ku = files.asKey(u) - if not mark[ku] then - mark[ku] = true - links[#links+1] = u - end + local ls = vm.getFileLinks(u) + if ls[uri] then + for _, l in ipairs(ls[uri]) do + links[#links+1] = l end end end diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index f7a35b6d..f598e788 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -84,6 +84,6 @@ function vm.interface.global(name) return vm.getGlobals(name) end -function vm.interface.links(uri) +function vm.interface.link(uri) return vm.getLinksTo(uri) end diff --git a/script-beta/vm/init.lua b/script-beta/vm/init.lua index ce07264d..bc2b41c1 100644 --- a/script-beta/vm/init.lua +++ b/script-beta/vm/init.lua @@ -7,5 +7,6 @@ require 'vm.getMeta' require 'vm.eachField' require 'vm.eachDef' require 'vm.eachRef' +require 'vm.getLinks' require 'vm.guideInterface' return vm |