diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-11 18:41:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-11 18:41:52 +0800 |
commit | 9d8602cedb35b2e6954b9ccbf26311c1662a2ff0 (patch) | |
tree | b878d7fc05fe839553dc721dc251e6df0a2ec75a /script-beta/vm/getLinks.lua | |
parent | 1ae7b425b75f630b3cdb3479137ace7215389580 (diff) | |
download | lua-language-server-9d8602cedb35b2e6954b9ccbf26311c1662a2ff0.zip |
更新
Diffstat (limited to 'script-beta/vm/getLinks.lua')
-rw-r--r-- | script-beta/vm/getLinks.lua | 39 |
1 files changed, 30 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 |