diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-08-27 19:42:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-08-27 19:42:40 +0800 |
commit | aed2110c50c670d46e5b96f6a364bcaffc7e9608 (patch) | |
tree | 8026945777da083f2c87187e6b5f775e21ca0520 /server/src/core | |
parent | 4376c804058f8f3a2895c7795df4f102b8879084 (diff) | |
download | lua-language-server-aed2110c50c670d46e5b96f6a364bcaffc7e9608.zip |
关键字的一些代码片段
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/snippet.lua | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/server/src/core/snippet.lua b/server/src/core/snippet.lua index d29f4533..a098d6a0 100644 --- a/server/src/core/snippet.lua +++ b/server/src/core/snippet.lua @@ -1,16 +1,78 @@ local snippet = {} -snippet.key = {} +local function add(cate, key, label) + return function (text) + if not snippet[cate] then + snippet[cate] = {} + end + if not snippet[cate][key] then + snippet[cate][key] = {} + end + snippet[cate][key][#snippet[cate][key]+1] = { + label = label, + text = text, + } + end +end -snippet.key['do'] = { - { - label = 'do .. end', - text = [[ +add('key', 'do', 'do .. end') [[ do $0 end ]] - } -} + +add('key', 'elseif', 'elseif .. then') +[[elseif ${1:true} then]] + +add('key', 'for', 'for .. in') [[ +for ${1:key, value} in ${2:pairs(t)} do + $0 +end +]] + +add('key', 'for', 'for i = ..') [[ +for ${1:i} = ${2:1}, ${3:10, 2} do + $0 +end +]] + +add('key', 'function', 'function name()') [[ +function ${1:name}(${2:arg1, arg2, arg3}) + $0 +end +]] + +add('key', 'function', 'function ()') [[ +function (${1:arg1, arg2, arg3}) + $0 +end +]] + +add('key', 'local', 'local function') [[ +local function ${1:name}(${2:arg1, arg2, arg3}) + $0 +end +]] + +add('key', 'if', 'if .. then') [[ +if ${1:true} then + $0 +end +]] + +add('key', 'repeat', 'repeat .. until') [[ +repeat + $0 +until ${1:true} +]] + +add('key', 'while', 'while .. do') [[ +while ${1:true} do + $0 +end +]] + +add('key', 'return', 'do return end') +[[do return ${1:true} end]] return snippet |