lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
3.95k stars 97 forks source link

Weird highlighting regarding scopes (lua) #893

Open hersi97 opened 1 month ago

hersi97 commented 1 month ago

Problem

Hi! I'm sorry if this is intended behavior, but I figured I should ask.

If I have my cursor under a function scope, I don't get highlights for the scope, however if I have the cursor under a block under the function scope (if block, for block, function block), I do get highlights.

Interestingly the show_start and show_end underlining does not have this problem.

image image (Notice the 3rd indent highlight)

Steps to reproduce

-- min-init.lua
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({
  {
    "lukas-reineke/indent-blankline.nvim",
    config = function()
      local highlight = {
        "IndentLight1",
        "IndentLight2",
        "IndentLight3",
        "IndentBase1",
        "IndentBase2",
        "IndentBase3",
        "IndentDark1",
        "IndentDark2",
        "IndentDark3",
        "IndentDarker1",
        "IndentDarker2",
        "IndentDarker3",
      }

      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, "IndentLight1", { fg = "#AFC8FF" })
        vim.api.nvim_set_hl(0, "IndentLight2", { fg = "#C2B0FF" })
        vim.api.nvim_set_hl(0, "IndentLight3", { fg = "#A6FFFC" })
        vim.api.nvim_set_hl(0, "IndentBase1", { fg = "#82AAFF" })
        vim.api.nvim_set_hl(0, "IndentBase2", { fg = "#A084FF" })
        vim.api.nvim_set_hl(0, "IndentBase3", { fg = "#74FFFA" })
        vim.api.nvim_set_hl(0, "IndentDark1", { fg = "#527FDF" })
        vim.api.nvim_set_hl(0, "IndentDark2", { fg = "#7555E1" })
        vim.api.nvim_set_hl(0, "IndentDark3", { fg = "#40D9D4" })
        vim.api.nvim_set_hl(0, "IndentDarker1", { fg = "#2F5FC3" })
        vim.api.nvim_set_hl(0, "IndentDarker2", { fg = "#5433C7" })
        vim.api.nvim_set_hl(0, "IndentDarker3", { fg = "#1DB9B3" })
      end)

      require("ibl").setup({
        indent = {
          char = "│",
          tab_char = "│",
          highlight = highlight,
        },
        scope = {
          show_start = true,
          show_end = true,
          highlight = highlight,
        },
      })
    end,
  },
  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
      require("nvim-treesitter.configs").setup({
        ensure_installed = { "lua" }, -- change this to the language you use
      })
    end,
  },
}, { root = "/tmp/lazy" })

image image image

Expected behavior

I expect the indent line highlight to be active while the cursor is anywhere under the scope.

Neovim version (nvim -v)

NVIM v0.10.0

lukas-reineke commented 4 weeks ago

I'm not sure I understand your problem. In the first screenshot, you are in the opts function scope, and that is highlighted correctly.
In the second screenshot, you are in the hooks.register function scope, and that is highlighted correctly too.

Everything looks correct.

hersi97 commented 3 weeks ago

Alright, yes, the highlights are correct. I was confused, since I didn't know it would highlight the current scope with the first highlight color in the config. I played around with it a bit and it's clear now, thanks!

Slight off-topic question, is there a way to tell ibl to highlight the current scope with a different color than the first one set in config.indent.highlight?

lukas-reineke commented 3 weeks ago

Ah I understand your problem now. Setting a list of highlights for scope is currently broken #860.
You can still set a different color from the normal highlights though.