summaryrefslogtreecommitdiff
path: root/script/core/completion
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-11-24 16:50:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-11-24 16:50:52 +0800
commit9143322ddf72876f3c89349e37a62cdf20cf3b65 (patch)
tree88a3229f262f2890acb25fe56d0f6dca5880019f /script/core/completion
parent13123693e692c6bcf1703e2ec4538d940cdc9d2c (diff)
downloadlua-language-server-9143322ddf72876f3c89349e37a62cdf20cf3b65.zip
postifx supports `++` and `++?`
Diffstat (limited to 'script/core/completion')
-rw-r--r--script/core/completion/postfix.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua
index 434c2a82..d1959fd0 100644
--- a/script/core/completion/postfix.lua
+++ b/script/core/completion/postfix.lua
@@ -133,6 +133,38 @@ register 'xpcall' {
end
}
+register '++' {
+ function (state, source, callback)
+ if source.type ~= 'getglobal'
+ and source.type ~= 'getfield'
+ and source.type ~= 'getindex'
+ and source.type ~= 'getlocal' then
+ return
+ end
+ local subber = subString(state)
+ callback(string.format('%s = %s + 1'
+ , subber(source.start + 1, source.finish)
+ , subber(source.start + 1, source.finish)
+ ))
+ end
+}
+
+register '++?' {
+ function (state, source, callback)
+ if source.type ~= 'getglobal'
+ and source.type ~= 'getfield'
+ and source.type ~= 'getindex'
+ and source.type ~= 'getlocal' then
+ return
+ end
+ local subber = subString(state)
+ callback(string.format('%s = (%s or 0) + 1'
+ , subber(source.start + 1, source.finish)
+ , subber(source.start + 1, source.finish)
+ ))
+ end
+}
+
local accepts = {
['local'] = true,
['getlocal'] = true,
@@ -195,5 +227,20 @@ return function (state, position, results)
checkPostFix(state, word or '', wordPosition, position, results)
return symbol ~= '.' and symbol ~= ':'
end
+ if not word then
+ if symbol == '+' then
+ word = text:sub(offset - 1, offset)
+ offset = offset - 2
+ end
+ if symbol == '?' then
+ word = text:sub(offset - 2, offset)
+ offset = offset - 3
+ end
+ if word then
+ local wordPosition = guide.offsetToPosition(state, offset - 1)
+ checkPostFix(state, word or '', wordPosition, position, results)
+ return true
+ end
+ end
return false
end