sainnhe / gruvbox-material

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

Colors of diagnostic signs are off in Lualine #145

Closed brxxlstxrs closed 2 years ago

brxxlstxrs commented 2 years ago

I have done the following steps before reporting this issue:

Operating system/version

Arch Linux x86_64

Terminal emulator/version

alacritty 0.10.1

$TERM environment variable

alacritty

Tmux version

No response

Feature matrix


null-ls: require("null-ls.health").check()
========================================================================
  - OK: flake8: the command "flake8" is executable.
  - OK: autopep8: the command "autopep8" is executable.
  - OK: stylua: the command "stylua" is executable.

nvim: health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: RelWithDebInfo

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $COLORTERM='truecolor'

nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
  - OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v18.8.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 12.2.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - python         ✓ ✓ ✓ ✓ ✓
  - cpp            ✓ ✓ ✓ ✓ ✓
  - c              ✓ ✓ ✓ ✓ ✓
  - lua            ✓ ✓ ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

provider: health#provider#check
========================================================================
## Clipboard (optional)
  - WARNING: No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.
    - ADVICE:
      - :help |clipboard|

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "/usr/bin/python"
  - INFO: Executable: /usr/bin/python
  - INFO: Python version: 3.10.6
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - OK: no $VIRTUAL_ENV

## Ruby provider (optional)
  - WARNING: `ruby` and `gem` must be in $PATH.
    - ADVICE:
      - Install Ruby and verify that `ruby` and `gem` commands work.

## Node.js provider (optional)
  - INFO: Node.js: v18.8.0
  - WARNING: Missing "neovim" npm (or yarn, pnpm) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim
      - Run in shell (if you use pnpm): pnpm install -g neovim
      - You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim

## Perl provider (optional)
  - WARNING: "Neovim::Ext" cpan module is not installed
    - ADVICE:
      - See :help |provider-perl| for more information.
      - You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim

vim.lsp: require("vim.lsp.health").check()
========================================================================
  - INFO: LSP log level : WARN
  - INFO: Log path: /home/misha/.local/state/nvim/lsp.log
  - INFO: Log size: 108 KB

vim.treesitter: require("vim.treesitter.health").check()
========================================================================
  - INFO: Runtime ABI version : 14
  - OK: Loaded parser for cpp: ABI version 13
  - OK: Loaded parser for lua: ABI version 13
  - OK: Loaded parser for python: ABI version 13
  - OK: Loaded parser for c: ABI version 13

Minimal vimrc that can reproduce this bug.

-- minimal.lua
require('impatient')

require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  use 'lewis6991/impatient.nvim'
  use 'neovim/nvim-lspconfig'
  use 'sainnhe/gruvbox-material'
end)

require'lualine'.setup {
  options = {
    theme = 'gruvbox-material'
  }
}
require('lspconfig')['pyright'].setup()

vim.cmd [[let g:gruvbox_material_better_performance = 1]]
vim.cmd [[let g:gruvbox_material_foreground = 'mix']]
vim cmd [[let g:gruvbox_material_disable_italic_comment = 1]]
vim.cmd [[let g:gruvbox_material_diagnostic_text_highlight = 1]]
vim.cmd [[let g:gruvbox_material_diagnostic_virtual_text = 'colored']]
vim.cmd [[colorscheme gruvbox-material]]

Steps to reproduce this bug using minimal vimrc

  1. Repeat steps 1-4 of the manual from :help gruvbox-material.txt and step to install for lualine (7)
  2. Install lsp server(s) (in example pyright)
  3. Run nvim with minimal.lua config, do :PackerSync and reload nvim
  4. Do situation to see diagnostics like:
    def hello(name):  # name is unused diagnostics
    pass
  5. See DARK BLUE

Expected behavior

Same lsp diagnostics colors in lualine as in code

Actual behavior

Dark blue colors

brxxlstxrs commented 2 years ago

IMG_20220909_171617

antoineco commented 2 years ago

Does :verbose highlight DiagnosticHint show the same color?

If yes, what's its value?

brxxlstxrs commented 2 years ago

Does :verbose highlight DiagnosticHint show the same color?

If yes, what's its value?

:verbose highlight DiagnosticHint

DiagnosticHint xxx ctermfg=7 guifg=LightGrey
                   links to HintText
        Last set from ~/.config/nvim/colors/gruvbox-material.vim line 246

As I said before: I copy colors/gruvbox-material.vim ( 7. To install lualine theme, copy /path/to/gruvbox-material/lua/lualine/themes/gruvbox-material.lua to ~/.config/nvim/lua/lualine/themes/ .) In neovim colors dir is .config/nvim/colors And I follow 1-4 steps too

antoineco commented 2 years ago

