catppuccin / nvim

🍨 Soothing pastel theme for (Neo)vim
MIT License
5.57k stars 251 forks source link

Bad highlighting in .gitignore files using tree-sitter #734

Closed ValdezFOmar closed 3 months ago

ValdezFOmar commented 3 months ago

Description

A recent commit in nvim-treesitter change the highlighting for wildcards and characters in .gitignore. The new captures link to the same Special group in catppuccin, which makes wildcards hard to distinguish:

image

Neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1720049189

Terminal and multiplexer

kitty 0.35.2

Catppuccin version / branch / rev

main

Steps to reproduce

  1. nvim -u repro.lua
  2. open a .gitignore file

Example .gitignore:

path/to/file

*.extension

dir/**file.*

a/*jj/c/d**g

/abc??ghjk

Expected behavior

Wildcards should stand out from the file/directory names.

Actual behavior

Almost everything is the same color and makes it hard to read.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "catppuccin/nvim",
    {
        "nvim-treesitter/nvim-treesitter",
        lazy = false,
        config = function()
            require("nvim-treesitter.configs").setup {
                ensure_installed = { 'gitignore' },
                highlight = { enable = true },
            }
        end
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here
vollowx commented 3 months ago

After searching among this and other colorschemes, I'm sure that this appearance is caused by:

And it's common to link the special character like this.

Could you please provide a "expected behavior" image, so that we can decide what/how to change, as changing any of them may break some other user interface.

ValdezFOmar commented 3 months ago

This is how it looks using traditional vim regex highlighting, making the glob patterns stand out:

image

Couldn't this be solved by linking any of the specific captures @character.special.gitignore or @string.special.path.gitignore to something different?

vollowx commented 3 months ago

It can, but changing that might also affect the UI in some other places. This should be with further consideration I guess

ValdezFOmar commented 3 months ago

According to neovim documentation this is the intended way:

As an additional rule, capture highlights can always be specialized by language, by appending the language name after an additional dot. For instance, to highlight comments differently per language:

hi @comment.c guifg=Blue
hi @comment.lua guifg=DarkBlue
hi link @comment.documentation.java String  
vollowx commented 3 months ago

Ah, I just found that I misread your advice here 😉

Couldn't this be solved by linking any of the specific captures @character.special.gitignore or @string.special.path.gitignore to something different?

This seems to be a acceptable solution, though I'm not sure if this should be implemented on upstream (nvim-treesitter) or we write custom queries in this repo.

ValdezFOmar commented 3 months ago

I don't think this is an upstream issue, nvim-treesitter only provides the queries, its the colorscheme responsibility to give them a useful color. I don't think queries are necessary either, just doing something like ["@string.special.path.gitignore"] = { whatever } would be enough.