diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-25 16:43:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-25 16:43:48 +0800 |
commit | 64aab1cc575552ce2ed494790d201d3e6f170065 (patch) | |
tree | 402c070348e347cd65b5601635c1d2bb9899cd4f /script-beta/vm/eachDef.lua | |
parent | 429364668ee08a6b28ba066dbcdef4125829c892 (diff) | |
download | lua-language-server-64aab1cc575552ce2ed494790d201d3e6f170065.zip |
支持 metatable
Diffstat (limited to 'script-beta/vm/eachDef.lua')
-rw-r--r-- | script-beta/vm/eachDef.lua | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 6d389d18..61da11d9 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -66,22 +66,52 @@ local function ofTableField(source, callback) callback(source) end +local function checkMetaRecv(source, callback) + if not source or source.type ~= 'select' then + return + end + if source.index ~= 1 then + return + end + local call = source.vararg + if not call or call.type ~= 'call' then + return + end + local special = vm.getSpecial(call.node) + if special ~= 'setmetatable' then + return + end + vm.eachFieldInTable(call.args[1]) + local mt = call.args[2] + if mt then + vm.eachField(mt, function (src) + if vm.getKeyName(src) == 's|__index' then + if src.value then + vm.eachField(src.value, callback) + end + end + end) + end +end + local function ofField(source, callback) local parent = source.parent local key = vm.getKeyName(source) + local function checkKey(src) + if vm.isSet(src) + and key == vm.getKeyName(src) then + callback(src) + end + end if parent.type == 'tablefield' or parent.type == 'tableindex' then - ofTableField(parent, callback) + ofTableField(parent, checkKey) else local node = parent.node - vm.eachField(node, function (src) - if vm.isSet(src) - and key == vm.getKeyName(src) then - callback(src) - end - end) + vm.eachField(node, checkKey) vm.eachDef(node, function (src) - vm.eachFieldInTable(src.value, callback) + vm.eachFieldInTable(src.value, checkKey) + checkMetaRecv(src.value, checkKey) end) end end |