diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-11 16:36:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-11 16:36:53 +0800 |
commit | 7426f1c8b300afc0ac5f14686c6244f37b1b010c (patch) | |
tree | 679250fd79e6a34ff82ed237c9772955104aca64 | |
parent | a8b970238486c28868d3199cd8bba2d07a421817 (diff) | |
download | lua-language-server-7426f1c8b300afc0ac5f14686c6244f37b1b010c.zip |
预处理特殊API
-rw-r--r-- | server-beta/src/core/engineer.lua | 79 | ||||
-rw-r--r-- | server-beta/src/core/getglobal.lua | 4 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 2 |
3 files changed, 48 insertions, 37 deletions
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index f11d6a9d..036095dc 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -34,32 +34,41 @@ local specials = { } function mt:getSpecialName(source) - if source.type == 'getglobal' then - local node = source.node - if node.tag ~= '_ENV' then - return nil - end - local name = guide.getKeyName(source) - if name:sub(1, 2) ~= 's|' then - return nil - end - local spName = name:sub(3) - if not specials[spName] then - return nil - end - return spName - elseif source.type == 'local' then - if source.tag == '_ENV' then - return '_G' + local spName = self.cache.specialName[source] + if spName ~= nil then + if spName then + return spName end return nil - elseif source.type == 'getlocal' then - local loc = source.loc - if loc.tag == '_ENV' then - return '_G' + end + local function getName(src) + if src.type == 'getglobal' then + local node = src.node + if node.tag ~= '_ENV' then + return nil + end + local name = guide.getKeyName(src) + if name:sub(1, 2) ~= 's|' then + return nil + end + spName = name:sub(3) + if not specials[spName] then + spName = nil + end + elseif src.type == 'local' then + if src.tag == '_ENV' then + spName = '_G' + end + elseif src.type == 'getlocal' then + local loc = src.loc + if loc.tag == '_ENV' then + spName = '_G' + end end end - return nil + self:eachValue(source, getName) + self.cache.specialName[source] = spName or false + return spName end function mt:eachSpecial(callback) @@ -70,23 +79,20 @@ function mt:eachSpecial(callback) end return end - local env = guide.getENV(self.ast) - if not env then - return - end - local refs = env.ref - if not refs then - return - end cache = {} self.cache.special = cache - for i = 1, #refs do - local ref = refs[i] - local name = self:getSpecialName(ref) - if name then - cache[#cache+1] = {name, ref} + guide.eachSource(self.ast, function (source) + if source.type == 'getlocal' + or source.type == 'getglobal' + or source.type == 'local' + or source.type == 'field' + or source.type == 'string' then + local name = self:getSpecialName(source) + if name then + cache[#cache+1] = { name, source } + end end - end + end) for i = 1, #cache do callback(cache[i][1], cache[i][2]) end @@ -312,6 +318,7 @@ return function (ast) ref = {}, field = {}, value = {}, + specialName = {}, }, }, mt) return self diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua index 8bf45d39..d7f56146 100644 --- a/server-beta/src/core/getglobal.lua +++ b/server-beta/src/core/getglobal.lua @@ -84,4 +84,8 @@ function m:field(source, key, callback) end) end +function m:value(source, callback) + callback(source) +end + return m diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 9530f9ce..e2138fc9 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -259,7 +259,7 @@ function m.eachSourceContain(ast, offset, callback) end end ---- 遍历所有包含offset的source +--- 遍历所有的source function m.eachSource(ast, callback) local map = m.childMap local list = { ast } |