aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluukvbaal <luukvbaal@gmail.com>2024-11-18 15:35:21 +0100
committerGitHub <noreply@github.com>2024-11-18 06:35:21 -0800
commit40347f6e27f1594797ecb0b268076a94630e4c1b (patch)
treef354b7ffef8aa1dc1d21efb67dff250bda73c92c
parent1763eddede82697a081d8741bd7e780c1b729de0 (diff)
downloadrneovim-40347f6e27f1594797ecb0b268076a94630e4c1b.tar.gz
rneovim-40347f6e27f1594797ecb0b268076a94630e4c1b.tar.bz2
rneovim-40347f6e27f1594797ecb0b268076a94630e4c1b.zip
fix(api): only flush nvim__redraw when necessary #31250
Problem: Not possible to only set a "redraw later" type with nvim__redraw, which seems to be desired for the treesitter highlighter. Solution: Do not update the screen when "flush" is explicitly set to false and only redraw later types are present. In that case, do not call ui_flush() either.
-rw-r--r--runtime/lua/vim/lsp/inlay_hint.lua6
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua4
-rw-r--r--src/nvim/api/vim.c14
3 files changed, 18 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua
index ca7bc3b022..f1ae9a8e9e 100644
--- a/runtime/lua/vim/lsp/inlay_hint.lua
+++ b/runtime/lua/vim/lsp/inlay_hint.lua
@@ -65,7 +65,7 @@ function M.on_inlayhint(err, result, ctx)
if num_unprocessed == 0 then
client_hints[client_id] = {}
bufstate.version = ctx.version
- api.nvim__redraw({ buf = bufnr, valid = true })
+ api.nvim__redraw({ buf = bufnr, valid = true, flush = false })
return
end
@@ -81,7 +81,7 @@ function M.on_inlayhint(err, result, ctx)
client_hints[client_id] = new_lnum_hints
bufstate.version = ctx.version
- api.nvim__redraw({ buf = bufnr, valid = true })
+ api.nvim__redraw({ buf = bufnr, valid = true, flush = false })
end
--- |lsp-handler| for the method `workspace/inlayHint/refresh`
@@ -215,7 +215,7 @@ local function clear(bufnr)
end
end
api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)
- api.nvim__redraw({ buf = bufnr, valid = true })
+ api.nvim__redraw({ buf = bufnr, valid = true, flush = false })
end
--- Disable inlay hints for a buffer
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 05124c29f0..8ce8652f7d 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -219,8 +219,8 @@ end
---@package
---@param changes Range6[]
function TSHighlighter:on_changedtree(changes)
- for i, ch in ipairs(changes) do
- api.nvim__redraw({ buf = self.bufnr, range = { ch[1], ch[4] + 1 }, flush = i == #changes })
+ for _, ch in ipairs(changes) do
+ api.nvim__redraw({ buf = self.bufnr, range = { ch[1], ch[4] + 1 }, flush = false })
end
end
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 0d562f2276..83f9aa573d 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -2396,9 +2396,16 @@ void nvim__redraw(Dict(redraw) *opts, Error *err)
last = rbuf->b_ml.ml_line_count;
}
redraw_buf_range_later(rbuf, first, last);
+ }
+
+ // Redraw later types require update_screen() so call implicitly unless set to false.
+ if (HAS_KEY(opts, redraw, valid) || HAS_KEY(opts, redraw, range)) {
opts->flush = HAS_KEY(opts, redraw, flush) ? opts->flush : true;
}
+ // When explicitly set to false and only "redraw later" types are present,
+ // don't call ui_flush() either.
+ bool flush_ui = opts->flush;
if (opts->tabline) {
// Flush later in case tabline was just hidden or shown for the first time.
if (redraw_tabline && firstwin->w_lines_valid == 0) {
@@ -2406,6 +2413,7 @@ void nvim__redraw(Dict(redraw) *opts, Error *err)
} else {
draw_tabline();
}
+ flush_ui = true;
}
bool save_lz = p_lz;
@@ -2422,6 +2430,7 @@ void nvim__redraw(Dict(redraw) *opts, Error *err)
} else {
redraw_status(win, opts, &opts->flush);
}
+ flush_ui = true;
}
win_T *cwin = win ? win : curwin;
@@ -2438,9 +2447,12 @@ void nvim__redraw(Dict(redraw) *opts, Error *err)
if (opts->cursor) {
setcursor_mayforce(cwin, true);
+ flush_ui = true;
}
- ui_flush();
+ if (flush_ui) {
+ ui_flush();
+ }
RedrawingDisabled = save_rd;
p_lz = save_lz;