diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-09-13 08:29:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-13 08:29:49 +0200 |
commit | 542022aae4ed8d1c0352042858f06da1ee077bf8 (patch) | |
tree | efdbc77ce8d0607f3bdfbd644022985a5d525058 /src/nvim/api/private/helpers.c | |
parent | 4d3ef578e91cb23586979ed50fa0dfddd45ded1d (diff) | |
parent | 2c15f695a812c8b6ad1484912acbecb978f8727b (diff) | |
download | rneovim-542022aae4ed8d1c0352042858f06da1ee077bf8.tar.gz rneovim-542022aae4ed8d1c0352042858f06da1ee077bf8.tar.bz2 rneovim-542022aae4ed8d1c0352042858f06da1ee077bf8.zip |
Merge pull request #12851 from bfredl/luahl
luahl: still WIP but better
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 13f77d2d85..e0d5862e02 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -15,6 +15,8 @@ #include "nvim/lua/executor.h" #include "nvim/ascii.h" #include "nvim/assert.h" +#include "nvim/charset.h" +#include "nvim/syntax.h" #include "nvim/vim.h" #include "nvim/buffer.h" #include "nvim/window.h" @@ -1579,3 +1581,52 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int return false; } } + +VirtText parse_virt_text(Array chunks, Error *err) +{ + VirtText virt_text = 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"); + 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"); + goto free_exit; + } + + String str = chunk.items[0].data.string; + char *text = transstr(str.size > 0 ? str.data : ""); // allocates + + int hl_id = 0; + if (chunk.size == 2) { + String hl = chunk.items[1].data.string; + if (hl.size > 0) { + hl_id = syn_check_group((char_u *)hl.data, (int)hl.size); + } + } + kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); + } + + return virt_text; + +free_exit: + clear_virttext(&virt_text); + return virt_text; +} + +bool api_is_truthy(Object obj, const char *what, Error *err) +{ + if (obj.type == kObjectTypeBoolean) { + return obj.data.boolean; + } else if (obj.type == kObjectTypeInteger) { + return obj.data.integer; // C semantics: non-zery int is true + } else { + api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what); + return false; + } +} |