diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-15 16:03:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-15 16:03:05 +0800 |
commit | 0177c2914c223fb6b335bfdccac1f146c2f80a60 (patch) | |
tree | b300422746c7742de358fb0e9aed05dd6bd6e2af /script-beta/parser | |
parent | 7970d6ca48f3509c7cfe29a8b81ae7777d6f2556 (diff) | |
download | lua-language-server-0177c2914c223fb6b335bfdccac1f146c2f80a60.zip |
支持 return setmetatable
Diffstat (limited to 'script-beta/parser')
-rw-r--r-- | script-beta/parser/guide.lua | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 947d21c6..44e97a66 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -947,7 +947,7 @@ end --- 根据函数调用的返回值,获取:调用的函数,参数列表,自己是第几个返回值 function m.getCallValue(source) - local value = m.getObjectValue(source) + local value = m.getObjectValue(source) or source if not value then return end @@ -1070,19 +1070,15 @@ function m.checkSameSimpleInValueInMetaTable(status, mt, start, queue) end end -function m.checkSameSimpleInValueOfSetMetaTable(status, value, start, queue) - if value.type ~= 'select' then - return - end - local vararg = value.vararg - if not vararg or vararg.type ~= 'call' then +function m.checkSameSimpleInValueOfCallMetaTable(status, call, start, queue) + if not call or call.type ~= 'call' then return end - local func = vararg.node + local func = call.node if not func or func.special ~= 'setmetatable' then return end - local args = vararg.args + local args = call.args local obj = args[1] local mt = args[2] if obj then @@ -1097,6 +1093,14 @@ function m.checkSameSimpleInValueOfSetMetaTable(status, value, start, queue) end end +function m.checkSameSimpleInValueOfSetMetaTable(status, value, start, queue) + if value.type ~= 'select' then + return + end + local call = value.vararg + m.checkSameSimpleInValueOfCallMetaTable(status, call, start, queue) +end + function m.checkSameSimpleInArg1OfSetMetaTable(status, obj, start, queue) local args = obj.parent if not args or args.type ~= 'callargs' then @@ -1121,6 +1125,11 @@ function m.checkSameSimpleInBranch(status, ref, start, queue) m.checkSameSimpleInValueOfSetMetaTable(status, value, start, queue) end + if ref.type == 'call' then + -- 检查赋值是 setmetatable 调用的情况 + m.checkSameSimpleInValueOfCallMetaTable(status, ref, start, queue) + end + -- 检查自己是字面量表的情况 m.checkSameSimpleInValueOfTable(status, ref, start, queue) -- 检查自己作为 setmetatable 第一个参数的情况 |