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
472 stars 29 forks source link

chunk not redrawn when toggling a comment line #109

Closed soifou closed 1 month ago

soifou commented 1 month ago

Describe the bug The redraw is discarded when toggling one or several lines inside a chunk using the builtin comment (eg gcc) yielding to a non-continuous vertical line. Undoing restore it though. See video below.

To Reproduce Steps to reproduce the behavior:

nvim -nu repro.lua repro.lua
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',
        opts = {
            chunk = {
                enable = true,
            },
        },
    }
}
require('lazy').setup(plugins, {
    root = root .. '/plugins',
})

vim.opt.termguicolors = true

Screenshots

https://github.com/shellRaining/hlchunk.nvim/assets/7377369/faed698d-cfd4-43b4-bbea-cebba4f72609

shellRaining commented 1 month ago

chunk will have diff operation between pre chunk and the new chunk when rendering, when you press gcc the text changed and autocmd does trigger, but the render char not changed, so actually not render actually, I will figure out how the comment plugin work.

shellRaining commented 1 month ago

it seems that comment.nvim use nvim_buf_set_lines() instead of nvim_buf_set_text() caused this, the first function will remove extmark when change text, I will take a issue in this repo

soifou commented 1 month ago

FWIW, I don't use any comment plugin but the now builtin comment implementation that comes with nvim 0.10. It use as well nvim_buf_set_lines() as shown here

shellRaining commented 1 month ago

I also found that https://github.com/numToStr/Comment.nvim/issues/52 and https://github.com/numToStr/Comment.nvim/pull/110 mentioned this, seems can solve this, but the example I can't fully understand

shellRaining commented 1 month ago

fix by add lazy field when rendering, if comment a line then re-render with no lazy option passed. and because debounce function, there maybe blink when comment, I will improve in the future

soifou commented 1 month ago

This works great! Thank you so much for the quick fix.