From 1afe6dd2f4578fa7e6758565db36fa36db72b236 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 20 Oct 2020 20:26:53 -0400 Subject: fixup: bfredl comments --- src/nvim/api/private/helpers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 84517c99fc..dbc4e16d09 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1619,7 +1619,9 @@ free_exit: return virt_text; } -bool api_is_truthy(Object obj, const char *what, bool nil_truthy, Error *err) +/// Force obj to bool. +/// If it fails, returns false and sets err +bool api_coerce_to_bool(Object obj, const char *what, bool nil_truthy, Error *err) { if (obj.type == kObjectTypeBoolean) { return obj.data.boolean; -- cgit From 7fca3ddccad2130e75c68e94b5bf4db925b1911b Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 22 Oct 2020 14:32:19 -0400 Subject: fixup: some small nit picks --- src/nvim/api/private/helpers.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index dbc4e16d09..41b0f8ae1d 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1621,14 +1621,18 @@ free_exit: /// Force obj to bool. /// If it fails, returns false and sets err -bool api_coerce_to_bool(Object obj, const char *what, bool nil_truthy, Error *err) +/// @param obj The object to coerce to a boolean +/// @param what The name of the object, used for error message +/// @param if_nil What to return if the type is nil. +/// @param err Set if there was an error in converting to a bool +bool api_coerce_to_bool(Object obj, const char *what, bool if_nil, Error *err) { if (obj.type == kObjectTypeBoolean) { return obj.data.boolean; } else if (obj.type == kObjectTypeInteger) { return obj.data.integer; // C semantics: non-zero int is true } else if (obj.type == kObjectTypeNil) { - return nil_truthy; // caller decides what NIL (missing retval in lua) means + return if_nil; // caller decides what NIL (missing retval in lua) means } else { api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what); return false; -- cgit From a83b76790b82c8f9e74b82c8b0061682b66ddd0d Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 22 Oct 2020 16:21:35 -0400 Subject: fixup: fixup: fixup: fixup: --- src/nvim/api/private/helpers.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 41b0f8ae1d..981d41ae6e 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1621,18 +1621,22 @@ free_exit: /// Force obj to bool. /// If it fails, returns false and sets err -/// @param obj The object to coerce to a boolean -/// @param what The name of the object, used for error message -/// @param if_nil What to return if the type is nil. -/// @param err Set if there was an error in converting to a bool -bool api_coerce_to_bool(Object obj, const char *what, bool if_nil, Error *err) +/// @param obj The object to coerce to a boolean +/// @param what The name of the object, used for error message +/// @param nil_value What to return if the type is nil. +/// @param err Set if there was an error in converting to a bool +bool api_coerce_to_bool( + Object obj, + const char *what, + bool nil_value, + Error *err) { if (obj.type == kObjectTypeBoolean) { return obj.data.boolean; } else if (obj.type == kObjectTypeInteger) { return obj.data.integer; // C semantics: non-zero int is true } else if (obj.type == kObjectTypeNil) { - return if_nil; // caller decides what NIL (missing retval in lua) means + return nil_value; // caller decides what NIL (missing retval in lua) means } else { api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what); return false; -- cgit From c146eddc8b768f1cd395ea0ce54c19e64eff0c08 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 8 Sep 2020 09:47:10 +0200 Subject: api: add API for themes co-author: hlpr98 (dict2hlattrs function) orange is sus?? NOVEMBER DAWN erase the lie that is redraw_later() --- src/nvim/api/private/helpers.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 981d41ae6e..a9b1676879 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1625,11 +1625,8 @@ free_exit: /// @param what The name of the object, used for error message /// @param nil_value What to return if the type is nil. /// @param err Set if there was an error in converting to a bool -bool api_coerce_to_bool( - Object obj, - const char *what, - bool nil_value, - Error *err) +bool api_object_to_bool(Object obj, const char *what, + bool nil_value, Error *err) { if (obj.type == kObjectTypeBoolean) { return obj.data.boolean; @@ -1654,3 +1651,30 @@ const char *describe_ns(NS ns_id) }) return "(UNKNOWN PLUGIN)"; } + +DecorationProvider *get_provider(NS ns_id, bool force) +{ + ssize_t i; + for (i = 0; i < (ssize_t)kv_size(decoration_providers); i++) { + DecorationProvider *item = &kv_A(decoration_providers, i); + if (item->ns_id == ns_id) { + return item; + } else if (item->ns_id > ns_id) { + break; + } + } + + if (!force) { + return NULL; + } + + for (ssize_t j = (ssize_t)kv_size(decoration_providers)-1; j >= i; j++) { + // allocates if needed: + (void)kv_a(decoration_providers, (size_t)j+1); + kv_A(decoration_providers, (size_t)j+1) = kv_A(decoration_providers, j); + } + DecorationProvider *item = &kv_a(decoration_providers, (size_t)i); + *item = DECORATION_PROVIDER_INIT(ns_id); + + return item; +} -- cgit From c60c7375f5754eea2a4209cc6441e70b2bb44f14 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 19 Oct 2020 20:05:54 +0200 Subject: startup: handle autoload and lua packages during startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ¡NO HAY BANDA! --- src/nvim/api/private/helpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index df3a263dcf..7c6f07402b 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -52,7 +52,8 @@ .type = kObjectTypeLuaRef, \ .data.luaref = r }) -#define NIL ((Object) {.type = kObjectTypeNil}) +#define NIL ((Object)OBJECT_INIT) +#define NULL_STRING ((String)STRING_INIT) #define PUT(dict, k, v) \ kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v })) -- cgit