diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-19 14:16:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-19 14:16:18 +0800 |
commit | ca5deb5333d8be7dae9a2b4e4f83d7650601dad0 (patch) | |
tree | 7919a466645b41fab6739b49eb0277a39b5b3966 /server/src | |
parent | 2aca34e65556b3428f4596906dfa6aa7a639c7b5 (diff) | |
download | lua-language-server-ca5deb5333d8be7dae9a2b4e4f83d7650601dad0.zip |
先接上协议
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/method/initialize.lua | 6 | ||||
-rw-r--r-- | server/src/method/textDocument/completion.lua | 48 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 6 |
3 files changed, 21 insertions, 39 deletions
diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 8daa2ae6..76fe3793 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -20,9 +20,9 @@ return function (lsp) change = 1, }, -- 自动完成 - --completionProvider = { - -- resolveProvider = false, - --}, + completionProvider = { + resolveProvider = false, + }, -- 工作目录 workspace = { workspaceFolders = { diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index 2e03882e..bac6ce22 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -1,39 +1,17 @@ -local CompletionItemKind = { - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25, -} +local matcher = require 'matcher' return function (lsp, params) - return { - isIncomplete = true, - items = { - { - label = 'xxxx', - kind = CompletionItemKind.Method, - } - } + local uri = params.textDocument.uri + local vm, lines = lsp:loadText(uri) + if not vm then + return {} + end + -- lua是从1开始的,因此都要+1 + local position = lines:position(params.position.line + 1, params.position.character + 1) + local items = matcher.completion(vm, position) + local response = { + isIncomplete = false, + items = items, } + return response end diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index f2356531..5e6b9fcf 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -71,10 +71,14 @@ local defs = { end, Simple = function (first, ...) if ... then - return { + local obj = { type = 'simple', + start = first.start, first, ..., } + local last = obj[#obj] + obj.finish = last.finish + return obj elseif first == '' then return nil else |