summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-15 14:58:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-15 14:58:01 +0800
commit69522a194a1e0c9a8263a985782d48fe1cc8690b (patch)
tree9f051b0515b7bfb8edd1a3b4e5a4acee11d305c4 /server-beta/src/searcher
parenta0d017be1128485b189c24d47fdd087ae19602cb (diff)
downloadlua-language-server-69522a194a1e0c9a8263a985782d48fe1cc8690b.zip
优化 getLinks
Diffstat (limited to 'server-beta/src/searcher')
-rw-r--r--server-beta/src/searcher/getLinks.lua24
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