diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-02-08 23:16:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 23:16:18 +0800 |
commit | fb3b0601c16cbe9579a7e060291e6656b28bf2f7 (patch) | |
tree | 8d58bec27a48508ca42bdf0272562cad77b7eff9 /script/core | |
parent | 86237012d5b80833d64547199c167db263626a2c (diff) | |
parent | 43f774f396d1457ed59341e2fe94f0f5af1e3a93 (diff) | |
download | lua-language-server-fb3b0601c16cbe9579a7e060291e6656b28bf2f7.zip |
Merge pull request #944 from kevinhwang91/improve-postfix
feat(postfix): add templates
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/postfix.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua index 984ad03c..3b58d0b2 100644 --- a/script/core/completion/postfix.lua +++ b/script/core/completion/postfix.lua @@ -133,6 +133,60 @@ register 'xpcall' { end } +register 'local' { + function (state, source, callback) + if source.type ~= 'getglobal' + and source.type ~= 'getfield' + and source.type ~= 'getmethod' + and source.type ~= 'getindex' + and source.type ~= 'getlocal' + and source.type ~= 'call' + and source.type ~= 'table' then + return + end + local subber = subString(state) + callback(string.format('local $1 = %s$0' + , subber(source.start + 1, source.finish) + )) + end +} + +register 'ipairs' { + function (state, source, callback) + if source.type ~= 'getglobal' + and source.type ~= 'getfield' + and source.type ~= 'getmethod' + and source.type ~= 'getindex' + and source.type ~= 'getlocal' + and source.type ~= 'call' + and source.type ~= 'table' then + return + end + local subber = subString(state) + callback(string.format('for ${1:i}, ${2:v} in ipairs(%s) do\n\t$0\nend' + , subber(source.start + 1, source.finish) + )) + end +} + +register 'pairs' { + function (state, source, callback) + if source.type ~= 'getglobal' + and source.type ~= 'getfield' + and source.type ~= 'getmethod' + and source.type ~= 'getindex' + and source.type ~= 'getlocal' + and source.type ~= 'call' + and source.type ~= 'table' then + return + end + local subber = subString(state) + callback(string.format('for ${1:k}, ${2:v} in pairs(%s) do\n\t$0\nend' + , subber(source.start + 1, source.finish) + )) + end +} + register 'insert' { function (state, source, callback) if source.type ~= 'getglobal' |