Skip to content

Commit

Permalink
feat(hipatterns)!: make default highlighting be more visible
Browse files Browse the repository at this point in the history
Make them reverse and bold of diagnostic groups instead of directly
linking to them.
  • Loading branch information
echasnovski committed Nov 30, 2024
1 parent 67357c4 commit b9dd171
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions lua/mini/hipatterns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions tests/test_hipatterns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b9dd171

Please sign in to comment.