aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2022-04-30 17:23:50 +0200
committerGitHub <noreply@github.com>2022-04-30 17:23:50 +0200
commit88411613e23bd829088f48983f0253f1b7e5c3fd (patch)
tree20b651ac4c5adf9bec31ea6c1cfb81fd3b768c1a /test
parent338b9032194a4bc4c98439eb00f65a8ec86609f2 (diff)
downloadrneovim-88411613e23bd829088f48983f0253f1b7e5c3fd.tar.gz
rneovim-88411613e23bd829088f48983f0253f1b7e5c3fd.tar.bz2
rneovim-88411613e23bd829088f48983f0253f1b7e5c3fd.zip
feat(lsp): add async option to vim.lsp.buf.format (#18322)
Deprecates the existing `vim.lsp.buf.formatting` function. With this, `vim.lsp.buf.format` will replace all three: - vim.lsp.buf.formatting - vim.lsp.buf.formatting_sync - vim.lsp.buf.formatting_seq_sync
Diffstat (limited to 'test')
-rw-r--r--test/functional/plugin/lsp_spec.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 6e28946cc4..be717cf724 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2833,5 +2833,49 @@ describe('LSP', function()
end,
}
end)
+ it('Can format async', function()
+ local expected_handlers = {
+ {NIL, {}, {method="shutdown", client_id=1}};
+ {NIL, {}, {method="start", client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "basic_formatting",
+ on_init = function(c)
+ client = c
+ end,
+ on_handler = function(_, _, ctx)
+ table.remove(expected_handlers)
+ if ctx.method == "start" then
+ local result = exec_lua([[
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID)
+
+ local notify_msg
+ local notify = vim.notify
+ vim.notify = function(msg, log_level)
+ notify_msg = msg
+ end
+
+ local handler = vim.lsp.handlers['textDocument/formatting']
+ local handler_called = false
+ vim.lsp.handlers['textDocument/formatting'] = function(...)
+ handler_called = true
+ end
+
+ vim.lsp.buf.format({ bufnr = bufnr, async = true })
+ vim.wait(1000, function() return handler_called end)
+
+ vim.notify = notify
+ vim.lsp.handlers['textDocument/formatting'] = handler
+ return {notify = notify_msg, handler_called = handler_called}
+ ]])
+ eq({handler_called=true}, result)
+ elseif ctx.method == "shutdown" then
+ client.stop()
+ end
+ end,
+ }
+ end)
end)
end)