diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-30 17:46:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-30 17:46:25 +0800 |
commit | a5aa84118fa196bc75d7dc2159b29a3ce63d9816 (patch) | |
tree | fa7ac58f284e79ff00bd9c119cbf3f3b8d80d81d | |
parent | 4e01c062182d333ea7d7007c2f44d036993d9c0f (diff) | |
download | lua-language-server-a5aa84118fa196bc75d7dc2159b29a3ce63d9816.zip |
暂存
-rw-r--r-- | server-beta/src/core/engineer.lua | 80 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 1 |
2 files changed, 81 insertions, 0 deletions
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 6baa0d20..dae501b1 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -29,6 +29,37 @@ mt['local'] = function (self, source, mode, callback) local node = method.node self:search(node, node.type, mode, callback) end + elseif mode == 'ref' then + if source.tag ~= 'self' then + callback(source, 'local') + end + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' then + callback(ref, 'set') + elseif ref.type == 'getlocal' then + callback(ref, 'get') + end + end + end + if source.tag == 'self' then + local method = source.method + local node = method.node + self:search(node, node.type, mode, callback) + end + elseif mode == 'field' then + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'getlocal' then + local parent = ref.parent + if parent.type == 'setfield' then + callback(parent) + elseif parent.type == 'getfield' then + callback(parent) + end + end + end + end end end mt['getlocal'] = function (self, source, mode, callback) @@ -45,6 +76,17 @@ mt['_G'] = function (self, source, mode, callback) elseif parent.type == 'callargs' then self:search(parent.parent, 'special', mode, callback) end + elseif mode == 'ref' then + local parent = source.parent + if parent.type == 'setfield' then + callback(parent, 'set') + elseif parent.type == 'getfield' then + callback(parent, 'get') + elseif parent.type == 'getfield' then + self:search(parent, 'special', mode, callback) + elseif parent.type == 'callargs' then + self:search(parent.parent, 'special', mode, callback) + end end end mt['getglobal'] = function (self, source, mode, callback) @@ -61,9 +103,47 @@ mt['getglobal'] = function (self, source, mode, callback) end end end + elseif mode == 'ref' then + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + callback(ref, 'get') + elseif ref.type == 'getglobal' then + self:search(ref, 'special', mode, callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', mode, callback) + end + end + end + elseif mode == 'field' then + self:search(source, 'getglobal', 'ref', function (src) + local parent = src.parent + if parent.type == 'setfield' then + callback(parent) + elseif parent.type == 'getfield' then + callback(parent) + end + end) end end mt['setglobal'] = mt['getglobal'] +mt['field'] = function (self, source, mode, callback) + local node = source.node + local key = guide.getKeyName(source) + self:eachRef(node, 'field', function (src) + if key == guide.getKeyName(src) then + if mode == 'def' then + if src.type == 'setfield' then + callback(src.field, 'set') + end + end + end + end) +end +mt['getfield'] = mt['field'] +mt['setfield'] = mt['field'] mt['special'] = function (self, source, mode, callback) local name = self:getSpecial(source) if not name then diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 91fc6d5d..4ef433dd 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -37,6 +37,7 @@ m.childMap = { ['elseifblock'] = {'filter', '#'}, ['elseblock'] = {'#'}, ['setfield'] = {'node', 'value'}, + ['setglobal'] = {'value'}, ['local'] = {'attrs', 'value'}, ['setlocal'] = {'value'}, ['return'] = {'#'}, |