summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/method/initialize.lua6
-rw-r--r--server/src/method/textDocument/completion.lua48
-rw-r--r--server/src/parser/ast.lua6
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