diff options
-rw-r--r-- | script/core/completion/postfix.lua | 24 | ||||
-rw-r--r-- | test/completion/common.lua | 74 |
2 files changed, 93 insertions, 5 deletions
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua index 16bada87..ee4df4b4 100644 --- a/script/core/completion/postfix.lua +++ b/script/core/completion/postfix.lua @@ -30,7 +30,29 @@ register 'pcall' { )) end else - callback(string.format('pcall(%s)' + callback(string.format('pcall(%s$1)$0' + , subber(source.start + 1, source.finish) + )) + end + end +} + +register 'xpcall' { + function (state, source, callback) + local subber = subString(state) + if source.type == 'call' then + if source.args and #source.args > 0 then + callback(string.format('xpcall(%s, ${1:debug.traceback}, %s)$0' + , subber(source.node.start + 1, source.node.finish) + , subber(source.args[1].start + 1, source.args[#source.args].finish) + )) + else + callback(string.format('xpcall(%s, ${1:debug.traceback})$0' + , subber(source.node.start + 1, source.node.finish) + )) + end + else + callback(string.format('xpcall(%s, ${1:debug.traceback}$2)$0' , subber(source.start + 1, source.finish) )) end diff --git a/test/completion/common.lua b/test/completion/common.lua index 7d6ba0c8..0dfabb07 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -2766,7 +2766,7 @@ xx@pcall<??> textEdit = { start = 3, finish = 8, - newText = 'pcall(xx)', + newText = 'pcall(xx$1)$0', }, additionalTextEdits = { { @@ -2775,7 +2775,7 @@ xx@pcall<??> newText = '' } } - } + }, } TEST [[ @@ -2797,7 +2797,7 @@ xx()@pcall<??> newText = '' } } - } + }, } TEST [[ @@ -2819,5 +2819,71 @@ xx(1, 2, 3)@pcall<??> newText = '' } } - } + }, +} + +TEST [[ +xx@xpcall<??> +]] +{ + [1] = { + label = 'xpcall', + kind = define.CompletionItemKind.Event, + textEdit = { + start = 3, + finish = 9, + newText = 'xpcall(xx, ${1:debug.traceback}$2)$0', + }, + additionalTextEdits = { + { + start = 0, + finish = 3, + newText = '' + } + } + }, +} + +TEST [[ +xx()@xpcall<??> +]] +{ + [1] = { + label = 'xpcall', + kind = define.CompletionItemKind.Event, + textEdit = { + start = 5, + finish = 11, + newText = 'xpcall(xx, ${1:debug.traceback})$0', + }, + additionalTextEdits = { + { + start = 0, + finish = 5, + newText = '' + } + } + }, +} + +TEST [[ +xx(1, 2, 3)@xpcall<??> +]] +{ + [1] = { + label = 'xpcall', + kind = define.CompletionItemKind.Event, + textEdit = { + start = 12, + finish = 18, + newText = 'xpcall(xx, ${1:debug.traceback}, 1, 2, 3)$0', + }, + additionalTextEdits = { + { + start = 0, + finish = 12, + newText = '' + } + } + }, } |