summaryrefslogtreecommitdiff
path: root/server/src/method
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 15:04:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 15:04:54 +0800
commit4574e0c6033bf8358989a5f14f8861c3627026f7 (patch)
tree34cfbf854b0912744cc493364df31f70f0840851 /server/src/method
parent71ed1ec92e69eb23c51f43ddf3f4940bc9a5a91a (diff)
downloadlua-language-server-4574e0c6033bf8358989a5f14f8861c3627026f7.zip
整理代码
Diffstat (limited to 'server/src/method')
-rw-r--r--server/src/method/textDocument/documentSymbol.lua66
1 files changed, 12 insertions, 54 deletions
diff --git a/server/src/method/textDocument/documentSymbol.lua b/server/src/method/textDocument/documentSymbol.lua
index 1d301881..49006f3b 100644
--- a/server/src/method/textDocument/documentSymbol.lua
+++ b/server/src/method/textDocument/documentSymbol.lua
@@ -1,34 +1,5 @@
local matcher = require 'matcher'
-local SymbolKind = {
- File = 1,
- Module = 2,
- Namespace = 3,
- Package = 4,
- Class = 5,
- Method = 6,
- Property = 7,
- Field = 8,
- Constructor = 9,
- Enum = 10,
- Interface = 11,
- Function = 12,
- Variable = 13,
- Constant = 14,
- String = 15,
- Number = 16,
- Boolean = 17,
- Array = 18,
- Object = 19,
- Key = 20,
- Null = 21,
- EnumMember = 22,
- Struct = 23,
- Event = 24,
- Operator = 25,
- TypeParameter = 26,
-}
-
local function posToRange(lines, start, finish)
local start_row, start_col = lines:rowcol(start)
local finish_row, finish_col = lines:rowcol(finish)
@@ -44,15 +15,15 @@ local function posToRange(lines, start, finish)
}
end
-local function buildFunc(lines, func, nextFunction)
- local source = func.source
- return {
- name = 'name',
- detail = 'hover',
- kind = SymbolKind.Function,
- range = posToRange(lines, source.start, source.finish),
- selectionRange = posToRange(lines, source.start, source.start)
- }
+local function convertRange(lines, symbol)
+ symbol.range = posToRange(lines, symbol.range[1], symbol.range[2])
+ symbol.selectionRange = posToRange(lines, symbol.selectionRange[1], symbol.selectionRange[2])
+
+ if symbol.children then
+ for _, child in ipairs(symbol.children) do
+ convertRange(lines, child)
+ end
+ end
end
return function (lsp, params)
@@ -62,24 +33,11 @@ return function (lsp, params)
return nil
end
- local i = 0
- local function nextFunction()
- i = i + 1
- local func = vm.results.funcs[i]
- return func
- end
+ local symbols = matcher.documentSymbol(vm)
- local symbols = {}
- while true do
- local func = nextFunction()
- if not func then
- break
- end
- symbols[1] = buildFunc(lines, func, nextFunction)
- do break end
+ for _, symbol in ipairs(symbols) do
+ convertRange(lines, symbol)
end
- log.debug(table.dump(symbols))
-
return symbols
end