diff options
author | kevinhwang91 <kevin.hwang@live.com> | 2022-02-07 01:16:41 +0800 |
---|---|---|
committer | kevinhwang91 <kevin.hwang@live.com> | 2022-02-08 23:06:00 +0800 |
commit | 43f774f396d1457ed59341e2fe94f0f5af1e3a93 (patch) | |
tree | c3273ae933b61fab2fc495e2b85976c8a646a129 /script/core | |
parent | 7842cd0e12e9d6a1971ff557a035f08386296198 (diff) | |
download | lua-language-server-43f774f396d1457ed59341e2fe94f0f5af1e3a93.zip |
feat(postfix): reduce its priority and add templates
In the language server like gopls, which supports `var` to
assign variable and `range` to iterate collection, we should add
these templates for postfix in Lua as well.
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 2ac24933..0bdc1d54 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' |