aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/diagnostic_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2021-07-19 12:49:55 -0600
committerGitHub <noreply@github.com>2021-07-19 11:49:55 -0700
commit1aeb945553a12ab5e88d9dca68d30a11ddc410fd (patch)
tree4075ec03f6c91150fe0e9374a1a15ac46d010be9 /test/functional/plugin/lsp/diagnostic_spec.lua
parentc487a73fa22f3815dc043e188cc73418115211e1 (diff)
downloadrneovim-1aeb945553a12ab5e88d9dca68d30a11ddc410fd.tar.gz
rneovim-1aeb945553a12ab5e88d9dca68d30a11ddc410fd.tar.bz2
rneovim-1aeb945553a12ab5e88d9dca68d30a11ddc410fd.zip
feat(lsp): allow diagnostics to be disabled for a buffer (#15134)
Add two new methods to allow diagnostics to be disabled (and re-enabled) in the current buffer. When diagnostics are disabled they are simply not displayed to the user, but they are still sent by the server and processed by the client. Disabling diagnostics can be helpful in a number of scenarios. For example, if one is working on a buffer with an overwhelming amount of diagnostic warnings it can be helpful to simply disable diagnostics without disabling the LSP client entirely. This also allows users more flexibility on when and how they may want diagnostic information to be displayed. For example, some users may not want to display diagnostic information until after the buffer is first written.
Diffstat (limited to 'test/functional/plugin/lsp/diagnostic_spec.lua')
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index c1c76c3916..7359ee4bce 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -241,6 +241,38 @@ describe('vim.lsp.diagnostic', function()
]]))
end)
+ it('should not display diagnostics when disabled', function()
+ eq({0, 2}, exec_lua [[
+ local server_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local server_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+
+ vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1)
+ vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2)
+
+ vim.lsp.diagnostic.disable(diagnostic_bufnr, 1)
+
+ return {
+ count_of_extmarks_for_client(diagnostic_bufnr, 1),
+ count_of_extmarks_for_client(diagnostic_bufnr, 2),
+ }
+ ]])
+
+ eq({4, 0}, exec_lua [[
+ vim.lsp.diagnostic.enable(diagnostic_bufnr, 1)
+ vim.lsp.diagnostic.disable(diagnostic_bufnr, 2)
+
+ return {
+ count_of_extmarks_for_client(diagnostic_bufnr, 1),
+ count_of_extmarks_for_client(diagnostic_bufnr, 2),
+ }
+ ]])
+ end)
+
describe('reset', function()
it('diagnostic count is 0 and displayed diagnostics are 0 after call', function()
-- 1 Error (1)