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 /server-beta/src/searcher/init.lua | |
parent | 6478e7db3913c4ab76a5a2735569d33a7dc7ca62 (diff) | |
download | lua-language-server-0d1dc69335146a5024419cc03f155c17d33c0d4f.zip |
暂存
Diffstat (limited to 'server-beta/src/searcher/init.lua')
-rw-r--r-- | server-beta/src/searcher/init.lua | 32 |
1 files changed, 28 insertions, 4 deletions
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 |