From ca5deb5333d8be7dae9a2b4e4f83d7650601dad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 19 Dec 2018 14:16:18 +0800 Subject: =?UTF-8?q?=E5=85=88=E6=8E=A5=E4=B8=8A=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/method/initialize.lua | 6 ++-- server/src/method/textDocument/completion.lua | 48 ++++++++------------------- server/src/parser/ast.lua | 6 +++- 3 files changed, 21 insertions(+), 39 deletions(-) (limited to 'server/src') 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 -- cgit v1.2.3