summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-29 10:54:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-29 10:54:21 +0800
commit55f143578193ac434b18d77bbbdacc468ff340c7 (patch)
tree37d849a2d93f1382d862103a63a34cb2bf25e8a6 /server/src
parent7d2e059198799acd874e8399bcb25920414e28da (diff)
downloadlua-language-server-55f143578193ac434b18d77bbbdacc468ff340c7.zip
大纲支持局部变量
Diffstat (limited to 'server/src')
-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
3 files changed, 34 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)