diff options
| author | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2025-09-05 17:12:28 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-05 07:12:28 -0700 |
| commit | 069be911064d0e64f1efc13348dbb878afaf347f (patch) | |
| tree | 6a3038e7c1739c241ac68621b3ded5012d78c0f6 /runtime/lua/vim/pack.lua | |
| parent | 0bafbe872b2f6cab2a4a6df9213ffc664eeee948 (diff) | |
| download | rneovim-069be911064d0e64f1efc13348dbb878afaf347f.tar.gz rneovim-069be911064d0e64f1efc13348dbb878afaf347f.tar.bz2 rneovim-069be911064d0e64f1efc13348dbb878afaf347f.zip | |
feat(pack): use `nvim_echo{kind=progress}` to report progress #35625
Problem: Progress reports use plain `nvim_echo()` with manually
constructed messages and populate history on every call.
Solution: Use `nvim_echo()` with newly added `kind=progress` which (at
least for now) is meant to be a unified interface for showing progress
report. Also save in history only first and last progress report
messages.
Diffstat (limited to 'runtime/lua/vim/pack.lua')
| -rw-r--r-- | runtime/lua/vim/pack.lua | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 1614cc0c83..ae999e95e7 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -368,35 +368,16 @@ local function trigger_event(p, event_name, kind) api.nvim_exec_autocmds(event_name, { pattern = p.path, data = data }) end ---- @param title string +--- @param action string --- @return fun(kind: 'begin'|'report'|'end', percent: integer, fmt: string, ...:any): nil -local function new_progress_report(title) - -- TODO(echasnovski): currently print directly in command line because - -- there is no robust built-in way of showing progress: - -- - `vim.ui.progress()` is planned and is a good candidate to use here. - -- - Use `'$/progress'` implementation in 'vim.pack._lsp' if there is - -- a working built-in '$/progress' handler. Something like this: - -- ```lua - -- local progress_token_count = 0 - -- function M.new_progress_report(title) - -- progress_token_count = progress_token_count + 1 - -- return vim.schedule_wrap(function(kind, msg, percent) - -- local value = { kind = kind, message = msg, percentage = percent } - -- dispatchers.notification( - -- '$/progress', - -- { token = progress_token_count, value = value } - -- ) - -- end - -- end - -- ``` - -- Any of these choices is better as users can tweak how progress is shown. +local function new_progress_report(action) + local progress = { kind = 'progress', title = 'vim.pack' } return vim.schedule_wrap(function(kind, percent, fmt, ...) - local progress = kind == 'end' and 'done' or ('%3d%%'):format(percent) - local details = (' %s %s'):format(title, fmt:format(...)) - local chunks = { { 'vim.pack', 'ModeMsg' }, { ': ' }, { progress, 'WarningMsg' }, { details } } - -- TODO: need to add support for progress-messages api - api.nvim_echo(chunks, true, {}) + progress.status = kind == 'end' and 'success' or 'running' + progress.percent = percent + local msg = ('%s %s'):format(action, fmt:format(...)) + progress.id = api.nvim_echo({ { msg } }, kind ~= 'report', progress) -- Force redraw to show installation progress during startup vim.cmd.redraw({ bang = true }) end) @@ -408,9 +389,9 @@ local copcall = package.loaded.jit and pcall or require('coxpcall').pcall --- Execute function in parallel for each non-errored plugin in the list --- @param plug_list vim.pack.Plug[] --- @param f async fun(p: vim.pack.Plug) ---- @param progress_title string -local function run_list(plug_list, f, progress_title) - local report_progress = new_progress_report(progress_title) +--- @param progress_action string +local function run_list(plug_list, f, progress_action) + local report_progress = new_progress_report(progress_action) -- Construct array of functions to execute in parallel local n_finished = 0 |