summaryrefslogtreecommitdiff
path: root/server-beta/src
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
parenta0d017be1128485b189c24d47fdd087ae19602cb (diff)
downloadlua-language-server-69522a194a1e0c9a8263a985782d48fe1cc8690b.zip
优化 getLinks
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/reference.lua4
-rw-r--r--server-beta/src/parser/guide.lua12
-rw-r--r--server-beta/src/searcher/getLinks.lua24
3 files changed, 28 insertions, 12 deletions
diff --git a/server-beta/src/core/reference.lua b/server-beta/src/core/reference.lua
index 8ce807c3..34487d30 100644
--- a/server-beta/src/core/reference.lua
+++ b/server-beta/src/core/reference.lua
@@ -11,7 +11,7 @@ local function isFunction(source, offset)
return offset >= source.start and offset < source.start + #'function'
end
-local function findDef(source, offset, callback)
+local function findRef(source, offset, callback)
if source.type ~= 'local'
and source.type ~= 'getlocal'
and source.type ~= 'setlocal'
@@ -70,7 +70,7 @@ return function (uri, offset)
end
local results = {}
guide.eachSourceContain(ast.ast, offset, function (source)
- findDef(source, offset, function (target, uri)
+ findRef(source, offset, function (target, uri)
results[#results+1] = {
target = target,
uri = files.getOriginUri(uri),
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index c141feb5..c96f7143 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -357,8 +357,16 @@ end
--- 获取指定的 special
function m.eachSpecialOf(ast, name, callback)
- if not ast.special then
-
+ local root = m.getRoot(ast)
+ if not root.specials then
+ return
+ end
+ local specials = root.specials[name]
+ if not specials then
+ return
+ end
+ for i = 1, #specials do
+ callback(specials[i])
end
end
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