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

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

Closed
ValdezFOmar opened this issue Jul 20, 2024 · 6 comments · Fixed by #736
Closed

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

ValdezFOmar opened this issue Jul 20, 2024 · 6 comments · Fixed by #736
Labels
bug Something isn't working

Comments

@ValdezFOmar
Copy link
Contributor

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
@ValdezFOmar ValdezFOmar added the bug Something isn't working label Jul 20, 2024
@vollowx
Copy link
Collaborator

vollowx commented Jul 23, 2024

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

  • @character.special => SpecialCharacter => Special
  • @string.special.path => Special

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
Copy link
Contributor Author

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
Copy link
Collaborator

vollowx commented Jul 24, 2024

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

@ValdezFOmar
Copy link
Contributor Author

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
Copy link
Collaborator

vollowx commented Jul 24, 2024

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
Copy link
Contributor Author

ValdezFOmar commented Jul 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants