diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/core/completion/postfix.lua | 47 | ||||
-rw-r--r-- | script/provider/completion.lua | 2 | ||||
-rw-r--r-- | test/completion/common.lua | 38 |
4 files changed, 87 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md index 466d549d..4c4b06f2 100644 --- a/changelog.md +++ b/changelog.md @@ -18,7 +18,7 @@ * `NEW` locale `pt-br`, thanks [Jeferson Ferreira](https://github.com/jefersonf) * `NEW` supports [utf-8-offsets](https://clangd.llvm.org/extensions#utf-8-offsets) * `NEW` supports quickfix for `.luarc.json` -* `NEW` completion postifx: `@function`, `@method`, `@pcall`, `@xpcall` +* `NEW` completion postifx: `@function`, `@method`, `@pcall`, `@xpcall`, `++`, `++?` * `CHG` `LuaDoc`: + `---@class` can be re-declared + supports unicode 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 diff --git a/script/provider/completion.lua b/script/provider/completion.lua index 12b1f676..ec31858a 100644 --- a/script/provider/completion.lua +++ b/script/provider/completion.lua @@ -6,7 +6,7 @@ local config = require 'config' local isEnable = false local function allWords() - local str = '\t\n.:(\'"[,#*@|=-{/\\ ' + local str = '\t\n.:(\'"[,#*@|=-{/\\ +?' local mark = {} local list = {} for c in str:gmatch '.' do diff --git a/test/completion/common.lua b/test/completion/common.lua index d3e56616..2bfc69a2 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -2953,3 +2953,41 @@ xx:yy@method<??> } }, } + +TEST [[ +xx++<??> +]] +{ + [1] = { + label = '++', + kind = define.CompletionItemKind.Event, + textEdit = { + start = 2, + finish = 4, + newText = 'xx = xx + 1', + }, + additionalTextEdits = { + { + start = 0, + finish = 2, + newText = '' + } + } + }, + [2] = { + label = '++?', + kind = define.CompletionItemKind.Event, + textEdit = { + start = 2, + finish = 4, + newText = 'xx = (xx or 0) + 1', + }, + additionalTextEdits = { + { + start = 0, + finish = 2, + newText = '' + } + } + }, +} |