I think the color you're seeing is #273faf, which is Lualine's fallback when it cannot find any of the DiagnosticHint, LspDiagnosticsDefaultHint or DiffChange highlight groups.

Gruvbox-material definitely sets these highlight groups, so to me this looks like an issue with the order things are loaded.

Try adding packadd! gruvbox-material and coloscheme gruvbox-material to your Neovim init file, not by typing commands manually. This will ensure that the color scheme is loaded before the plugins.

Loading the color scheme manually is also possible, but then you need to initialize all the plugins which depend on it again, also manually, like this:

:lua require'lualine'.setup({options = {theme = 'gruvbox-material'}})
brxxlstxrs commented 2 years ago

I think the color you're seeing is #273faf, which is Lualine's fallback when it cannot find any of the DiagnosticHint, LspDiagnosticsDefaultHint or DiffChange highlight groups.

Gruvbox-material definitely sets these highlight groups, so to me this looks like an issue with the order things are loaded.

Try adding packadd! gruvbox-material and coloscheme gruvbox-material to your Neovim init file, not by typing commands manually. This will ensure that the color scheme is loaded before the plugins.

Loading the color scheme manually is also possible, but then you need to initialize all the plugins which depend on it again, also manually.

Already done all of it and its not working for me. And why its happening after I copy /path/to/gruvbox-material/lua/lualine/themes/gruvbox-material.lua to ~/.config/nvim/lua/lualine/themes/

antoineco commented 2 years ago

What happens if you execute this manually after starting Neovim?

:lua require'lualine'.setup({options = {theme = 'gruvbox-material'}})
brxxlstxrs commented 2 years ago

IMG_20220909_204432

brxxlstxrs commented 2 years ago

Its very strange, because if focus on the code, then in the colors folder of the repository, the values of (Diagnostic)*Hint* contain links to TextHint (its green)

antoineco commented 2 years ago

Confirmed. I'm observing the same behaviour. Thanks for reporting!

image

The good news is: I found the root cause.

Problem

Gruvbox-material doesn't set any foreground color for HintText, InfoText, WarnText and ErrorText. Instead, it uses the undercurl highlight style, as shown below:

image

As a result, lualine assumes those groups don't have any color, and falls back to its default values of #273faf, #ffffff, #ffa500 and #e32636.

Now, if I apply a foreground color to HintText and reload lualine, the bulb icon and the number turn green as expected:

:highlight HintText guifg=#a9b665
:lua require'lualine'.setup{options = { theme = 'gruvbox-material' }}
image

Possible workaround

This is going to be slightly problematic because I don't think we want to touch the current style of the highlight groups used by default by lualine: DiagnosticHint, DiagnosticInfo, DiagnosticWarn and DiagnosticError.

However, it is possible to configure lualine to use specific colors from the gruvbox-material palette:

local palette = vim.fn['gruvbox_material#get_palette']('medium', 'material', {[vim.type_idx]=vim.types.dictionary})

require'lualine'.setup{
  options = {
    theme = 'gruvbox-material',
    diagnostics_color = {
      hint  = { fg = palette['green'][1]  },
      info  = { fg = palette['blue'][1]   },
      warn  = { fg = palette['yellow'][1] },
      error = { fg = palette['red'][1]    },
    }
  }
}

Result:

image

It doesn't feel ideal, but considering lualine's default behaviour, I think this is the most reasonable approach.

brxxlstxrs commented 2 years ago

Thanks, now I set it to me, but with 'mix' colors.(I'm not sure why the problem still exists, why no one noticed it, because a lot of people probably use all these plugins along with this theme, but I'm not sure, because it's more focused on vim syntax and not lua, not very much use lualine)

and also does this plugin have bufferline.nvim support?

antoineco commented 2 years ago

I also wonder why. I personally don't use Lualine because the way it refreshes on a timer used to cause a bunch of issues for me, and I know that the Neovim ecosystem has so many alternatives that it's hard to support every use case: feline, heirline, mini, NvChad, ...

Since Lualine is popular, maybe I could send them a pull request to suggest falling back to the underline color if no foreground color was defined. The maintainers will most likely tell me it's too opinionated, but it's worth a try.

Meanwhile, I added a note about this behaviour to the FAQ 👇

antoineco commented 2 years ago

@brxxlstxrs to your other question, bufferline is supported, but it might need some tweaking to make it look even nicer. In case you find some possible improvements, feel free to suggest them in a new issue.

antoineco commented 2 years ago

@brxxlstxrs FYI my patch was accepted in Lualine (much faster than I anticipated; https://github.com/nvim-lualine/lualine.nvim/pull/836), so if you update to the latest version, the underline color of the Diagnostic highlight groups will be used if they exist. This means you don't need to set diagnostics_color manually anymore inside Lualine's configuration. Things will just work out of the box with Gruvbox Material.