summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 14:33:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 14:33:23 +0800
commita78a31584d144a05f2fe35edc63f37c850a2e79f (patch)
tree1ed15fddb4ea4b656d454a221d78a8813199e908
parentd33546238551e3771fc7f0005e788f530cd7b58c (diff)
downloadlua-language-server-a78a31584d144a05f2fe35edc63f37c850a2e79f.zip
大纲测试
-rw-r--r--README.md2
-rw-r--r--server/src/method/init.lua1
-rw-r--r--server/src/method/initialize.lua2
-rw-r--r--server/src/method/textDocument/documentSymbol.lua85
4 files changed, 90 insertions, 0 deletions
diff --git a/README.md b/README.md
index cd02b855..5c5d66b1 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,8 @@
- [ ] Type Format
- [ ] Accurate Type Inference
- [ ] Document Symbols
+- [ ] Search Globals
+- [ ] Find All References
### Locale
diff --git a/server/src/method/init.lua b/server/src/method/init.lua
index ea7fa05a..1c272eb4 100644
--- a/server/src/method/init.lua
+++ b/server/src/method/init.lua
@@ -13,6 +13,7 @@ init 'textDocument/definition'
init 'textDocument/didOpen'
init 'textDocument/didChange'
init 'textDocument/didClose'
+init 'textDocument/documentSymbol'
init 'textDocument/hover'
init 'textDocument/implementation'
init 'textDocument/publishDiagnostics'
diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua
index aa4a5edc..ba183c5e 100644
--- a/server/src/method/initialize.lua
+++ b/server/src/method/initialize.lua
@@ -21,6 +21,8 @@ return function (lsp)
referencesProvider = true,
-- 支持“重命名”
renameProvider = true,
+ -- 支持“大纲”
+ documentSymbolProvider = true,
-- 支持“签名帮助”
signatureHelpProvider = {
triggerCharacters = { '(', ',' },
diff --git a/server/src/method/textDocument/documentSymbol.lua b/server/src/method/textDocument/documentSymbol.lua
new file mode 100644
index 00000000..1d301881
--- /dev/null
+++ b/server/src/method/textDocument/documentSymbol.lua
@@ -0,0 +1,85 @@
+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)
+ return {
+ start = {
+ line = start_row - 1,
+ character = start_col - 1,
+ },
+ ['end'] = {
+ line = finish_row - 1,
+ character = finish_col,
+ },
+ }
+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)
+ }
+end
+
+return function (lsp, params)
+ local uri = params.textDocument.uri
+ local vm, lines = lsp:loadVM(uri)
+ if not vm then
+ return nil
+ end
+
+ local i = 0
+ local function nextFunction()
+ i = i + 1
+ local func = vm.results.funcs[i]
+ return func
+ end
+
+ local symbols = {}
+ while true do
+ local func = nextFunction()
+ if not func then
+ break
+ end
+ symbols[1] = buildFunc(lines, func, nextFunction)
+ do break end
+ end
+
+ log.debug(table.dump(symbols))
+
+ return symbols
+end