lukas-reineke / indent-blankline.nvim

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

incorrect highlight when type a bracket in the last line of a function #823

Closed aklk1ng closed 8 months ago

aklk1ng commented 8 months ago

Problem

when i type a bracket in the last line of a function, an incorrect highlight happened. before: swappy-20240107_195715 after: swappy-20240107_195726

Steps to reproduce

config file:

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 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, 'IblIndent', { fg = '#d39aaa' })
        vim.api.nvim_set_hl(0, 'IblScope', { fg = '#4f575e' })
      end)

      hooks.register(hooks.type.SCOPE_HIGHLIGHT, hooks.builtin.scope_highlight_from_extmark)
      require('ibl').setup({})
    end,
  },
  -- uncomment this if the problem is related to scope
  {
    'nvim-treesitter/nvim-treesitter',
    build = ':TSUpdate',
    config = function()
      require('nvim-treesitter.configs').setup({
        highlight = { enable = true },
        ensure_installed = { 'cpp' }, -- change this to the language you use
      })
    end,
  },
}, { root = '/tmp/lazy', lockfile = '/tmp/lazy/lazy-lock.json' })

test file:

void solve() {

}

int main() {
  printf("hello world");

  return 0;
}

steps: 1.nvim -u minimal.lua test.cpp 2.just type a bracket in the last line of the solve function

Expected behavior

highlight group: swappy-20240107_200330

when i type a bracket the highlight group of main function is IblScope,but it should be IblIndent

Neovim version (nvim -v)

v0.10.0-dev-2047+g8df374237

Danielkonge commented 8 months ago

This highlighting problem seems to come from the way treesitter parses the code in your example when there is a missing } at that spot. I am not sure if ibl can do anything about this, since the scope highlighting depends on treesitter's parsing of the text. (#805 might make this slightly better by picking a different scope, but it won't fix the problem with the parsing.)

lukas-reineke commented 8 months ago

Yeah this is an issue in the treesitter parser. Nothing I can do to fix it, sorry.