aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2022-09-08 11:33:04 +0200
committerGitHub <noreply@github.com>2022-09-08 11:33:04 +0200
commit11167ab6d569994dd0a4f58155c84b118706380c (patch)
treee0e4b1bac8ce4c454c9914c7924e71a205259500 /test
parent8c59d7e6a719b4d8e14441e6ba9e551bd84ed3d1 (diff)
downloadrneovim-11167ab6d569994dd0a4f58155c84b118706380c.tar.gz
rneovim-11167ab6d569994dd0a4f58155c84b118706380c.tar.bz2
rneovim-11167ab6d569994dd0a4f58155c84b118706380c.zip
feat(lsp): add range option to lsp.buf.format (#19998)
Diffstat (limited to 'test')
-rw-r--r--test/functional/plugin/lsp_spec.lua48
1 files changed, 47 insertions, 1 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index fa731f6faf..9da2c4aa61 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -3180,8 +3180,54 @@ describe('LSP', function()
end,
}
end)
+ it('format formats range in visual mode', function()
+ local result = exec_lua([[
+ local messages = {}
+ local server = function(dispatchers)
+ local closing = false
+ return {
+ request = function(method, params, callback)
+ table.insert(messages, {
+ method = method,
+ params = params,
+ })
+ if method == 'initialize' then
+ callback(nil, {
+ capabilities = {
+ documentFormattingProvider = true,
+ documentRangeFormattingProvider = true,
+ }
+ })
+ end
+ end,
+ notify = function(...)
+ end,
+ is_closing = function()
+ return closing
+ end,
+ terminate = function()
+ closing = true
+ end
+ }
+ end
+ local bufnr = vim.api.nvim_get_current_buf()
+ local client_id = vim.lsp.start({ name = 'dummy', cmd = server })
+ vim.api.nvim_win_set_buf(0, bufnr)
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {'foo', 'bar'})
+ vim.api.nvim_win_set_cursor(0, { 1, 0 })
+ vim.cmd.normal('v')
+ vim.api.nvim_win_set_cursor(0, { 2, 3 })
+ vim.lsp.buf.format({ bufnr = bufnr, false })
+ return messages
+ ]])
+ eq("textDocument/rangeFormatting", result[2].method)
+ local expected_range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 1, character = 4 },
+ }
+ eq(expected_range, result[2].params.range)
+ end)
end)
-
describe('cmd', function()
it('can connect to lsp server via rpc.connect', function()
local result = exec_lua [[