summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/core/document_symbol.lua41
-rw-r--r--server/src/core/env.lua19
-rw-r--r--server/src/core/vm.lua3
3 files changed, 32 insertions, 31 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 75035e92..72121f09 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -75,24 +75,43 @@ local function buildFunction(vm, func)
}
end
-local function buildChunk(vm, chunk)
- local symbol = buildFunction(vm, chunk.func)
- local childs = {}
- for i, child in vm.chunk:childs(chunk) do
- childs[i] = buildChunk(vm, child)
- end
- if #childs ~= 0 then
- symbol.children = childs
+local function packChild(symbols, finish)
+ local t
+ while true do
+ local symbol = symbols[#symbols]
+ if not symbol then
+ break
+ end
+ if symbol.range[1] > finish then
+ break
+ end
+ symbols[#symbols] = nil
+ symbol.children = packChild(symbols, symbol.range[2])
+ if not t then
+ t = {}
+ end
+ t[#t+1] = symbol
end
- return symbol
+ return t
+end
+
+local function packSymbols(symbols)
+ -- 按照start位置反向排序
+ table.sort(symbols, function (a, b)
+ return a.range[1] > b.range[1]
+ end)
+ -- 处理嵌套
+ return packChild(symbols, math.maxinteger)
end
return function (vm)
local symbols = {}
- for i, chunk in vm.chunk:childs() do
- symbols[i] = buildChunk(vm, chunk)
+ for i, func in ipairs(vm.results.funcs) do
+ symbols[i] = buildFunction(vm, func)
end
+ symbols = packSymbols(symbols)
+
return symbols
end
diff --git a/server/src/core/env.lua b/server/src/core/env.lua
index bee90012..ada26145 100644
--- a/server/src/core/env.lua
+++ b/server/src/core/env.lua
@@ -16,13 +16,7 @@ return function (root)
local mt = { _env = env }
function mt:push()
- local current = env[#env]
- if not current._child then
- current._child = {}
- end
- local new = { _next = env[#env], _cut = {} }
- current._child[#current._child+1] = new
- env[#env+1] = new
+ env[#env+1] = { _next = env[#env], _cut = {} }
end
function mt:pop()
env[#env] = nil
@@ -30,15 +24,6 @@ return function (root)
function mt:cut(key)
env[#env]._cut[key] = true
end
- function mt:childs(obj)
- if not obj then
- obj = env[#env]
- end
- if not obj._child then
- return function () end
- end
- return ipairs(obj._child)
- end
function mt:__index(key)
local origin = env[#env]
if is_table[key] then
@@ -114,7 +99,7 @@ return function (root)
cuted[key] = true
end
for key, value in pairs(o) do
- if key == '_cut' or key == '_next' or key == '_child' then
+ if key == '_cut' or key == '_next' then
goto CONTINUE
end
if cuted[key] then
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index f60fcb57..5ccada8e 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -119,7 +119,6 @@ function mt:createLocal(key, source, value)
self.scope.locals[key] = loc
self.results.locals[#self.results.locals+1] = loc
- self.chunk.locals[#self.chunk.locals+1] = loc
self:addInfo(loc, 'local', source)
self:setValue(loc, value, source)
@@ -401,7 +400,6 @@ function mt:buildFunction(exp, object)
self.chunk:cut 'dots'
self.chunk:cut 'labels'
self.chunk.func = func
- self.chunk.locals = {}
if object then
local var = self:createArg('self', object.source, self:getValue(object))
@@ -1436,7 +1434,6 @@ function mt:createEnvironment()
self.scope.block = { start = 0, finish = math.maxinteger }
-- 整个文件是一个函数
self.chunk.func = self:buildFunction()
- self.chunk.locals = {}
self.results.main = self.chunk.func
-- 隐藏的上值`_ENV`
local parent = self:createLocal('_ENV')