diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e15a05..6da6b3de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - FEATURE: implement `yank_path` mapping to yank full path under cursor. +## mini.hipatterns + +- BREAKING FEATURE: make `MiniHipatterns{Fixme,Hack,Todo,Note}` highlight groups by default be inverse and bold variant of `Diagnostic{Error,Warn,Info,Hint}` group instead of directly link to it. This ensures better visibility for color schemes which don't have explicit support for 'mini.hipatterns'. + ## mini.hues - FEATURE: add `'lowmedium'` and `'mediumhigh'` saturation levels. diff --git a/lua/mini/hipatterns.lua b/lua/mini/hipatterns.lua index 9c48ed3b..92c11ba9 100644 --- a/lua/mini/hipatterns.lua +++ b/lua/mini/hipatterns.lua @@ -704,12 +704,20 @@ H.create_autocommands = function() au('ColorScheme', '*', H.on_colorscheme, 'Reload all enabled pattern highlighters') end ---stylua: ignore H.create_default_hl = function() - vim.api.nvim_set_hl(0, 'MiniHipatternsFixme', { default = true, link = 'DiagnosticError' }) - vim.api.nvim_set_hl(0, 'MiniHipatternsHack', { default = true, link = 'DiagnosticWarn' }) - vim.api.nvim_set_hl(0, 'MiniHipatternsTodo', { default = true, link = 'DiagnosticInfo' }) - vim.api.nvim_set_hl(0, 'MiniHipatternsNote', { default = true, link = 'DiagnosticHint' }) + local get_hl_data = vim.fn.has('nvim-0.9') == 1 + and function(x) return vim.api.nvim_get_hl(0, { name = x, link = false }) end + or function(x) return vim.api.nvim_get_hl_by_name(x, true) end + local hi_link_bold_reverse = function(to, from) + local data = get_hl_data(from) + data.default, data.bold, data.reverse = true, true, true + data.cterm = { bold = true, reverse = true } + vim.api.nvim_set_hl(0, to, data) + end + hi_link_bold_reverse('MiniHipatternsFixme', 'DiagnosticError') + hi_link_bold_reverse('MiniHipatternsHack', 'DiagnosticWarn') + hi_link_bold_reverse('MiniHipatternsTodo', 'DiagnosticInfo') + hi_link_bold_reverse('MiniHipatternsNote', 'DiagnosticHint') end H.is_disabled = function(buf_id) diff --git a/tests/test_hipatterns.lua b/tests/test_hipatterns.lua index 6c7d5bd6..46552dc8 100644 --- a/tests/test_hipatterns.lua +++ b/tests/test_hipatterns.lua @@ -89,11 +89,18 @@ T['setup()']['creates side effects'] = function() -- Highlight groups child.cmd('hi clear') + child.cmd('hi DiagnosticError guifg=#ff0000 ctermfg=9') + child.cmd('hi DiagnosticWarn guifg=#ffff00 ctermfg=11') + child.cmd('hi DiagnosticInfo guifg=#0000ff ctermfg=14') + child.cmd('hi DiagnosticHint guifg=#00ffff ctermfg=12') load_module() - expect.match(child.cmd_capture('hi MiniHipatternsFixme'), 'links to DiagnosticError') - expect.match(child.cmd_capture('hi MiniHipatternsHack'), 'links to DiagnosticWarn') - expect.match(child.cmd_capture('hi MiniHipatternsTodo'), 'links to DiagnosticInfo') - expect.match(child.cmd_capture('hi MiniHipatternsNote'), 'links to DiagnosticHint') + local has_highlight = function(group, value) expect.match(child.cmd_capture('hi ' .. group), value) end + if child.fn.has('nvim-0.9') == 0 then MiniTest.skip('Neovim<0.9 does not preserve `ctermfg`, which is fine.') end + + has_highlight('MiniHipatternsFixme', 'cterm=bold,reverse ctermfg=9 gui=bold,reverse guifg=#ff0000') + has_highlight('MiniHipatternsHack', 'cterm=bold,reverse ctermfg=11 gui=bold,reverse guifg=#ffff00') + has_highlight('MiniHipatternsTodo', 'cterm=bold,reverse ctermfg=14 gui=bold,reverse guifg=#0000ff') + has_highlight('MiniHipatternsNote', 'cterm=bold,reverse ctermfg=12 gui=bold,reverse guifg=#00ffff') end T['setup()']['creates `config` field'] = function() @@ -129,7 +136,7 @@ end T['setup()']['ensures colors'] = function() load_module() child.cmd('colorscheme default') - expect.match(child.cmd_capture('hi MiniHipatternsFixme'), 'links to DiagnosticError') + expect.match(child.cmd_capture('hi MiniHipatternsFixme'), 'gui=bold,reverse') end T['Auto enable'] = new_set()