diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-28 20:56:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-28 20:56:57 +0800 |
commit | 5b45dfffe0a6b124873dbf278bce7987fabc36aa (patch) | |
tree | 77b1a00b64793034c581f02f597dccaa9b35ccca /server-beta | |
parent | 803febe4956557dba464c66625e6c67868fa0b18 (diff) | |
download | lua-language-server-5b45dfffe0a6b124873dbf278bce7987fabc36aa.zip |
支持 rawset
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/searcher/eachField.lua | 38 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 78 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 10 |
3 files changed, 82 insertions, 44 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua index 8b987cc2..8fea864e 100644 --- a/server-beta/src/searcher/eachField.lua +++ b/server-beta/src/searcher/eachField.lua @@ -41,17 +41,33 @@ end local function ofVar(searcher, source, callback) local parent = source.parent - if parent then - if parent.type == 'getfield' - or parent.type == 'getmethod' - or parent.type == 'getindex' - or parent.type == 'setfield' - or parent.type == 'setmethod' - or parent.type == 'setindex' then - callback { - searcher = searcher, - source = parent, - } + if not parent then + return + end + if parent.type == 'getfield' + or parent.type == 'getmethod' + or parent.type == 'getindex' + or parent.type == 'setfield' + or parent.type == 'setmethod' + or parent.type == 'setindex' then + callback { + searcher = searcher, + source = parent, + } + return + end + if parent.type == 'callargs' then + local call = parent.parent + local func = call.node + local name = searcher:getSpecialName(func) + if name == 'rawset' + or name == 'rawget' then + if parent[1] == source then + callback { + searcher = searcher, + source = call, + } + end end end end diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua index a08c0751..52dcbc42 100644 --- a/server-beta/src/searcher/eachRef.lua +++ b/server-beta/src/searcher/eachRef.lua @@ -108,76 +108,94 @@ local function ofLocal(searcher, loc, callback) end end -local function checkField(key, info, callback) +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 - if key ~= guide.getKeyName(src) then + local srcKey = guide.getKeyName(src) + if key ~= srcKey then return end + local stype = src.type - local mode - local value if stype == 'setglobal' then - mode = 'set' - value = src.value + return 'set', src.value elseif stype == 'getglobal' then - mode = 'get' + return 'get' elseif stype == 'setfield' then - mode = 'set' - value = src.value + return 'set', src.value elseif stype == 'getfield' then - mode = 'get' + return 'get' elseif stype == 'setmethod' then - mode = 'set' - value = src.value + return 'set', src.value elseif stype == 'getmethod' then - mode = 'get' + return 'get' elseif stype == 'setindex' then - mode = 'set' - value = src.value + return 'set', src.value elseif stype == 'getindex' then - mode = 'get' + return 'get' elseif stype == 'field' then local parent = src.parent if parent.type == 'setfield' then - mode = 'set' + return 'set', parent.value elseif parent.type == 'getfield' then - mode = 'get' + return 'get' elseif parent.type == 'tablefield' then - mode = 'set' + return 'set', parent.value end - value = parent.value elseif stype == 'index' then local parent = src.parent if parent.type == 'setindex' then - mode = 'set' + return 'set', parent.value elseif parent.type == 'getindex' then - mode = 'get' + return 'get' elseif parent.type == 'tableindex' then - mode = 'set' + return 'set', parent.value end - value = parent.value elseif stype == 'method' then local parent = src.parent if parent.type == 'setmethod' then - mode = 'set' + return 'set', parent.value elseif parent.type == 'getmethod' then - mode = 'get' + return 'get' end - value = parent.value elseif stype == 'number' or stype == 'string' or stype == 'boolean' then local parent = src.parent if parent.type == 'setindex' then - mode = 'set' + return 'set', parent.value elseif parent.type == 'getindex' then - mode = 'get' + 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 = src, + source = info.source, mode = mode, } end diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index 5360a1e2..66a15f54 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -97,8 +97,7 @@ function mt:getSpecialName(source) end return nil end - local function getName(info) - local src = info.source + local function getName(src) if src.type == 'getglobal' then local node = src.node if node.tag ~= '_ENV' then @@ -123,7 +122,12 @@ function mt:getSpecialName(source) end end end - self:eachRef(source, getName) + getName(source) + if not spName then + self:eachRef(source, function (info) + getName(info.source) + end) + end self.cache.specialName[source] = spName or false return spName end |