Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep extmarks as much as possible when reset hunk #637

Closed
kevinhwang91 opened this issue Sep 30, 2022 · 3 comments · Fixed by #897
Closed

Keep extmarks as much as possible when reset hunk #637

kevinhwang91 opened this issue Sep 30, 2022 · 3 comments · Fixed by #897
Labels
enhancement New feature or request

Comments

@kevinhwang91
Copy link

Is your feature request related to a problem? Please describe.
reset_hunk with range (maybe total buffer content) and reset_buffer will replace range lines with lines in hunks.

Describe the solution you'd like
Find all hunks and set lines one by one in the range. Maybe can set a limited value if the hunks are Intensive in the range.

Additional context
TBH, semantic tokens of coc.nvim and nvim-ufo use a lot of extmarks, that's the reason I want to replace Gread in fugitive with reset_buffer in gitsigns.

@kevinhwang91 kevinhwang91 added the enhancement New feature or request label Sep 30, 2022
@kevinhwang91
Copy link
Author

function _G.resetBuffer(bufnr)
    bufnr = bufnr or vim.api.nvim_get_current_buf()
    local gs = require('gitsigns')
    local hunks = gs.get_hunks(bufnr)
    for i = #hunks, 1, -1 do
        local hunk = hunks[i]
        local added = hunk.added
        gs.reset_hunk({added.start, added.start + math.max(0, added.count - 1)})
    end
end

This script works for me, feel free to close the issue if you want.

@lewis6991
Copy link
Owner

Sorry, I really don't understand the feature you are asking for. Can you explain? I don't understand what reset_buffer is doing that you don't like.

@kevinhwang91
Copy link
Author

nvim_buf_set_lines(0, s, e, true, {lines}) will clear extmarks from s to e. If the range has only a hunk under {hs, he}, I expect to invoke nvim_buf_set_lines(0, hs, he, true, {hunk_lines}) instead. This will keep extmarks under ranges {s, hs - 1} and {he + 1, e}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants