summaryrefslogtreecommitdiff
path: root/script-beta/vm/getLinks.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-11 19:47:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-11 19:47:36 +0800
commit0e4da86a34a4162b2d094390e1dc3a6d89f3e7e9 (patch)
tree7d20fe9231ac8c0532886bb713f0188c285e9c79 /script-beta/vm/getLinks.lua
parentf6af139891a40eaadc8197202b198a3965a05c3b (diff)
downloadlua-language-server-0e4da86a34a4162b2d094390e1dc3a6d89f3e7e9.zip
暂存
Diffstat (limited to 'script-beta/vm/getLinks.lua')
-rw-r--r--script-beta/vm/getLinks.lua27
1 files changed, 18 insertions, 9 deletions
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