From 8a3bc607d69b521472e5416cae14866e00a2c198 Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 2 Sep 2024 15:44:02 +0800 Subject: [PATCH] fix(diagnostic): add cursorlinehl in vim.diagnotic.opts.Signs Problem: extmark also support cursorline_hl_group when cursorline is on. Solution: support it on vim.diangostic.optss.Signs --- runtime/doc/diagnostic.txt | 46 ++++++++++++++----------- runtime/lua/vim/diagnostic.lua | 6 ++++ test/functional/lua/diagnostic_spec.lua | 6 +++- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index 444829c325..cda1f91af7 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -526,28 +526,32 @@ Lua module: vim.diagnostic *diagnostic-api* *vim.diagnostic.Opts.Signs* Fields: ~ - • {severity}? (`vim.diagnostic.SeverityFilter`) Only show virtual text - for diagnostics matching the given severity - |diagnostic-severity| - • {priority}? (`integer`, default: `10`) Base priority to use for - signs. When {severity_sort} is used, the priority of a - sign is adjusted based on its severity. Otherwise, all - signs use the same priority. - • {text}? (`table`) A table mapping - |diagnostic-severity| to the sign text to display in the - sign column. The default is to use `"E"`, `"W"`, `"I"`, - and `"H"` for errors, warnings, information, and hints, - respectively. Example: >lua - vim.diagnostic.config({ - signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } } - }) + • {severity}? (`vim.diagnostic.SeverityFilter`) Only show virtual + text for diagnostics matching the given severity + |diagnostic-severity| + • {priority}? (`integer`, default: `10`) Base priority to use for + signs. When {severity_sort} is used, the priority of a + sign is adjusted based on its severity. Otherwise, all + signs use the same priority. + • {text}? (`table`) A table + mapping |diagnostic-severity| to the sign text to + display in the sign column. The default is to use + `"E"`, `"W"`, `"I"`, and `"H"` for errors, warnings, + information, and hints, respectively. Example: >lua + vim.diagnostic.config({ + signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } } + }) < - • {numhl}? (`table`) A table mapping - |diagnostic-severity| to the highlight group used for the - line number where the sign is placed. - • {linehl}? (`table`) A table mapping - |diagnostic-severity| to the highlight group used for the - whole line the sign is placed in. + • {numhl}? (`table`) A table + mapping |diagnostic-severity| to the highlight group + used for the line number where the sign is placed. + • {linehl}? (`table`) A table + mapping |diagnostic-severity| to the highlight group + used for the whole line the sign is placed in. + • {cursorlinehl} (`table`) A table + mapping |diagnostic-severity| to the highlight group + used for the highlight the sign column text when + cursor is on target line and 'cursorline' is enabled. *vim.diagnostic.Opts.Underline* diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index db540c0dc1..dd6a5e836c 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -243,6 +243,10 @@ local M = {} --- A table mapping |diagnostic-severity| to the highlight group used for the --- whole line the sign is placed in. --- @field linehl? table +--- +--- A table mapping |diagnostic-severity| to the highlight group used for the +--- highlight the sign column text when cursor is on target line and 'cursorline' is enabled. +--- @field cursorlinehl table --- @class vim.diagnostic.Opts.Jump --- @@ -1447,6 +1451,7 @@ M.handlers.signs = { local numhl = opts.signs.numhl or {} local linehl = opts.signs.linehl or {} + local curlinehl = opts.signs.cursorlinehl or {} local line_count = api.nvim_buf_line_count(bufnr) @@ -1457,6 +1462,7 @@ M.handlers.signs = { sign_hl_group = sign_highlight_map[diagnostic.severity], number_hl_group = numhl[diagnostic.severity], line_hl_group = linehl[diagnostic.severity], + cursorline_hl_group = vim.wo.cursorline and curlinehl[diagnostic.severity] or nil, priority = get_priority(diagnostic.severity), }) end diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 718b9469a3..c5e7231a53 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -2347,6 +2347,7 @@ describe('vim.diagnostic', function() -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 eq(0, n.fn.has('nvim-0.12')) + n.command('set cursorline') n.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg') n.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg') n.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined') @@ -2354,7 +2355,7 @@ describe('vim.diagnostic', function() local result = exec_lua(function() vim.diagnostic.config({ - signs = true, + signs = { cursorlinehl = { 'DiagnosticError', 'DiagnosticWarn' } }, }) local diagnostics = { @@ -2382,6 +2383,7 @@ describe('vim.diagnostic', function() text = s[4].sign_text or '', numhl = s[4].number_hl_group, linehl = s[4].line_hl_group, + culhl = s[4].cursorline_hl_group, } end return result @@ -2393,6 +2395,7 @@ describe('vim.diagnostic', function() text = '', numhl = 'ErrorMsg', linehl = 'ErrorMsg', + culhl = 'DiagnosticError', }, result[1]) eq({ @@ -2401,6 +2404,7 @@ describe('vim.diagnostic', function() text = '', numhl = 'WarningMsg', linehl = 'WarningMsg', + culhl = 'DiagnosticWarn', }, result[2]) end) end)