feat(api): nvim_echo can emit Progress messages/events #34846

Problem:
Nvim does not have a core concept for indicating "progress" of
long-running tasks. The LspProgress event is specific to LSP.

Solution:
- `nvim_echo` can emit `kind="progress"` messages.
  - Emits a `Progress` event.
  - Includes new fields (id, status, percent) in the `msg_show` ui-event.
  - The UI is expected to overwrite any message having the same id.
- Messages have a globally unique ID.
  - `nvim_echo` returns the message ID.
- `nvim_echo(… {id=…})` updates existing messages.

Example:

    local grp = vim.api.nvim_create_augroup("Msg", {clear = true})
    vim.api.nvim_create_autocmd('Progress', {
      pattern={"term"},
      group = grp,
      callback = function(ev)
        print(string.format('event fired: %s', vim.inspect(ev))..'\n')
      end
    })

    -- require('vim._extui').enable({enable=true, msg={target='msg', timeout=1000}})
    vim.api.nvim_echo({{'searching'}}, true, {kind='progress',  percent=80, status='running', title="terminal(ripgrep)"})
    local id = vim.api.nvim_echo({{'searching'}}, true, {kind='progress', status='running', percent=10, title="terminal(ripgrep)"})
    vim.api.nvim_echo({}, true, {id = id, kind='progress', percent=20, status = 'running', title='find tests'})
    vim.api.nvim_echo({}, true, {id = id, kind='progress', status='running', percent=70})
    vim.api.nvim_echo({{'complete'}}, true, {id = id, kind='progress', status='success', percent=100, title="find tests"})

Followups:
- Integrate with 'statusline' by listening to the Progress autocmd event.
- Integrate progress ui-event with `vim._extui`.
This commit is contained in:
Shadman
2025-08-27 02:48:53 +06:00
committed by GitHub
parent 1e1619de83
commit 8b171852a9
19 changed files with 648 additions and 19 deletions

View File

@@ -1100,10 +1100,25 @@ function vim.api.nvim_del_var(name) end
--- the (optional) name or ID `hl_group`.
--- @param history boolean if true, add to `message-history`.
--- @param opts vim.api.keyset.echo_opts Optional parameters.
--- - id: message id for updating existing message.
--- - err: Treat the message like `:echoerr`. Sets `hl_group` to `hl-ErrorMsg` by default.
--- - kind: Set the `ui-messages` kind with which this message will be emitted.
--- - verbose: Message is controlled by the 'verbose' option. Nvim invoked with `-V3log`
--- will write the message to the "log" file instead of standard output.
--- - title: The title for `progress-message`.
--- - status: Current status of the `progress-message`. Can be
--- one of the following values
--- - success: The progress item completed successfully
--- - running: The progress is ongoing
--- - failed: The progress item failed
--- - cancel: The progressing process should be canceled.
--- note: Cancel needs to be handled by progress
--- initiator by listening for the `Progress` event
--- - percent: How much progress is done on the progress
--- message
--- - data: dictionary containing additional information
--- @return integer|string # Message id.
--- - -1 means nvim_echo didn't show a message
function vim.api.nvim_echo(chunks, history, opts) end
--- @deprecated