bug: Missing highlight groups for diff files?
wahyuwiyoko opened this issue · 3 comments
Neovim version (nvim -v)
NVIM v0.9.4
Terminal
Alacritty
Describe the bug
I often do git add --patch
for editing diff files. I don't see any highlighted line for added and deleted line on the diff files.
I have latest version of Rose Pine and Treesitter with diff
module installed and highlight
option enabled.
Example diff file:
Steps To Reproduce
After comparing with Catppuccin theme, I found some missing highlight groups after inspecting with Treesitter on Rose Pine. Here is a few that I found on Catppuccin that Rose Pine doesn't have:
@attribute.diff
links to Constant@text.diff.add
links to diffAdded@text.diff.delete
links to diffRemoved
So to solve my problem is to add those highlight groups on my Rose Pine setup:
require("rose-pine").setup({
highlight_groups = {
["@attribute.diff"] = { fg = "gold" },
["@text.diff.add"] = { bg = "foam", blend = 20 },
["@text.diff.delete"] = { bg = "love", blend = 20 }
}
})
Here is my Neovim configuration for more details:
Expected Behavior
After adding the missing highlight groups:
I also checked the theme source doesn't have those three highlight groups or maybe I missed something?
Repro
vim.o.packpath = "/tmp/nvim/site"
local plugins = {
rose_pine = "https://github.com/rose-pine/neovim",
treesitter = "https://github.com/nvim-treesitter/nvim-treesitter"
}
for name, url in pairs(plugins) do
local install_path = "/tmp/nvim/site/pack/test/start/" .. name
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
end
end
require("rose-pine").setup({
variant = "main",
highlight_groups = {
["@attribute.diff"] = { fg = "gold" },
["@text.diff.add"] = { bg = "foam", blend = 20 },
["@text.diff.delete"] = { bg = "love", blend = 20 }
}
})
require("nvim-treesitter.configs").setup({
ensure_installed = { "query", "regex", "diff", "comment" },
highlight = { enable = true },
indent = { enable = true }
})
vim.cmd("colorscheme rose-pine")
Thank you for providing screenshots and a reproduction, that is much appreciated! Apologies for the delay but I will add these soon—part of a larger refactor.
Looks like the proposed changes also effect markdown diff code blocks which is quite nice. The contrast, however, is quite low. I'm curious if there are any cases where diff views also use syntax highlighting or if it would be okay to add a foreground to @text.diff.{add,delete}
.
Happy to hear other's preferences. I'm personally leaning towards option 2.
I also choose the second option, matching colorful foreground looks nice. I think GitHub's markdown diff highlight also use the same thing:
let foo = true
- foo = "bar"
+ foo = false
If anyone curious how to set the second option in highlight groups:
require("rose-pine").setup({
highlight_groups = {
["@text.diff.add"] = { fg = "foam", bg = "foam", blend = 20 },
["@text.diff.delete"] = { fg = "love", bg = "love", blend = 20 }
}
})
And also the third option looks nice for brighter text:
require("rose-pine").setup({
highlight_groups = {
["@text.diff.add"] = { fg = "text", bg = "foam", blend = 20 },
["@text.diff.delete"] = { fg = "text", bg = "love", blend = 20 }
}
})
Or without the background color:
require("rose-pine").setup({
highlight_groups = {
["@text.diff.add"] = { fg = "foam" },
["@text.diff.delete"] = { fg = "love" }
}
})