summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-27 17:16:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-27 17:16:42 +0800
commit4376c804058f8f3a2895c7795df4f102b8879084 (patch)
treed680a7662fa0d2d2d055b5f350e52cf81357cb73
parenta90fa730acdbd823e556dcbc66ab8a360650c290 (diff)
downloadlua-language-server-4376c804058f8f3a2895c7795df4f102b8879084.zip
支持关键字代码片段
-rw-r--r--server/src/core/completion.lua9
-rw-r--r--server/src/core/snippet.lua16
2 files changed, 25 insertions, 0 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 45e1ab4f..5a403a55 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -7,6 +7,7 @@ local config = require 'config'
local matchKey = require 'core.matchKey'
local parser = require 'parser'
local lang = require 'language'
+local snippet = require 'core.snippet'
local State
local CompletionItemKind = {
@@ -355,6 +356,14 @@ local function searchKeyWords(vm, source, word, callback)
for _, key in ipairs(KEYS) do
if matchKey(word, key) then
callback(key, nil, CompletionItemKind.Keyword)
+ if snippet.key[key] then
+ for _, data in ipairs(snippet.key[key]) do
+ callback(data.label, nil, CompletionItemKind.Snippet, {
+ insertTextFormat = 2,
+ insertText = data.text,
+ })
+ end
+ end
end
end
end
diff --git a/server/src/core/snippet.lua b/server/src/core/snippet.lua
new file mode 100644
index 00000000..d29f4533
--- /dev/null
+++ b/server/src/core/snippet.lua
@@ -0,0 +1,16 @@
+local snippet = {}
+
+snippet.key = {}
+
+snippet.key['do'] = {
+ {
+ label = 'do .. end',
+ text = [[
+do
+ $0
+end
+]]
+ }
+}
+
+return snippet