aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2023-03-12 09:45:28 +0100
committerGitHub <noreply@github.com>2023-03-12 09:45:28 +0100
commitd15abd1be4ae85b10174e3ee139d3b7605e87577 (patch)
treeed40845811b796d2b80a42a8a8be9cf5716c6d6b /test/functional
parent314f20a44fdfdc382b0ce9d124290d3e7d702d42 (diff)
downloadrneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.tar.gz
rneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.tar.bz2
rneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.zip
fix(lsp): use line start/end for visual line selection (#22632)
Fixes https://github.com/neovim/neovim/issues/22629
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/plugin/lsp_spec.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index c621a5eae2..a6e50ac82c 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -3554,6 +3554,7 @@ describe('LSP', function()
vim.cmd.normal('v')
vim.api.nvim_win_set_cursor(0, { 2, 3 })
vim.lsp.buf.format({ bufnr = bufnr, false })
+ vim.lsp.stop_client(client_id)
return server.messages
]])
eq("textDocument/rangeFormatting", result[3].method)
@@ -3563,6 +3564,52 @@ describe('LSP', function()
}
eq(expected_range, result[3].params.range)
end)
+ it('format formats range in visual line mode', function()
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local server = _create_server({ capabilities = {
+ documentFormattingProvider = true,
+ documentRangeFormattingProvider = true,
+ }})
+ local bufnr = vim.api.nvim_get_current_buf()
+ local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ vim.api.nvim_win_set_buf(0, bufnr)
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {'foo', 'bar baz'})
+ vim.api.nvim_win_set_cursor(0, { 1, 2 })
+ vim.cmd.normal('V')
+ vim.api.nvim_win_set_cursor(0, { 2, 1 })
+ vim.lsp.buf.format({ bufnr = bufnr, false })
+
+ -- Format again with visual lines going from bottom to top
+ -- Must result in same formatting
+ vim.cmd.normal("<ESC>")
+ vim.api.nvim_win_set_cursor(0, { 2, 1 })
+ vim.cmd.normal('V')
+ vim.api.nvim_win_set_cursor(0, { 1, 2 })
+ vim.lsp.buf.format({ bufnr = bufnr, false })
+
+ vim.lsp.stop_client(client_id)
+ return server.messages
+ ]])
+ local expected_methods = {
+ "initialize",
+ "initialized",
+ "textDocument/rangeFormatting",
+ "$/cancelRequest",
+ "textDocument/rangeFormatting",
+ "$/cancelRequest",
+ "shutdown",
+ "exit",
+ }
+ eq(expected_methods, vim.tbl_map(function(x) return x.method end, result))
+ -- uses first column of start line and last column of end line
+ local expected_range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 1, character = 7 },
+ }
+ eq(expected_range, result[3].params.range)
+ eq(expected_range, result[5].params.range)
+ end)
it('Aborts with notify if no clients support requested method', function()
exec_lua(create_server_definition)
exec_lua([[