diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-28 21:09:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-28 21:09:15 +0800 |
commit | f64a39d8f0f22812bc47817a164525a1ade08ff4 (patch) | |
tree | 21838b76b3bff670ac43f71aefaa932e97afee6f /server-beta/src | |
parent | 5b45dfffe0a6b124873dbf278bce7987fabc36aa (diff) | |
download | lua-language-server-f64a39d8f0f22812bc47817a164525a1ade08ff4.zip |
整理代码
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/searcher/eachField.lua | 67 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 118 |
2 files changed, 68 insertions, 117 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua index 8fea864e..98f7fd69 100644 --- a/server-beta/src/searcher/eachField.lua +++ b/server-beta/src/searcher/eachField.lua @@ -1,19 +1,15 @@ +local guide = require 'parser.guide' + local function ofTabel(searcher, value, callback) for _, field in ipairs(value) do - if field.type == 'tablefield' then - callback { - searcher = searcher, - source = field.field, - } - elseif field.type == 'tableindex' then - callback { - searcher = searcher, - source = field.index, - } - else + if field.type == 'tablefield' + or field.type == 'tableindex' then callback { searcher = searcher, source = field, + key = guide.getKeyName(field), + value = field.value, + mode = 'set', } end end @@ -27,14 +23,25 @@ local function ofENV(searcher, source, callback) or parent.type == 'getindex' then callback { searcher = searcher, - source = parent, + source = parent, + key = guide.getKeyName(parent), + mode = 'get', } end - elseif source.type == 'getglobal' - or source.type == 'setglobal' then + elseif source.type == 'getglobal' then callback { searcher = searcher, - source = source, + source = source, + key = guide.getKeyName(source), + mode = 'get', + } + elseif source.type == 'setglobal' then + callback { + searcher = searcher, + source = source, + key = guide.getKeyName(source), + mode = 'set', + value = source.value, } end end @@ -46,13 +53,24 @@ local function ofVar(searcher, source, callback) end if parent.type == 'getfield' or parent.type == 'getmethod' - or parent.type == 'getindex' - or parent.type == 'setfield' + or parent.type == 'getindex' then + callback { + searcher = searcher, + source = parent, + key = guide.getKeyName(parent), + mode = 'get', + } + return + end + if parent.type == 'setfield' or parent.type == 'setmethod' or parent.type == 'setindex' then callback { searcher = searcher, source = parent, + key = guide.getKeyName(parent), + value = parent.value, + mode = 'set', } return end @@ -60,12 +78,23 @@ local function ofVar(searcher, source, callback) local call = parent.parent local func = call.node local name = searcher:getSpecialName(func) - if name == 'rawset' - or name == 'rawget' then + 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 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 |