summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 18:32:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 18:32:52 +0800
commit4e63ce41147f68b25282c375b2c067c2663e9aaa (patch)
tree61d434440e2dc5e373355a4c979ae44a5959a686 /server/src
parent08ab0f45adb64f314b55f38ae69b7fee97e30e36 (diff)
downloadlua-language-server-4e63ce41147f68b25282c375b2c067c2663e9aaa.zip
暂时先这样实现吧
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/document_symbol.lua19
-rw-r--r--server/src/core/env.lua19
-rw-r--r--server/src/core/vm.lua3
3 files changed, 35 insertions, 6 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 8e6fd01c..3902f8a3 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -30,7 +30,7 @@ local SymbolKind = {
TypeParameter = 26,
}
-local function buildFunc(vm, func)
+local function buildFunction(vm, func)
local source = func.source
local declarat = func.declarat
local name
@@ -75,10 +75,23 @@ local function buildFunc(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
+ end
+ return symbol
+end
+
return function (vm)
local symbols = {}
- for _, func in ipairs(vm.results.funcs) do
- symbols[#symbols+1] = buildFunc(vm, func)
+
+ for i, chunk in vm.chunk:childs() do
+ symbols[i] = buildChunk(vm, chunk)
end
return symbols
diff --git a/server/src/core/env.lua b/server/src/core/env.lua
index ada26145..bee90012 100644
--- a/server/src/core/env.lua
+++ b/server/src/core/env.lua
@@ -16,7 +16,13 @@ return function (root)
local mt = { _env = env }
function mt:push()
- env[#env+1] = { _next = env[#env], _cut = {} }
+ 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
end
function mt:pop()
env[#env] = nil
@@ -24,6 +30,15 @@ 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
@@ -99,7 +114,7 @@ return function (root)
cuted[key] = true
end
for key, value in pairs(o) do
- if key == '_cut' or key == '_next' then
+ if key == '_cut' or key == '_next' or key == '_child' then
goto CONTINUE
end
if cuted[key] then
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index fc00b581..f60fcb57 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -401,6 +401,7 @@ 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))
@@ -1435,6 +1436,7 @@ 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')
@@ -1464,7 +1466,6 @@ local function compile(ast, lsp, uri)
},
chunk = env {
labels = {},
- locals = {},
},
results = {
locals = {},