summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachField.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-29 15:05:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-29 15:05:01 +0800
commit5c7f8776c839bc6898953affb0d94ec99e435cd8 (patch)
treedb505ef9595d7ce8403a3a43ec8e4cc19c58f0d9 /server-beta/src/searcher/eachField.lua
parente362be47cd394fdb197840781e371867145990b0 (diff)
downloadlua-language-server-5c7f8776c839bc6898953affb0d94ec99e435cd8.zip
setmetatable 参数1 支持 __index
Diffstat (limited to 'server-beta/src/searcher/eachField.lua')
-rw-r--r--server-beta/src/searcher/eachField.lua59
1 files changed, 36 insertions, 23 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua
index 98f7fd69..3db2375f 100644
--- a/server-beta/src/searcher/eachField.lua
+++ b/server-beta/src/searcher/eachField.lua
@@ -46,6 +46,41 @@ local function ofENV(searcher, source, callback)
end
end
+local function ofSpecialArg(searcher, source, callback)
+ local args = source.parent
+ local call = args.parent
+ local func = call.node
+ local name = searcher:getSpecialName(func)
+ if name == 'rawset' then
+ if args[1] == source and args[2] then
+ callback {
+ searcher = searcher,
+ source = call,
+ key = guide.getKeyName(args[2]),
+ value = args[3],
+ mode = 'set',
+ }
+ end
+ elseif name == 'rawget' then
+ if args[1] == source and args[2] then
+ callback {
+ searcher = searcher,
+ source = call,
+ key = guide.getKeyName(args[2]),
+ mode = 'get',
+ }
+ end
+ elseif name == 'setmetatable' then
+ if args[1] == source and args[2] then
+ searcher:eachField(args[2], function (info)
+ if info.key == 's|__index' and info.value then
+ info.searcher:eachField(info.value, callback)
+ end
+ end)
+ end
+ end
+end
+
local function ofVar(searcher, source, callback)
local parent = source.parent
if not parent then
@@ -75,29 +110,7 @@ local function ofVar(searcher, source, callback)
return
end
if parent.type == 'callargs' then
- local call = parent.parent
- local func = call.node
- local name = searcher:getSpecialName(func)
- if name == 'rawset' then
- if parent[1] == source then
- callback {
- searcher = searcher,
- source = call,
- key = guide.getKeyName(parent[2]),
- value = parent[3],
- mode = 'set',
- }
- end
- elseif name == 'rawget' then
- if parent[1] == source then
- callback {
- searcher = searcher,
- source = call,
- key = guide.getKeyName(parent[2]),
- mode = 'get',
- }
- end
- end
+ ofSpecialArg(searcher, source, callback)
end
end