diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-25 10:16:26 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-25 10:16:26 +0800 |
commit | 0d1dc69335146a5024419cc03f155c17d33c0d4f (patch) | |
tree | c922e1094f1a2640df8b6d74a7097ff54e5f4258 | |
parent | 6478e7db3913c4ab76a5a2735569d33a7dc7ca62 (diff) | |
download | lua-language-server-0d1dc69335146a5024419cc03f155c17d33c0d4f.zip |
暂存
-rw-r--r-- | server-beta/src/searcher/eachField.lua | 19 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 28 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 32 |
3 files changed, 75 insertions, 4 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua new file mode 100644 index 00000000..c55902ff --- /dev/null +++ b/server-beta/src/searcher/eachField.lua @@ -0,0 +1,19 @@ +local function ofLocal(seacher, source, callback) + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'getlocal' then + local parent = ref.parent + + end + end + end +end + +return function (seacher, source, callback) + if source.type == 'local' then + ofLocal(seacher, source, callback) + elseif source.type == 'getlocal' + or source.type == 'setlocal' then + ofLocal(seacher, source.node, callback) + end +end diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua index 47cb8f27..94419c18 100644 --- a/server-beta/src/searcher/eachRef.lua +++ b/server-beta/src/searcher/eachRef.lua @@ -1,3 +1,5 @@ +local guide = require 'parser.guide' + local function ofLocal(searcher, loc, callback) callback { searcher = searcher, @@ -23,11 +25,37 @@ local function ofLocal(searcher, loc, callback) end end +local function ofGlobal(searcher, source, callback) + local node = source.node + local key = guide.getKeyName(source) + searcher.node:eachField(node, function (info) + local src = info.source + if key == guide.getKeyName(src) then + if src.type == 'setglobal' then + callback { + searcher = searcher, + source = src, + mode = 'set', + } + elseif src.type == 'getglobal' then + callback { + searcher = searcher, + source = src, + mode = 'get', + } + end + end + end) +end + return function (searcher, source, callback) if source.type == 'local' then ofLocal(searcher, source, callback) elseif source.type == 'getlocal' or source.type == 'setlocal' then ofLocal(searcher, source.node, callback) + elseif source.type == 'setglobal' + or source.type == 'getglobal' then + ofGlobal(searcher, source, callback) end end diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index b146ed82..ea9d10ed 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -4,6 +4,7 @@ local util = require 'utility' local getValue = require 'searcher.getValue' local getField = require 'searcher.getField' local eachRef = require 'searcher.eachRef' +local eachField = require 'searcher.eachField' local setmetatable = setmetatable local assert = assert @@ -53,7 +54,7 @@ function mt:getField(source) return getField(self, source) end ---- 获取所有的定义(不递归) +--- 获取所有的引用(不递归) function mt:eachRef(source, callback) local lock <close> = self:lock('eachRef', source) if not lock then @@ -74,6 +75,27 @@ function mt:eachRef(source, callback) end) end +--- 获取所有的field(不递归) +function mt:eachField(source, callback) + local lock <close> = self:lock('eachField', source) + if not lock then + return + end + local cache = self.cache.eachField[source] + if cache then + for i = 1, #cache do + callback(cache[i]) + end + return + end + cache = {} + self.cache.eachField[source] = cache + eachField(self, source, function (info) + cache[#cache+1] = info + callback(info) + end) +end + ---@class engineer local m = {} @@ -86,11 +108,13 @@ function m.create(uri) ast = ast.ast, uri = uri, cache = { - eachRef = {}, + eachRef = {}, + eachField = {}, }, locked = { - getValue = {}, - eachRef = {}, + getValue = {}, + eachRef = {}, + eachField = {}, } }, mt) return searcher |