summaryrefslogtreecommitdiff
path: root/script-beta/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-11 18:41:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-11 18:41:52 +0800
commit9d8602cedb35b2e6954b9ccbf26311c1662a2ff0 (patch)
treeb878d7fc05fe839553dc721dc251e6df0a2ec75a /script-beta/vm
parent1ae7b425b75f630b3cdb3479137ace7215389580 (diff)
downloadlua-language-server-9d8602cedb35b2e6954b9ccbf26311c1662a2ff0.zip
更新
Diffstat (limited to 'script-beta/vm')
-rw-r--r--script-beta/vm/getLinks.lua39
-rw-r--r--script-beta/vm/guideInterface.lua7
2 files changed, 37 insertions, 9 deletions
diff --git a/script-beta/vm/getLinks.lua b/script-beta/vm/getLinks.lua
index b034fd24..41318e1c 100644
--- a/script-beta/vm/getLinks.lua
+++ b/script-beta/vm/getLinks.lua
@@ -3,11 +3,36 @@ local vm = require 'vm.vm'
local files = require 'files'
local function getFileLinks(uri)
-
+ local links = {}
+ local ast = files.getAst(uri)
+ if not ast then
+ return links
+ end
+ guide.eachSpecialOf(ast.ast, 'require', function (source)
+ local call = source.parent
+ if not call or call.type ~= 'call' then
+ return
+ end
+ end)
+ return links
end
local function getLinksTo(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
+ end
+ end
+ end
+ return links
end
function vm.getLinksTo(uri)
@@ -21,11 +46,7 @@ function vm.getLinksTo(uri)
end
function vm.getFileLinks(uri)
- local cache = vm.getCache('getFileLinks')[uri]
- if cache ~= nil then
- return cache
- end
- cache = getFileLinks(uri)
- vm.getCache('getFileLinks')[uri] = cache
- return cache
+ local cache = files.getCache(uri)
+ cache.links = cache.links or getFileLinks(uri)
+ return cache.links
end
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
index f3ce2740..f7a35b6d 100644
--- a/script-beta/vm/guideInterface.lua
+++ b/script-beta/vm/guideInterface.lua
@@ -7,6 +7,9 @@ local m = {}
function m.searchFileReturn(results, ast, index)
local returns = ast.returns
+ if not returns then
+ return
+ end
for _, ret in ipairs(returns) do
local exp = ret[index]
if exp then
@@ -80,3 +83,7 @@ end
function vm.interface.global(name)
return vm.getGlobals(name)
end
+
+function vm.interface.links(uri)
+ return vm.getLinksTo(uri)
+end