fix(diagnostic)!: make virtual text handler opt-in (#32079)

Making this opt-out (on by default) was the wrong choice from the
beginning. It is too visually noisy to be enabled by default.

BREAKING CHANGE: Users must opt-in to the diagnostic virtual text
handler by adding

  vim.diagnostic.config({ virtual_text = true })

to their config.
This commit is contained in:
Gregory Anders
2025-01-18 07:43:21 -06:00
committed by GitHub
parent 954d4969c9
commit 51ccd12b3d
4 changed files with 30 additions and 6 deletions

View File

@ -464,7 +464,7 @@ Lua module: vim.diagnostic *diagnostic-api*
Fields: ~ Fields: ~
• {underline}? (`boolean|vim.diagnostic.Opts.Underline|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Underline`, default: `true`) • {underline}? (`boolean|vim.diagnostic.Opts.Underline|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Underline`, default: `true`)
Use underline for diagnostics. Use underline for diagnostics.
• {virtual_text}? (`boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText`, default: `true`) • {virtual_text}? (`boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText`, default: `false`)
Use virtual text for diagnostics. If multiple Use virtual text for diagnostics. If multiple
diagnostics are set for a namespace, one prefix diagnostics are set for a namespace, one prefix
per diagnostic + the last diagnostic message are per diagnostic + the last diagnostic message are

View File

@ -70,7 +70,9 @@ DIAGNOSTICS
the "severity_sort" option. the "severity_sort" option.
• Diagnostics are filtered by severity before being passed to a diagnostic • Diagnostics are filtered by severity before being passed to a diagnostic
handler |diagnostic-handlers|. handler |diagnostic-handlers|.
• The "virtual_text" handler is disabled by default. Enable with >lua
vim.diagnostic.config({ virtual_text = true })
<
EDITOR EDITOR
• The order in which signs are placed was changed. Higher priority signs will • The order in which signs are placed was changed. Higher priority signs will

View File

@ -70,7 +70,7 @@ end
--- Use virtual text for diagnostics. If multiple diagnostics are set for a --- Use virtual text for diagnostics. If multiple diagnostics are set for a
--- namespace, one prefix per diagnostic + the last diagnostic message are --- namespace, one prefix per diagnostic + the last diagnostic message are
--- shown. --- shown.
--- (default: `true`) --- (default: `false`)
--- @field virtual_text? boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText --- @field virtual_text? boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText
--- ---
--- Use signs for diagnostics |diagnostic-signs|. --- Use signs for diagnostics |diagnostic-signs|.
@ -312,7 +312,7 @@ M.severity = {
local global_diagnostic_options = { local global_diagnostic_options = {
signs = true, signs = true,
underline = true, underline = true,
virtual_text = true, virtual_text = false,
float = true, float = true,
update_in_insert = false, update_in_insert = false,
severity_sort = false, severity_sort = false,

View File

@ -369,6 +369,9 @@ describe('vim.diagnostic', function()
end) end)
it('handles one namespace clearing highlights while the other still has highlights', function() it('handles one namespace clearing highlights while the other still has highlights', function()
exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
end)
-- 1 Error (1) -- 1 Error (1)
-- 1 Warning (2) -- 1 Warning (2)
-- 1 Warning (2) + 1 Warning (1) -- 1 Warning (2) + 1 Warning (1)
@ -443,6 +446,10 @@ describe('vim.diagnostic', function()
end) end)
it('does not display diagnostics when disabled', function() it('does not display diagnostics when disabled', function()
exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
end)
eq( eq(
{ 0, 2 }, { 0, 2 },
exec_lua(function() exec_lua(function()
@ -916,6 +923,10 @@ describe('vim.diagnostic', function()
describe('reset()', function() describe('reset()', function()
it('diagnostic count is 0 and displayed diagnostics are 0 after call', function() it('diagnostic count is 0 and displayed diagnostics are 0 after call', function()
exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
end)
-- 1 Error (1) -- 1 Error (1)
-- 1 Warning (2) -- 1 Warning (2)
-- 1 Warning (2) + 1 Warning (1) -- 1 Warning (2) + 1 Warning (1)
@ -2117,7 +2128,11 @@ describe('vim.diagnostic', function()
end) end)
it('can perform updates after insert_leave', function() it('can perform updates after insert_leave', function()
exec_lua [[vim.api.nvim_set_current_buf( _G.diagnostic_bufnr)]] exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
vim.api.nvim_set_current_buf(_G.diagnostic_bufnr)
end)
api.nvim_input('o') api.nvim_input('o')
eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
@ -2258,7 +2273,10 @@ describe('vim.diagnostic', function()
end) end)
it('can perform updates while in insert mode, if desired', function() it('can perform updates while in insert mode, if desired', function()
exec_lua [[vim.api.nvim_set_current_buf( _G.diagnostic_bufnr)]] exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
vim.api.nvim_set_current_buf(_G.diagnostic_bufnr)
end)
api.nvim_input('o') api.nvim_input('o')
eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
@ -2292,6 +2310,10 @@ describe('vim.diagnostic', function()
end) end)
it('can set diagnostics without displaying them', function() it('can set diagnostics without displaying them', function()
exec_lua(function()
vim.diagnostic.config({ virtual_text = true })
end)
eq( eq(
0, 0,
exec_lua(function() exec_lua(function()