lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.07k stars 102 forks source link

rainbow-delimiters.nvim integration is broken since 3.4.0 #811

Closed tan-wei closed 8 months ago

tan-wei commented 8 months ago

Problem

rainbow-delimiters.nvim integration is broken since 3.4.0, and I can confirm it is OK with 3.3.12 and before.

Since 3.4.0, the color for indent line is always the first color instead of rainbow colors.

Steps to reproduce

Use example configuration in Readme.md:

local highlight = {
    "RainbowRed",
    "RainbowYellow",
    "RainbowBlue",
    "RainbowOrange",
    "RainbowGreen",
    "RainbowViolet",
    "RainbowCyan",
}
local hooks = require "ibl.hooks"
-- create the highlight groups in the highlight setup hook, so they are reset
-- every time the colorscheme changes
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
    vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
    vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
    vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
    vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
    vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
    vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
    vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)

vim.g.rainbow_delimiters = { highlight = highlight }
require("ibl").setup { scope = { highlight = highlight } }

hooks.register(hooks.type.SCOPE_HIGHLIGHT, hooks.builtin.scope_highlight_from_extmark)

For version 3.3.11 (and before), the rainbow indent line would be: 3 3 11-1 3 3 11-2 3 3 11-3

But since 3.4.0, it becomes (the pictures are using ibl 3.4.2): 3 4 2-1 3 4 2-2 3 4 2-3

Expected behavior

Works as version before 3.4.0.

Neovim version (nvim -v)

v0.10.0-dev-1947+gab2aad509d6

lukas-reineke commented 8 months ago

Using this minimal init.lua, I can't reproduce the problem. Can you check if anything in your config might conflict?

The hook for scope highlight from extmark changed in #802, but I can't immediately see what could make the new one fail if the old one works.

local lazypath = "/tmp/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }
end
vim.opt.rtp:prepend(lazypath)
vim.opt.termguicolors = true

require("lazy").setup ({
    {
        "hiphish/rainbow-delimiters.nvim"
    },
    {
        "lukas-reineke/indent-blankline.nvim",
        main = "ibl",
        config = function()
            local highlight = {
                "RainbowRed",
                "RainbowYellow",
                "RainbowBlue",
                "RainbowOrange",
                "RainbowGreen",
                "RainbowViolet",
                "RainbowCyan",
            }
            local hooks = require "ibl.hooks"
            -- create the highlight groups in the highlight setup hook, so they are reset
            -- every time the colorscheme changes
            hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
                vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
                vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
                vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
                vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
                vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
                vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
                vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
            end)

            vim.g.rainbow_delimiters = { highlight = highlight }
            require("ibl").setup { scope = { highlight = highlight } }

            hooks.register(hooks.type.SCOPE_HIGHLIGHT, hooks.builtin.scope_highlight_from_extmark)
        end
    },
    -- uncomment this if the problem is related to scope
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        config = function()
            require("nvim-treesitter.configs").setup {
                ensure_installed = { "rust" }, -- change this to the language you use
            }
        end,
    },
}, { root = "/tmp/lazy" })
tan-wei commented 8 months ago

Hmm. With the minimal init.lua, I can't reproduce the problem, either.

So it must be my own problem in my configuration. I'll try to find the confilict.

tan-wei commented 8 months ago

I think I find the method how to make it work. Both of them should be applied at the same time:

  1. Disable lazy loading for ibl. Before changed, I use event = "VeryLazy" to make it lazy load (update: Changed it into BufEnter just the same with rainbow-delimiters.nvim is OK, does it mean rainbow-delimiters.nvim may conflict with ibl?)
  2. set vim.g.rainbow_delimiters like the minimal init.lua in config file. Before changed, I set it in init function, which is set before config function is called

But I can't find why these steps work.

tan-wei commented 8 months ago

The issue should be closed. Thanks @lukas-reineke .

lukas-reineke commented 8 months ago

If you lazy load ibl after rainbow delimiters, and you create the highlight groups inside the ibl setup, rainbow delimiters will not have any highlighting set when it initializes. It falls back to the default, and the highlights won't match that of ibl.

You need to either, create the highlight groups first, before you load any plugins, or keep it as you have now, but load rainbow delimiters after ibl.

tan-wei commented 8 months ago

Got it. Lazy load could cause some issues like this. Thanks for your reply.