diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-23 17:31:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-23 17:31:02 +0800 |
commit | 4248038716c6c2281a10af9c0a3f04c6468b1946 (patch) | |
tree | 79361f8df2cf46ab99843e84bba175ea60147da2 /server-beta/src/searcher-old/setmetatable.lua | |
parent | 68541432820dfff4554375c4c424a537943a938d (diff) | |
download | lua-language-server-4248038716c6c2281a10af9c0a3f04c6468b1946.zip |
准备换一个写法试试
Diffstat (limited to 'server-beta/src/searcher-old/setmetatable.lua')
-rw-r--r-- | server-beta/src/searcher-old/setmetatable.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/server-beta/src/searcher-old/setmetatable.lua b/server-beta/src/searcher-old/setmetatable.lua new file mode 100644 index 00000000..7489bf6f --- /dev/null +++ b/server-beta/src/searcher-old/setmetatable.lua @@ -0,0 +1,63 @@ +local guide = require 'parser.guide' + +local function checkIndex(info, key, t, used, call, callback) + if info.mode ~= 'set' then + return + end + local src = info.source + -- t.field -> mt.__index.field + if used[t] then + info.searcher:eachValue(src, function (info) + info.searcher:eachField(info.source, key, callback) + end) + end + -- mt.__index.field -> t.field + info.searcher:eachValue(src, function (info) + local value = info.source + if used[value] then + info.searcher:eachValue(t, function (info) + info.searcher:eachField(info.source, key, callback) + end) + local obj = info.searcher:callReturnOf(call) + if obj then + info.searcher:eachValue(obj, function (info) + info.searcher:eachField(info.source, key, callback) + end) + end + end + end) +end + +return function (self, key, used, found, callback) + self:eachSpecial(function (name, src) + local call = src.parent + if name == 'rawset' then + local t, k = self:callArgOf(call) + if used[t] and guide.getKeyName(k) == key then + callback { + source = call, + uri = self.uri, + mode = 'set', + } + end + elseif name == 'rawget' then + local t, k, v = self:callArgOf(call) + if used[t] and guide.getKeyName(k) == key then + callback { + source = call, + uri = self.uri, + mode = 'get', + } + self:eachField(v, key, callback) + end + elseif name == 'setmetatable' and not found then + -- 如果已经找到值,则不检查meta表 + local t, mt = self:callArgOf(call) + if mt then + self:eachField(mt, 's|__index', function (info) + checkIndex(info, key, t, used, call, callback) + end) + end + end + end) +end |