diff options
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/core/definition.lua | 2 | ||||
-rw-r--r-- | server-beta/src/core/engineer.lua | 24 | ||||
-rw-r--r-- | server-beta/src/parser/compile.lua | 1 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 42 |
4 files changed, 47 insertions, 22 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua index bd8124d2..087ef948 100644 --- a/server-beta/src/core/definition.lua +++ b/server-beta/src/core/definition.lua @@ -3,7 +3,7 @@ local engineer = require 'core.engineer' return function (ast, text, offset) local results = {} - guide.eachSource(ast.ast, offset, function (source) + guide.eachSourceContain(ast.ast, offset, function (source) local searcher = engineer(ast) searcher:eachRef(source, 'def', function (src, mode) results[#results+1] = { diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 3f4f1705..c5ed636c 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -35,6 +35,8 @@ mt['_G'] = function (self, source, mode, callback) callback(parent, 'set') 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 @@ -56,14 +58,28 @@ mt['getglobal'] = function (self, source, mode, callback) end mt['setglobal'] = mt['getglobal'] mt['special'] = function (self, source, mode, callback) + local name = self:getSpecial(source) + if not name then + return + end if mode == 'def' then - local name = guide.getKeyName(source) if name == '_G' then self:search(source, '_G', mode, callback) + elseif name == 'rawset' then + callback(source.parent, 'set') end end end +function mt:getSpecial(source) + local node = source.node + if node.tag ~= '_ENV' then + return nil + end + local name = guide.getKeyName(source) + return name +end + function mt:search(source, method, mode, callback) local f = mt[method] if not f then @@ -78,12 +94,12 @@ function mt:eachRef(source, mode, callback) end return function (ast) - if not ast.vm then - ast.vm = {} - end local self = setmetatable({ step = 0, ast = ast.ast, }, mt) + if not ast.vm then + ast.vm = {} + end return self end diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua index 95829130..ead4b882 100644 --- a/server-beta/src/parser/compile.lua +++ b/server-beta/src/parser/compile.lua @@ -296,6 +296,7 @@ local vmMap = { start = 0, finish = 0, effect = 0, + tag = '_ENV', [1] = '_ENV', }, obj) end diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 49b43f92..91fc6d5d 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -226,7 +226,7 @@ function m.isInRange(source, offset) end --- 遍历所有包含offset的source -function m.eachSource(ast, offset, callback) +function m.eachSourceContain(ast, offset, callback) local map = m.childMap local list = { ast } while true do @@ -257,24 +257,32 @@ function m.eachSource(ast, offset, callback) end end ---- 遍历所有某种类型的source -function m.eachSourceOf(types, callback) - if type(types) == 'string' then - types = {[types] = callback} - elseif type(types) == 'table' then - for i = 1, #types do - types[types[i]] = callback +--- 遍历所有包含offset的source +function m.eachSource(ast, callback) + local map = m.childMap + local list = { ast } + while true do + local len = #list + if len == 0 then + return + end + local obj = list[len] + list[len] = nil + callback(obj) + local keys = map[obj.type] + if keys then + for i = 1, #keys do + local key = keys[i] + if key == '#' then + for i = 1, #obj do + list[#list+1] = obj[i] + end + else + list[#list+1] = obj[key] + end + end end - else - return end - --for i = 1, #root do - -- local source = root[i] - -- local f = types[source.type] - -- if f then - -- f(source) - -- end - --end end --- 获取偏移对应的坐标(row从0开始,col为光标位置) |