shellRaining / hlchunk.nvim

This is the lua implementation of nvim-hlchunk, you can use this neovim plugin to highlight your indent line and the current chunk (context) your cursor stayed
MIT License
628 stars 31 forks source link

Chunk highlight the whole first indent of a buffer #113

Closed soifou closed 3 months ago

soifou commented 3 months ago

Describe the bug This is a bug and by extend a proposal feature.

With chunk enabled when you jump into a buffer with some content, whatever allowed filetype, that lead to the first line, the first indent is then highlighted in the whole buffer. This happen only in this case. If you move your cursor everything gets correctly "init".

To Reproduce Steps to reproduce the behavior:

  1. nvim README.md +1
  2. First indent highlighted in the whole buffer

Expected behavior Chunk should be correctly initialized

Screenshots image image

Additional context Additionally, it could be nice to have an option to disable the first level of indent, like indent-blankline.nvim already does. This seems to be frequently asked in this kind of plugin like here or there

Personally I often feel this pointless when browsing code and add unnecessary visual clutter.

What do you think? Is this something fairly easy to implement?

shellRaining commented 3 months ago

I will take a look at this bug.

As for the second feat request, yes, This is relatively easy to implement, but I am thinking about how to provide it in a certain way.

because indent first get render info (such as lnum, col, virt_text, style, indent level...), so we can call a filter function on this table, such as

vim.tbl_filter(function (v)
  return v.level ~= 1
end, render_info)

I will rethink and write a demo in next version, for now I'm dealing with the perf of indent.

shellRaining commented 3 months ago

sorry but I can't reproduce this bug, can you provide more details.

and the feat you mentioned has been achieved. The effect is as follows

without_first_level

after refactor I will publish and upload

soifou commented 3 months ago

Very nice! Would you mind to disable the chunk effect as well on the first indent? If the user want to disable the first indent on indent module, he might want to do the same for the chunk module.

Here is the repro, this clearly has something to do using lazy-load on specific event like BufEnter, UIEnter or ColorScheme. I should have mentioned it, sorry!

nvim -nu repro.lua README.md +1
  local root = vim.fn.fnamemodify('./.repro', ':p')

  for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
      vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
  end

  local lazypath = root .. '/plugins/lazy.nvim'
  if not vim.uv.fs_stat(lazypath) then
      vim.fn.system({
          'git',
          'clone',
          '--filter=blob:none',
          '--single-branch',
          'https://github.com/folke/lazy.nvim.git',
          lazypath,
      })
  end
  vim.opt.runtimepath:prepend(lazypath)

  local plugins = {
      {
          'shellRaining/hlchunk.nvim',
          event = 'BufEnter', -- or UIEnter, ColorScheme
          lazy = true,
          opts = {
              chunk = {
                  enable = true,
              },
          },
      },
  }
  require('lazy').setup(plugins, {
      root = root .. '/plugins',
  })

  vim.opt.termguicolors = true
shellRaining commented 3 months ago

very thanks for your detailed report, I have fixed this in latest commit

shellRaining commented 3 months ago

Very nice! Would you mind to disable the chunk effect as well on the first indent? If the user want to disable the first indent on indent module, he might want to do the same for the chunk module.

yes, however chunk and textobjecgt are related, if a chunk is not rendered, it may be confused