summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/document_symbol.lua36
-rw-r--r--server/src/core/hover.lua4
-rw-r--r--server/src/method/textDocument/documentSymbol.lua3
-rw-r--r--server/test/document_symbol/init.lua57
4 files changed, 91 insertions, 9 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 72121f09..61d58772 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -1,5 +1,6 @@
local hoverFunction = require 'core.hover_function'
local hoverName = require 'core.hover_name'
+local hover = require 'core.hover'
local SymbolKind = {
File = 1,
@@ -47,8 +48,8 @@ local function buildFunction(vm, func)
else
name = ''
end
- local hover = hoverFunction(name, func, declarat and declarat.object)
- if not hover then
+ local hvr = hoverFunction(name, func, declarat and declarat.object)
+ if not hvr then
return
end
local selectionRange
@@ -68,13 +69,31 @@ local function buildFunction(vm, func)
return {
name = name,
-- 前端不支持多行
- detail = hover.label:gsub('[\r\n]', ''),
+ detail = hvr.label:gsub('[\r\n]', ''),
kind = kind,
range = range,
selectionRange = selectionRange,
}
end
+local function buildLocal(vm, loc)
+ if loc.source.start == 0 then
+ return nil
+ end
+ if loc.value and loc.value.type == 'function' then
+ return nil
+ end
+ local range = { loc.source.start, loc.source.finish }
+ local hvr = hover(loc, loc.source)
+ return {
+ name = loc.key,
+ detail = hvr.label,
+ kind = SymbolKind.Variable,
+ range = range,
+ selectionRange = range,
+ }
+end
+
local function packChild(symbols, finish)
local t
while true do
@@ -107,11 +126,14 @@ end
return function (vm)
local symbols = {}
- for i, func in ipairs(vm.results.funcs) do
- symbols[i] = buildFunction(vm, func)
+ for _, func in ipairs(vm.results.funcs) do
+ symbols[#symbols+1] = buildFunction(vm, func)
+ end
+ for _, loc in ipairs(vm.results.locals) do
+ symbols[#symbols+1] = buildLocal(vm, loc)
end
- symbols = packSymbols(symbols)
+ local packedSymbols = packSymbols(symbols)
- return symbols
+ return packedSymbols
end
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index ea22f1be..d0886e7c 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -263,7 +263,7 @@ local function unpackTable(result)
return table.concat(lines, '\r\n')
end
-local function getValueHover(name, valueType, result, source, lib)
+local function getValueHover(name, valueType, result, lib)
if not lib then
local class = findClass(result)
if class then
@@ -355,7 +355,7 @@ return function (result, source, lsp, select)
hover = getFunctionHover(name, result.value, source.object, select)
end
else
- hover = getValueHover(name, valueType, result, source, lib)
+ hover = getValueHover(name, valueType, result, lib)
end
if not hover then
return
diff --git a/server/src/method/textDocument/documentSymbol.lua b/server/src/method/textDocument/documentSymbol.lua
index 7484bb97..2f9a6b8a 100644
--- a/server/src/method/textDocument/documentSymbol.lua
+++ b/server/src/method/textDocument/documentSymbol.lua
@@ -38,6 +38,9 @@ return function (lsp, params)
end
local symbols = core.documentSymbol(vm)
+ if not symbols then
+ return nil
+ end
for _, symbol in ipairs(symbols) do
convertRange(lines, symbol)
diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua
index eac54f8a..52896461 100644
--- a/server/test/document_symbol/init.lua
+++ b/server/test/document_symbol/init.lua
@@ -151,6 +151,15 @@ end
kind = SymbolKind.Field,
range = {1, 21},
selectionRange = {13, 15},
+ children = {
+ [1] = {
+ name = 'self',
+ detail = EXISTS,
+ kind = SymbolKind.Variable,
+ range = {10, 11},
+ selectionRange = {10, 11},
+ }
+ }
}
}
@@ -196,3 +205,51 @@ end
selectionRange = {79, 79},
},
}
+
+TEST [[
+local x = 1
+local function f()
+ local x = 'x'
+ local y = {}
+end
+local y = true
+]]
+{
+ [1] = {
+ name = 'x',
+ detail = 'local x: number = 1',
+ kind = SymbolKind.Variable,
+ range = {7, 7},
+ selectionRange = {7, 7},
+ },
+ [2] = {
+ name = 'f',
+ detail = 'function f()',
+ kind = SymbolKind.Function,
+ range = {13, 69},
+ selectionRange = {28, 28},
+ children = {
+ [1] = {
+ name = 'x',
+ detail = 'local x: string = "x"',
+ kind = SymbolKind.Variable,
+ range = {42, 42},
+ selectionRange = {42, 42},
+ },
+ [2] = {
+ name = 'y',
+ detail = 'local y: {}',
+ kind = SymbolKind.Variable,
+ range = {60, 60},
+ selectionRange = {60, 60},
+ },
+ },
+ },
+ [3] = {
+ name = 'y',
+ detail = 'local y: boolean = true',
+ kind = SymbolKind.Variable,
+ range = {77, 77},
+ selectionRange = {77, 77},
+ },
+}