sainnhe / gruvbox-material

Gruvbox with Material Palette
MIT License
1.83k stars 164 forks source link

feat(configuration): add g:gruvbox_material_inlay_hints_background #204

Closed sainnhe closed 2 months ago

sainnhe commented 2 months ago

Fix #190

This PR adds a config option named g:gruvbox_material_inlay_hints_background which has two possible values:

  1. none: default value, no background
  2. dimmed: dimmed background

Preview of dimmed background:

截屏2024-05-17 13 58 05 截屏2024-05-17 13 58 28

I'm considering using dimmed as default value since it looks easier for reading.

@antoineco Could you try this branch?

antoineco commented 2 months ago

Nice! I have a preference for the existing style because it is less distracting, but I like the new option 👍

Please be aware that Neovim's native LSP client uses LspInlayHint, not InlayHints (at least in v0.10). I searched on GitHub for /InlayHints/ language:vim but couldn't find any relevant result. Do you know if any plugin uses this highlight group? If not, should we instead use LspInlayHint?

diff --git a/colors/gruvbox-material.vim b/colors/gruvbox-material.vim
index 3bfcbfb..99d88f0 100644
--- a/colors/gruvbox-material.vim
+++ b/colors/gruvbox-material.vim
@@ -482,12 +482,12 @@ else
   call gruvbox_material#highlight('CurrentWord', s:palette.none, s:palette.none, s:configuration.current_word)
 endif
 if s:configuration.inlay_hints_background ==# 'none'
-  highlight! link InlayHints LineNr
+  highlight! link LspInlayHint LineNr
 else
   if &background ==# 'dark'
-    call gruvbox_material#highlight('InlayHints', s:palette.grey0, s:palette.bg_dim)
+    call gruvbox_material#highlight('LspInlayHint', s:palette.grey0, s:palette.bg_dim)
   else
-    call gruvbox_material#highlight('InlayHints', s:palette.grey1, s:palette.bg_dim)
+    call gruvbox_material#highlight('LspInlayHint', s:palette.grey1, s:palette.bg_dim)
   endif
 endif
 " Define a color for each LSP item kind to create highlights for nvim-cmp, aerial.nvim, nvim-navic and coc.nvim
@@ -814,7 +814,7 @@ highlight! link CocPumMenu Pmenu
 highlight! link CocMenuSel PmenuSel
 highlight! link CocDisabled Grey
 highlight! link CocSnippetVisual DiffAdd
-highlight! link CocInlayHint InlayHints
+highlight! link CocInlayHint LspInlayHint
 highlight! link CocNotificationProgress Green
 highlight! link CocNotificationButton PmenuSel
 highlight! link CocSemClass TSType
@@ -875,8 +875,8 @@ highlight! link LspWarningHighlight WarningText
 highlight! link LspInformationHighlight InfoText
 highlight! link LspHintHighlight HintText
 highlight! link lspReference CurrentWord
-highlight! link lspInlayHintsType InlayHints
-highlight! link lspInlayHintsParameter InlayHints
+highlight! link lspInlayHintsType LspInlayHint
+highlight! link lspInlayHintsParameter LspInlayHint
 highlight! link LspSemanticType TSType
 highlight! link LspSemanticClass TSType
 highlight! link LspSemanticEnum TSType
@@ -905,7 +905,7 @@ highlight! link YcmErrorLine ErrorLine
 highlight! link YcmWarningLine WarningLine
 highlight! link YcmErrorSection ErrorText
 highlight! link YcmWarningSection WarningText
-highlight! link YcmInlayHint InlayHints
+highlight! link YcmInlayHint LspInlayHint
 highlight! link YcmErrorText VirtualTextError
 highlight! link YcmWarningText VirtualTextWarning
 if !has('nvim') && has('textprop') && !exists('g:YCM_HIGHLIGHT_GROUP')
sainnhe commented 2 months ago

InlayHints is a predefined highlight group. I've linked LspInlayHint to this highlight group in the latest commit.

Could you try this in neovim's built-in lsp client?

antoineco commented 2 months ago

It works now in Neovim 👍

InlayHints is a predefined highlight group.

That's also what I thought but it doesn't seem to be the case. InlayHints is neither predefined in Neovim nor in Vim 9:

# :verbose hi InlayHints
E411: Highlight group not found: InlayHints

I also see no reference to it in the source code of Vim: https://github.com/search?q=repo%3Avim%2Fvim+%2FInlayHints%2F&type=code

sainnhe commented 2 months ago

It works now in Neovim 👍

InlayHints is a predefined highlight group.

That's also what I thought but it doesn't seem to be the case. InlayHints is neither predefined in Neovim nor in Vim 9:

# :verbose hi InlayHints
E411: Highlight group not found: InlayHints

I also see no reference to it in the source code of Vim: https://github.com/search?q=repo%3Avim%2Fvim+%2FInlayHints%2F&type=code

I mean InlayHints is a custom predefined highlight group like Green, Red and CurrentWord. I defined this highlight group just for cleaner code structure.

IMO directly using LspInlayHint and linking other hi groups to it is not suitable, because Lsp* hi groups are neovim-only, and are defined in a if block.

https://github.com/sainnhe/gruvbox-material/blob/8f504421acd991b786ae6796176a1c5878221052/colors/gruvbox-material.vim#L256-L309

So I defined InlayHints and link all other hi groups to it, including LspInlayHints.

antoineco commented 2 months ago

Oh, you are correct. Thanks for the explanation! LGTM

sainnhe commented 2 months ago

OK. I'm going to merge it.