diff options
-rw-r--r-- | server-beta/src/core/reference.lua | 4 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 12 | ||||
-rw-r--r-- | server-beta/src/searcher/getLinks.lua | 24 |
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 |