marko-cerovac / material.nvim

:trident: Material colorscheme for NeoVim written in Lua with built-in support for native LSP, TreeSitter and many more plugins
GNU General Public License v2.0
1k stars 131 forks source link

Treesitter @variable.field color changed after rewrite #136

Closed okuuva closed 2 years ago

okuuva commented 2 years ago

It used to be the same color as "@variable" (like "colors" and "material" in the sample pic) but now it defaults to the same color as comments: image

Would be very nice to be able to define "@treesitter.object" style highlights in custom_highlights but that's a whole another thing.

marko-cerovac commented 2 years ago

Since a recent update to treesitter and neovim, you can define @treesitter.object style highlights. You can change @field to return it to the original version.

okuuva commented 2 years ago

Since a recent update to treesitter and neovim, you can define @treesitter.object style highlights. You can change @field to return it to the original version.

Could you give an example? I tried setting ["@field"] = { fg = colors.main.green }, in the custom_highlights (don't want it really to be green but just to see the difference) but it doesn't seem to be working. Also tried ["@variable"] and ["@variable.field"] with no success. All the other custom_highlights are working.

marko-cerovac commented 2 years ago

This was added in neovim 0.8.0, so I you need the nightly build. Also, your treesitter needs to be updated to the latest version. If you try TSField = { fg = colors.main.green }, and it works, that means that you need newer versions of neovim or the treesitter plugin.

okuuva commented 2 years ago

This was added in neovim 0.8.0, so I you need the nightly build. Also, your treesitter needs to be updated to the latest version. If you try TSField = { fg = colors.main.green }, and it works, that means that you need newer versions of neovim or the treesitter plugin.

I am running neovim 0.8.0 and latest (0.20.7) tree-sitter:

❯ nvim --version
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

❯ brew info tree-sitter
==> tree-sitter: stable 0.20.7 (bottled), HEAD
Parser generator tool and incremental parsing library

And TSField = { fg = colors.main.green } isn't working either.

okuuva commented 2 years ago

Confusion intensifies. Some of the new style TS highlight groups work, others don't:

image

As you can see from e.g. vim variable on the very last line, the ["@variable"] = { fg = colors.main.green }, works just fine. But the rest of them don't. nil under the cursor should be green but it isn't. Same goes for WinSeparator et al. Which are oddly enough both @variable and @field but still not affected by neither custom highlight groups:

image

marko-cerovac commented 2 years ago

That's weird. ["@constant.builtin"] = { fg = colors.main.green } works just fine for me and makes the nil value green. As far as some treesitter highlights using the new @name group, and some using the old TSName group, I believe that that's an upstream issue with treesitter. Is your treesitter updated to the latest version?

okuuva commented 2 years ago

I don't think it's some TS highlights using the new group and some old. I tried setting TSConstantBuiltin = { fg = colors.main.green }, and that didn't have an effect either.

Treesitter is installed from homebrew and sits at version 0.20.7. nvim-treesitter/nvim-treesitter is at latest HEAD.

I think I'll try to create a minimal config with just treesitter and material installed and see if I can repro. My best guess atm is that some other plugin is messing with the hlgroups. Would be nice to see what the hlgroup is set to and what set it...

okuuva commented 2 years ago

No luck. Some of the overrides do not work even with just packer, material and nvim-treesitter installed. Here's the config I used:

```lua local on_windows = vim.loop.os_uname().version:match("Windows") local function join_paths(...) local path_sep = on_windows and "\\" or "/" local result = table.concat({ ... }, path_sep) return result end vim.cmd([[set runtimepath=$VIMRUNTIME]]) local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp" vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site")) local package_root = join_paths(temp_dir, "nvim", "site", "pack") local install_path = join_paths(package_root, "packer", "start", "packer.nvim") local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua") local function load_plugins() require("packer").startup({ { "wbthomason/packer.nvim", -- offending plugin here "marko-cerovac/material.nvim", "nvim-treesitter/nvim-treesitter", }, config = { package_root = package_root, compile_path = compile_path, }, }) end local load_config = function() local opts = { noremap = true, silent = true } -- Shorten function name local keymap = vim.api.nvim_set_keymap vim.g.mapleader = " " vim.g.maplocalleader = " " keymap("n", "", ":wincmd h", opts) keymap("n", "", ":wincmd j", opts) keymap("n", "", ":wincmd k", opts) keymap("n", "", ":wincmd l", opts) vim.opt.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time vim.opt.number = true -- set numbered lines -- config of the offending plugin here vim.g.material_style = "darker" require("material").setup({ contrast = { terminal = false, -- Enable contrast for the built-in terminal sidebars = false, -- Enable contrast for sidebar-like windows ( for example Nvim-Tree ) floating_windows = false, -- Enable contrast for floating windows cursor_line = true, -- Enable darker background for the cursor line non_current_windows = true, -- Enable darker background for non-current windows filetypes = {}, -- Specify which filetypes get the contrasted (darker) background }, styles = { -- Give comments style such as bold, italic, underline etc. comments = { italic = true, }, strings = {}, keywords = { bold = true, italic = true, }, functions = {}, variables = {}, operators = {}, types = {}, }, plugins = { -- Uncomment the plugins that you use to highlight them -- Available plugins: "dap", -- "dashboard", "gitsigns", -- "hop", "indent-blankline", -- "lspsaga", "mini", -- "neogit", "nvim-cmp", -- "nvim-navic", "nvim-tree", -- "sneak", "telescope", "trouble", "which-key", }, disable = { colored_cursor = true, -- Disable the colored cursor borders = true, -- Disable borders between verticaly split windows background = false, -- Prevent the theme from setting the background (NeoVim then uses your terminal background) term_colors = false, -- Prevent the theme from setting terminal colors eob_lines = false, -- Hide the end-of-buffer lines }, high_visibility = { lighter = false, -- Enable higher contrast text for lighter style darker = true, -- Enable higher contrast text for darker style }, lualine_style = "default", -- Lualine style ( can be 'stealth' or 'default' ) async_loading = false, -- Load parts of the theme asyncronously for faster startup (turned on by default) custom_colors = nil, -- If you want to everride the default colors, set this to a function -- Overwrite highlights with your own custom_highlights = { -- YourHighlightGroup = { -- fg = "#SOME_COLOR", -- foreground color -- bg = "#SOME_COLOR", -- background color -- sp = "#SOME_COLOR", -- special color (for colored underlines, undercurls...) -- bold = false, -- make group bold -- italic = false, -- make group italic -- underline = false, -- make group underlined -- undercurl = false, -- make group undercurled -- underdot = false, -- make group underdotted -- underdash = false, -- make group underdotted -- striketrough = false, -- make group striked trough -- reverse = false, -- reverse the fg and bg colors -- link = "SomeOtherGroup", -- link to some other highlight group -- }, WinSeparator = { link = "VertSplit" }, ["@variable"] = { fg = "#FF00FF"}, ["@field"] = { fg = "#FF00FF"}, ["@constant.builtin"] = { fg = "#FF00FF"}, }, }) vim.cmd("colorscheme material") require("nvim-treesitter.configs").setup({ ensure_installed = "all", -- "all", or a list of languages sync_install = false, -- install languages synchronously (only applied to `ensure_installed`) ignore_install = { "" }, -- List of parsers to ignore installing autopairs = { enable = true }, autotag = { enable = true }, highlight = { enable = true, -- false will disable the whole extension disable = nil, -- list of language that will be disabled additional_vim_regex_highlighting = false, }, indent = { enable = true, disable = { "python" } }, matchup = { enable = true }, context_commentstring = { enable = true, enable_autocmd = false, }, }) end if vim.fn.isdirectory(install_path) == 0 then vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }) load_plugins() require("packer").sync() local packer_group = vim.api.nvim_create_augroup("Packer", { clear = true }) vim.api.nvim_create_autocmd( "User", { pattern = "PackerComplete", callback = load_config, group = packer_group, once = true } ) else load_plugins() require("packer").sync() load_config() end ```

And here's a screenshot from the end result: image

I also tried setting ["@boolean"] = { fg = "#FF00FF"}, and that works so it seems that the problem might lie with @group.subgroup type of hl groups.

While this is interesting it's also frustrating. I would be happy to just get the @field to the way it was.

marko-cerovac commented 2 years ago

This is really weird. I'm trying to reproduce the issue, but just can't do it. When I use

custom_highlights = {
    ["@field"] = { fg = colors.main.green },
    ["@function.builtin"] = { fg = colors.main.red }
}

everything works just fine. This could be due to another plugin, or the order in which plugins get loaded.

okuuva commented 2 years ago

I thought so too, but the minimal config I have in the previous comment doesn't load anything but packer, material and nvim-treesitter (in that order). Still setting "@field" or "@constant.builtin" doesn't work for me. Tried it with my home server running Debian and the same result (installed neovim, tree-sitter and luajit from homebrew with --HEAD) so it's not tied to OS either. There must be something simple I'm missing...

marko-cerovac commented 2 years ago

I'll look further into this. For now I have no idea what could be causing this.

okuuva commented 2 years ago

Now it works, takkâ ennuv! (Thank you very much!)