diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:15:05 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:27:38 +0000 |
commit | c5d770d311841ea5230426cc4c868e8db27300a8 (patch) | |
tree | dd21f70127b4b8b5f109baefc8ecc5016f507c91 /src/nvim/api/private/helpers.c | |
parent | 9be89f131f87608f224f0ee06d199fcd09d32176 (diff) | |
parent | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff) | |
download | rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2 rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index e1fb4ed732..8ddaecc58e 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -771,7 +771,7 @@ int object_to_hl_id(Object obj, const char *what, Error *err) int id = (int)obj.data.integer; return (1 <= id && id <= highlight_num_groups()) ? id : 0; } else { - api_set_error(err, kErrorTypeValidation, "Invalid highlight: %s", what); + api_set_error(err, kErrorTypeValidation, "Invalid hl_group: %s", what); return 0; } } @@ -809,31 +809,22 @@ HlMessage parse_hl_msg(Array chunks, Error *err) { HlMessage hl_msg = KV_INITIAL_VALUE; for (size_t i = 0; i < chunks.size; i++) { - if (chunks.items[i].type != kObjectTypeArray) { - api_set_error(err, kErrorTypeValidation, "Chunk is not an array"); + VALIDATE_T("chunk", kObjectTypeArray, chunks.items[i].type, { goto free_exit; - } + }); Array chunk = chunks.items[i].data.array; - if (chunk.size == 0 || chunk.size > 2 - || chunk.items[0].type != kObjectTypeString - || (chunk.size == 2 && chunk.items[1].type != kObjectTypeString)) { - api_set_error(err, kErrorTypeValidation, - "Chunk is not an array with one or two strings"); + 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; - } + }); String str = copy_string(chunk.items[0].data.string, NULL); - int attr = 0; + int hl_id = 0; if (chunk.size == 2) { - String hl = chunk.items[1].data.string; - if (hl.size > 0) { - // TODO(bfredl): use object_to_hl_id and allow integer - int hl_id = syn_check_group(hl.data, hl.size); - attr = hl_id > 0 ? syn_id2attr(hl_id) : 0; - } + hl_id = object_to_hl_id(chunk.items[1], "text highlight", err); } - kv_push(hl_msg, ((HlMessageChunk){ .text = str, .attr = attr })); + kv_push(hl_msg, ((HlMessageChunk){ .text = str, .hl_id = hl_id })); } return hl_msg; |