diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-15 14:58:01 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-15 14:58:01 +0800 |
commit | 69522a194a1e0c9a8263a985782d48fe1cc8690b (patch) | |
tree | 9f051b0515b7bfb8edd1a3b4e5a4acee11d305c4 /server-beta/src/searcher | |
parent | a0d017be1128485b189c24d47fdd087ae19602cb (diff) | |
download | lua-language-server-69522a194a1e0c9a8263a985782d48fe1cc8690b.zip |
优化 getLinks
Diffstat (limited to 'server-beta/src/searcher')
-rw-r--r-- | server-beta/src/searcher/getLinks.lua | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/server-beta/src/searcher/getLinks.lua b/server-beta/src/searcher/getLinks.lua index db1072e3..3e204e1f 100644 --- a/server-beta/src/searcher/getLinks.lua +++ b/server-beta/src/searcher/getLinks.lua @@ -3,18 +3,26 @@ local searcher = require 'searcher.searcher' local function getLinks(root) local cache = {} - guide.eachSourceType(root, 'call', function (source) - local uris = searcher.getLinkUris(source) - if uris then - for i = 1, #uris do - local uri = uris[i] - if not cache[uri] then - cache[uri] = {} + local ok + guide.eachSpecialOf(root, 'require', function (source) + local call = source.parent + if call.type == 'call' then + local uris = searcher.getLinkUris(call) + if uris then + ok = true + for i = 1, #uris do + local uri = uris[i] + if not cache[uri] then + cache[uri] = {} + end + cache[uri][#cache[uri]+1] = call end - cache[uri][#cache[uri]+1] = source end end end) + if not ok then + return nil + end return cache end |