Skip to content

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

@aklk1ng

Description

@aklk1ng

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

Activity

Danielkonge

Danielkonge commented on Jan 7, 2024

@Danielkonge
Contributor

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

lukas-reineke commented on Jan 8, 2024

@lukas-reineke
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Danielkonge@lukas-reineke@aklk1ng

        Issue actions

          incorrect highlight when type a bracket in the last line of a function · Issue #823 · lukas-reineke/indent-blankline.nvim