Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff view is missing syntax highlighting #105

Closed
ojurkiewicz opened this issue Mar 6, 2022 · 8 comments
Closed

Diff view is missing syntax highlighting #105

ojurkiewicz opened this issue Mar 6, 2022 · 8 comments

Comments

@ojurkiewicz
Copy link

Screenshot 2022-03-06 at 22 33 13

Hey, just as the title and attached screenshot show. I am using the "sindrets/diffview.nvim" plugin and reviewing changes is currently very unreadable in my opinion. An example of how it might look below. I have no experience with configuring colorschemes but if someone would like to guide me which properties are responsible for this diffview I can try to fix it and open a PR. If there is no desire to change it in this project, I will at least overwrite it in my private init.lua, so any help is welcome.

Thanks a lot in advance.

image

@Spuxy
Copy link

Spuxy commented Mar 24, 2022

agree this should be implemented 👍🏿

@ellisonleao
Copy link
Owner

hey @ojurkiewicz thanks for the issue! I will be checking the highlights used in that plugin and see how can we improve this one.

@ellisonleao
Copy link
Owner

hey @ojurkiewicz i just pushed a new breaking change, and in the diffview tests i could see on my side that the colors were correct. Can you please pull latest, read the new README and check if it's working properly please?

@ojurkiewicz
Copy link
Author

ojurkiewicz commented Jul 4, 2022

pc
hl

I've updated all plugins with Packer, restarted Neovim and it does not seem to make any difference

Edit: Seems like you've asked about versions and config but removed. I'll answer anyway. Neovim 0.7. I've minimized config to what you can see below and I don't see any additional highlighting.

local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.fn.execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
end

vim.api.nvim_exec(
  [[
  augroup Packer
    autocmd!
    autocmd BufWritePost init.lua PackerCompile
  augroup end
]],
  false
)


local use = require('packer').use
require('packer').startup(function()
  use 'ellisonleao/gruvbox.nvim'
  use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' }
end)


--Set colorscheme (order is important here)
vim.o.termguicolors = true
vim.o.background = "dark" -- or "light" for light mode
vim.cmd([[colorscheme gruvbox]])
vim.cmd([[highlight normal guibg=#000000]])

-- Diffview config
local cb = require'diffview.config'.diffview_callback

require('diffview').setup()

@ellisonleao
Copy link
Owner

ellisonleao commented Jul 6, 2022

I've checked the original plugins and it seems this is a problem in the original version as well. Unfortunately, I don't have an immediate solution for this because that will require changing the main colors for the Diff* highlight groups. If you are uncomfortable with the current colors you can override them with the new override system:

require('gruvbox').setup({
  overrides = {
    DiffChange = {bg="#rgbcolor", fg="#rgbcolor", ...},
    DiffAdd = {bg="#rgbcolor", fg="#rgbcolor", ...},
    DiffDelete = {bg="#rgbcolor", fg="#rgbcolor", ...},
    DiffText = {bg="#rgbcolor", fg="#rgbcolor", ...},
  }
})
vim.cmd([[colorscheme gruvbox]])

@timsofteng
Copy link

I've faced up with same issue...

@thallada
Copy link
Contributor

thallada commented Mar 23, 2023

I tried overriding the gruvbox Diff highlights with the overrides config setting but it doesn't seem to clear out existing styles set to the highlight group, so I'm unable to clear out the foreground colors with that config. I fixed it by using vim.api.nvim_set_hl myself outside the config.

I created a new file in ~/.config/nvim/after/plugin/gruvbox.lua (to make sure it runs after gruvbox config completes):

local colors = require("gruvbox.palette").colors;

function FixGruvbox()
  vim.api.nvim_set_hl(0, 'DiffviewDiffAddAsDelete', { bg = "#431313" })
  vim.api.nvim_set_hl(0, 'DiffDelete', { bg = "none", fg = colors.dark2 })
  vim.api.nvim_set_hl(0, 'DiffviewDiffDelete', { bg = "none", fg = colors.dark2 })
  vim.api.nvim_set_hl(0, 'DiffAdd', { bg = "#142a03" })
  vim.api.nvim_set_hl(0, 'DiffChange', { bg = "#3B3307" })
  vim.api.nvim_set_hl(0, 'DiffText', { bg = "#4D520D" })
end
FixGruvbox()

vim.api.nvim_create_autocmd(
  "ColorScheme",
    { pattern = { "gruvbox" }, callback = FixGruvbox }
)

These colors were picked by me based on what I think looked nice and was gruvbox-y enough (all existing palette colors were too bright to use as background colors). I have also overrode my background color to be darker (#131516), so your mileage may vary.

The autocmd ensures the fix is applied again after switching to a different theme with the :colorscheme command and then switching back to gruvbox.

Note the enhanced_diff_hl = true option needs to be set in the diffview setup config so that you get red backgrounds in the left pane. I also have the special diff fillchars option set as mentioned in the README.

Example:
Screen Shot 2023-03-22 at 11 14 56 PM

thallada added a commit to thallada/neovim-config that referenced this issue Mar 23, 2023
@timsofteng
Copy link

@thallada cool!
May you contribute it into gruvbox.nvim please?

thallada added a commit to thallada/neovim-config that referenced this issue Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants