diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-25 17:39:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-25 17:39:30 +0800 |
commit | 33fd161778557ab8f3a511b544d5416b6b8285bd (patch) | |
tree | 2641bf27c7bcff918d809456e2dfe17f15df32c9 /server-beta/src | |
parent | 2f3d7120596d8f814c999f800e9c4c5e4e2664b3 (diff) | |
download | lua-language-server-33fd161778557ab8f3a511b544d5416b6b8285bd.zip |
更新
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/searcher/eachField.lua | 101 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 24 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 12 |
3 files changed, 97 insertions, 40 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua index 320fd9f2..6a86314b 100644 --- a/server-beta/src/searcher/eachField.lua +++ b/server-beta/src/searcher/eachField.lua @@ -1,30 +1,63 @@ -local function ofLocal(searcher, source, callback) - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'getlocal' then - local parent = ref.parent - local field = searcher:getField(parent) - if field then - callback { - searcher = searcher, - source = field, - } - end - elseif ref.type == 'getglobal' - or ref.type == 'setglobal' then - callback { - searcher = searcher, - source = ref, - } - end +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 + callback { + searcher = searcher, + source = field, + } end end end -local function ofGlobal(searcher, source, callback) +local function ofValue(searcher, value, callback) + if value.type == 'table' then + ofTabel(searcher, value, callback) + end +end + +local function rawField(searcher, source, callback) + if source.type == 'getlocal' then + local parent = source.parent + local field = searcher:getField(parent) + if field then + callback { + searcher = searcher, + source = field, + } + end + elseif source.type == 'getglobal' + or source.type == 'setglobal' then + callback { + searcher = searcher, + source = source, + } + end +end + +return function (searcher, source, callback) searcher:eachRef(source, function (info) local src = info.source - if src.type == 'getglobal' then + if src.tag == '_ENV' then + if src.ref then + for _, ref in ipairs(src.ref) do + rawField(info.searcher, ref, callback) + end + end + elseif src.type == 'local' then + if src.value then + ofValue(searcher, src.value, callback) + end + elseif src.type == 'getlocal' then if src.parent then local field = info.searcher:getField(src.parent) if field then @@ -34,18 +67,20 @@ local function ofGlobal(searcher, source, callback) } end end + elseif src.type == 'setlocal' then + ofValue(info.searcher, src.value, callback) + elseif src.type == 'getglobal' then + if src.parent then + local field = info.searcher:getField(src.parent) + if field then + callback { + searcher = info.searcher, + source = field, + } + end + end + elseif src.type == 'setglobal' then + ofValue(info.searcher, src.value, callback) end end) end - -return function (searcher, source, callback) - if source.type == 'local' then - ofLocal(searcher, source, callback) - elseif source.type == 'getlocal' - or source.type == 'setlocal' then - ofLocal(searcher, source.node, callback) - elseif source.type == 'getglobal' - or source.type == 'setglobal' then - ofGlobal(searcher, source, callback) - end -end diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua index 8230914e..81bfb8bf 100644 --- a/server-beta/src/searcher/eachRef.lua +++ b/server-beta/src/searcher/eachRef.lua @@ -45,12 +45,13 @@ local function checkField(key, info, callback) if key ~= guide.getKeyName(src) then return end + local stype = src.type local mode - if src.type == 'setglobal' then + if stype == 'setglobal' then mode = 'set' - elseif src.type == 'getglobal' then + elseif stype == 'getglobal' then mode = 'get' - elseif src.type == 'field' then + elseif stype == 'field' then local parent = src.parent if parent.type == 'setfield' then mode = 'set' @@ -59,16 +60,25 @@ local function checkField(key, info, callback) elseif parent.type == 'tablefield' then mode = 'set' end - elseif src.type == 'method' then + elseif stype == 'index' then + local parent = src.parent + if parent.type == 'setindex' then + mode = 'set' + elseif parent.type == 'getindex' then + mode = 'get' + elseif parent.type == 'tableindex' then + mode = 'set' + end + elseif stype == 'method' then local parent = src.parent if parent.type == 'setmethod' then mode = 'set' elseif parent.type == 'getmethod' then mode = 'get' end - elseif src.type == 'number' - or src.type == 'string' - or src.type == 'boolean' then + elseif stype == 'number' + or stype == 'string' + or stype == 'boolean' then local parent = src.parent if parent.type == 'setindex' then mode = 'set' diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index d575e65f..054067d7 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -69,7 +69,13 @@ function mt:eachRef(source, callback) end cache = {} self.cache.eachRef[source] = cache + local mark = {} eachRef(self, source, function (info) + local src = info.source + if mark[src] then + return + end + mark[src] = true cache[#cache+1] = info callback(info) end) @@ -90,7 +96,13 @@ function mt:eachField(source, callback) end cache = {} self.cache.eachField[source] = cache + local mark = {} eachField(self, source, function (info) + local src = info.source + if mark[src] then + return + end + mark[src] = true cache[#cache+1] = info callback(info) end) |