commit 38aac21083a5fe877ae6a60bb33d5aa412dea0da
parent f731766474901e5e345e0ca630315ef69122e556
Author: Lewis Russell <lewis6991@gmail.com>
Date: Tue, 1 Jul 2025 12:15:34 +0100
fix: type of nvim_echo
Diffstat:
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
@@ -651,7 +651,7 @@ nvim_echo({chunks}, {history}, {opts}) *nvim_echo()*
Since: 0.5.0
Parameters: ~
- • {chunks} (`[string, integer|string][]`) List of `[text, hl_group]`
+ • {chunks} (`[string, integer|string?][]`) List of `[text, hl_group]`
pairs, where each is a `text` string highlighted by the
(optional) name or ID `hl_group`.
• {history} (`boolean`) if true, add to |message-history|.
diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua
@@ -1096,7 +1096,7 @@ function vim.api.nvim_del_var(name) end
--- vim.api.nvim_echo({ { 'chunk1-line1\nchunk1-line2\n' }, { 'chunk2-line1' } }, true, {})
--- ```
---
---- @param chunks [string, integer|string][] List of `[text, hl_group]` pairs, where each is a `text` string highlighted by
+--- @param chunks [string, integer|string?][] List of `[text, hl_group]` pairs, where each is a `text` string highlighted by
--- 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.
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
@@ -770,14 +770,14 @@ char *api_typename(ObjectType t)
UNREACHABLE;
}
-HlMessage parse_hl_msg(Array chunks, bool is_err, Error *err)
+HlMessage parse_hl_msg(ArrayOf(Tuple(String, *HLGroupID)) chunks, bool is_err, Error *err)
{
HlMessage hl_msg = KV_INITIAL_VALUE;
for (size_t i = 0; i < chunks.size; i++) {
VALIDATE_T("chunk", kObjectTypeArray, chunks.items[i].type, {
goto free_exit;
});
- Array chunk = chunks.items[i].data.array;
+ Tuple(String, *HLGroupID) chunk = chunks.items[i].data.array;
VALIDATE((chunk.size > 0 && chunk.size <= 2 && chunk.items[0].type == kObjectTypeString),
"%s", "Invalid chunk: expected Array with 1 or 2 Strings", {
goto free_exit;
@@ -785,10 +785,10 @@ HlMessage parse_hl_msg(Array chunks, bool is_err, Error *err)
String str = copy_string(chunk.items[0].data.string, NULL);
- int hl_id = is_err ? HLF_E : 0;
- if (chunk.size == 2) {
- hl_id = object_to_hl_id(chunk.items[1], "text highlight", err);
- }
+ int hl_id =
+ chunk.size == 2 ? object_to_hl_id(chunk.items[1], "text highlight", err)
+ : is_err ? HLF_E
+ : 0;
kv_push(hl_msg, ((HlMessageChunk){ .text = str, .hl_id = hl_id }));
}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
@@ -762,7 +762,7 @@ void nvim_set_vvar(String name, Object value, Error *err)
/// - 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.
-void nvim_echo(ArrayOf(Tuple(String, HLGroupID)) chunks, Boolean history, Dict(echo_opts) *opts,
+void nvim_echo(ArrayOf(Tuple(String, *HLGroupID)) chunks, Boolean history, Dict(echo_opts) *opts,
Error *err)
FUNC_API_SINCE(7)
{