summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachRef.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-28 21:09:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-28 21:09:15 +0800
commitf64a39d8f0f22812bc47817a164525a1ade08ff4 (patch)
tree21838b76b3bff670ac43f71aefaa932e97afee6f /server-beta/src/searcher/eachRef.lua
parent5b45dfffe0a6b124873dbf278bce7987fabc36aa (diff)
downloadlua-language-server-f64a39d8f0f22812bc47817a164525a1ade08ff4.zip
整理代码
Diffstat (limited to 'server-beta/src/searcher/eachRef.lua')
-rw-r--r--server-beta/src/searcher/eachRef.lua118
1 files changed, 20 insertions, 98 deletions
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 52dcbc42..7ecfa35a 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -108,107 +108,20 @@ local function ofLocal(searcher, loc, callback)
end
end
-local function checkSpecialField(key, info, callback)
- local source = info.source
- if source.type == 'call' then
- local func = source.node
- local args = source.args
- local name = info.searcher:getSpecialName(func)
- if name == 'rawset' then
- if key == guide.getKeyName(args[2]) then
- return 'set', args[3]
- end
- elseif name == 'rawget' then
- if key == guide.getKeyName(args[2]) then
- return 'get'
- end
- end
- end
-end
-
-local function checkCommonField(key, info, callback)
- local src = info.source
- local srcKey = guide.getKeyName(src)
- if key ~= srcKey then
- return
- end
-
- local stype = src.type
- if stype == 'setglobal' then
- return 'set', src.value
- elseif stype == 'getglobal' then
- return 'get'
- elseif stype == 'setfield' then
- return 'set', src.value
- elseif stype == 'getfield' then
- return 'get'
- elseif stype == 'setmethod' then
- return 'set', src.value
- elseif stype == 'getmethod' then
- return 'get'
- elseif stype == 'setindex' then
- return 'set', src.value
- elseif stype == 'getindex' then
- return 'get'
- elseif stype == 'field' then
- local parent = src.parent
- if parent.type == 'setfield' then
- return 'set', parent.value
- elseif parent.type == 'getfield' then
- return 'get'
- elseif parent.type == 'tablefield' then
- return 'set', parent.value
- end
- elseif stype == 'index' then
- local parent = src.parent
- if parent.type == 'setindex' then
- return 'set', parent.value
- elseif parent.type == 'getindex' then
- return 'get'
- elseif parent.type == 'tableindex' then
- return 'set', parent.value
- end
- elseif stype == 'method' then
- local parent = src.parent
- if parent.type == 'setmethod' then
- return 'set', parent.value
- elseif parent.type == 'getmethod' then
- return 'get'
- end
- elseif stype == 'number'
- or stype == 'string'
- or stype == 'boolean' then
- local parent = src.parent
- if parent.type == 'setindex' then
- return 'set', parent.value
- elseif parent.type == 'getindex' then
- return 'get'
- end
- end
-end
-
-local function checkField(key, info, callback)
- local mode, value = checkCommonField(key, info, callback)
- if not mode then
- mode, value = checkSpecialField(key, info, callback)
- end
- if mode then
- callback {
- searcher = info.searcher,
- source = info.source,
- mode = mode,
- }
- end
- if value then
- ofValue(info.searcher, value, callback)
- end
-end
-
local function ofGlobal(searcher, source, callback)
local node = source.node
local key = guide.getKeyName(source)
searcher:eachField(node, function (info)
- checkField(key, info, callback)
+ if key == info.key then
+ callback {
+ searcher = info.searcher,
+ source = info.source,
+ mode = info.mode,
+ }
+ if info.value then
+ ofValue(info.searcher, info.value, callback)
+ end
+ end
end)
end
@@ -217,7 +130,16 @@ local function ofField(searcher, source, callback)
local node = parent.node
local key = guide.getKeyName(source)
searcher:eachField(node, function (info)
- checkField(key, info, callback)
+ if key == info.key then
+ callback {
+ searcher = info.searcher,
+ source = info.source,
+ mode = info.mode,
+ }
+ if info.value then
+ ofValue(info.searcher, info.value, callback)
+ end
+ end
end)
end