From 35767912bbe9da4556aab122ba00488c56dd9f17 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 27 Oct 2020 22:20:52 -0400 Subject: api/options: add option metadata --- src/nvim/api/vim.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 77002697fe..c5dc89410a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -970,6 +970,62 @@ Object nvim_get_option(String name, Error *err) return get_option_from(NULL, SREQ_GLOBAL, name, err); } +Dictionary nvim_get_vimoption_info(Error *err) + FUNC_API_SINCE(7) +{ + Dictionary retval = ARRAY_DICT_INIT; + + vimoption_T *all_options = get_all_vimoptions(); + + int i = 0; + vimoption_T opt; + while (true) { + opt = all_options[i++]; + if (opt.fullname == NULL) { + break; + } + + Dictionary opt_dict = ARRAY_DICT_INIT; + + PUT(opt_dict, "fullname", STRING_OBJ(cstr_to_string(opt.fullname))); + PUT(opt_dict, "shortname", STRING_OBJ(cstr_to_string(opt.shortname))); + PUT(opt_dict, "is_global", BOOLEAN_OBJ(opt.flags & OPT_GLOBAL)); + PUT(opt_dict, "is_local", BOOLEAN_OBJ(opt.flags & OPT_LOCAL)); + PUT(opt_dict, "flag", INTEGER_OBJ(opt.flags)); + PUT(opt_dict, "sourced_sid", INTEGER_OBJ(opt.last_set.script_ctx.sc_sid)); + PUT(opt_dict, "sourced_lnum", INTEGER_OBJ(opt.last_set.script_ctx.sc_lnum)); + PUT(opt_dict, "type", STRING_OBJ(get_option_type_string(opt))); + + PUT(retval, opt.fullname, DICTIONARY_OBJ(opt_dict)); + } + + return retval; +} + +Dictionary nvim_get_option_info(String name, Error *err) + FUNC_API_SINCE(7) +{ + Dictionary retval = ARRAY_DICT_INIT; + + get_option_from(NULL, SREQ_GLOBAL, name, err); + if (ERROR_SET(err)) { + return retval; + } + + int opt_idx = findoption_len((const char *)name.data, name.size); + vimoption_T opt = get_vimoption(opt_idx); + + PUT(retval, "fullname", STRING_OBJ(cstr_to_string(opt.fullname))); + PUT(retval, "shortname", STRING_OBJ(cstr_to_string(opt.shortname))); + PUT(retval, "is_global", BOOLEAN_OBJ(opt.flags & OPT_GLOBAL)); + PUT(retval, "is_local", BOOLEAN_OBJ(opt.flags & OPT_LOCAL)); + PUT(retval, "flag", INTEGER_OBJ(opt.flags)); + PUT(retval, "sourced_sid", INTEGER_OBJ(opt.last_set.script_ctx.sc_sid)); + PUT(retval, "sourced_lnum", INTEGER_OBJ(opt.last_set.script_ctx.sc_lnum)); + + return retval; +} + /// Sets an option value. /// /// @param channel_id -- cgit From 3b3c006ae34256637f101ea85a84998377f56e40 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 1 Dec 2020 22:10:41 +0100 Subject: api/options: cleanup --- src/nvim/api/vim.c | 50 +++----------------------------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c5dc89410a..b3576bc436 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -970,60 +970,16 @@ Object nvim_get_option(String name, Error *err) return get_option_from(NULL, SREQ_GLOBAL, name, err); } -Dictionary nvim_get_vimoption_info(Error *err) +Dictionary nvim_get_options_info(Error *err) FUNC_API_SINCE(7) { - Dictionary retval = ARRAY_DICT_INIT; - - vimoption_T *all_options = get_all_vimoptions(); - - int i = 0; - vimoption_T opt; - while (true) { - opt = all_options[i++]; - if (opt.fullname == NULL) { - break; - } - - Dictionary opt_dict = ARRAY_DICT_INIT; - - PUT(opt_dict, "fullname", STRING_OBJ(cstr_to_string(opt.fullname))); - PUT(opt_dict, "shortname", STRING_OBJ(cstr_to_string(opt.shortname))); - PUT(opt_dict, "is_global", BOOLEAN_OBJ(opt.flags & OPT_GLOBAL)); - PUT(opt_dict, "is_local", BOOLEAN_OBJ(opt.flags & OPT_LOCAL)); - PUT(opt_dict, "flag", INTEGER_OBJ(opt.flags)); - PUT(opt_dict, "sourced_sid", INTEGER_OBJ(opt.last_set.script_ctx.sc_sid)); - PUT(opt_dict, "sourced_lnum", INTEGER_OBJ(opt.last_set.script_ctx.sc_lnum)); - PUT(opt_dict, "type", STRING_OBJ(get_option_type_string(opt))); - - PUT(retval, opt.fullname, DICTIONARY_OBJ(opt_dict)); - } - - return retval; + return get_all_vimoptions(); } Dictionary nvim_get_option_info(String name, Error *err) FUNC_API_SINCE(7) { - Dictionary retval = ARRAY_DICT_INIT; - - get_option_from(NULL, SREQ_GLOBAL, name, err); - if (ERROR_SET(err)) { - return retval; - } - - int opt_idx = findoption_len((const char *)name.data, name.size); - vimoption_T opt = get_vimoption(opt_idx); - - PUT(retval, "fullname", STRING_OBJ(cstr_to_string(opt.fullname))); - PUT(retval, "shortname", STRING_OBJ(cstr_to_string(opt.shortname))); - PUT(retval, "is_global", BOOLEAN_OBJ(opt.flags & OPT_GLOBAL)); - PUT(retval, "is_local", BOOLEAN_OBJ(opt.flags & OPT_LOCAL)); - PUT(retval, "flag", INTEGER_OBJ(opt.flags)); - PUT(retval, "sourced_sid", INTEGER_OBJ(opt.last_set.script_ctx.sc_sid)); - PUT(retval, "sourced_lnum", INTEGER_OBJ(opt.last_set.script_ctx.sc_lnum)); - - return retval; + return get_vimoption(name, err); } /// Sets an option value. -- cgit From ced951c2aacd175c21c68a5bbf7fdf459954d0ab Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 3 Dec 2020 20:59:36 -0500 Subject: api/options: fixup --- src/nvim/api/vim.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b3576bc436..a95aa0f170 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -970,12 +970,38 @@ Object nvim_get_option(String name, Error *err) return get_option_from(NULL, SREQ_GLOBAL, name, err); } +/// Gets the option information for all options. +/// @return Map Dictionary nvim_get_options_info(Error *err) FUNC_API_SINCE(7) { return get_all_vimoptions(); } +/// Gets the option information for one option +/// +/// Resulting dictionary has keys: +/// - name (string): Name of the option +/// - shortname (shortname): Shortened name of the option +/// - type (string): Name of the type of option +/// - default (Any): The default value for the option +/// +/// Script-Related Keys: +/// - was_set (bool): Whether the option was set. +/// - last_set_sid (int): Last set script id +/// - last_set_linenr (int): Last set script id, -1 if invalid. +/// - last_set_lchan (int): Last set script id, -1 if invalid. +/// +/// Flag-Related Keys: +/// - win (bool): Window-local option +/// - buf (bool): Buffer-local option +/// - global_local (bool): Global or Buffer local option +/// - flaglist (bool): List of single char flags +/// +/// +/// @param name Option name +/// @param[out] err Error details, if any +/// @return Option Information Dictionary nvim_get_option_info(String name, Error *err) FUNC_API_SINCE(7) { -- cgit From 17a58043a3fc49179a47590e905ed3a7d5a29907 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 4 Dec 2020 10:59:58 +0100 Subject: api/options: cleanup the fixup --- src/nvim/api/private/helpers.h | 5 +++++ src/nvim/api/vim.c | 39 +++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 271fd5b485..055abb797f 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -16,6 +16,7 @@ #define BOOLEAN_OBJ(b) ((Object) { \ .type = kObjectTypeBoolean, \ .data.boolean = b }) +#define BOOL(b) BOOLEAN_OBJ(b) #define INTEGER_OBJ(i) ((Object) { \ .type = kObjectTypeInteger, \ @@ -29,6 +30,8 @@ .type = kObjectTypeString, \ .data.string = s }) +#define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s)) + #define BUFFER_OBJ(s) ((Object) { \ .type = kObjectTypeBuffer, \ .data.integer = s }) @@ -59,6 +62,8 @@ #define PUT(dict, k, v) \ kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v })) +#define PUT_BOOL(dict, name, condition) PUT(dict, name, BOOLEAN_OBJ(condition)); + #define ADD(array, item) \ kv_push(array, item) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a95aa0f170..8ac820abd9 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -971,8 +971,12 @@ Object nvim_get_option(String name, Error *err) } /// Gets the option information for all options. -/// @return Map -Dictionary nvim_get_options_info(Error *err) +/// +/// The dictionary has the full option names as keys and option metadata +/// dictionaries as detailed at |nvim_get_option_info|. +/// +/// @return dictionary of all options +Dictionary nvim_get_all_options_info(Error *err) FUNC_API_SINCE(7) { return get_all_vimoptions(); @@ -981,22 +985,21 @@ Dictionary nvim_get_options_info(Error *err) /// Gets the option information for one option /// /// Resulting dictionary has keys: -/// - name (string): Name of the option -/// - shortname (shortname): Shortened name of the option -/// - type (string): Name of the type of option -/// - default (Any): The default value for the option -/// -/// Script-Related Keys: -/// - was_set (bool): Whether the option was set. -/// - last_set_sid (int): Last set script id -/// - last_set_linenr (int): Last set script id, -1 if invalid. -/// - last_set_lchan (int): Last set script id, -1 if invalid. -/// -/// Flag-Related Keys: -/// - win (bool): Window-local option -/// - buf (bool): Buffer-local option -/// - global_local (bool): Global or Buffer local option -/// - flaglist (bool): List of single char flags +/// - name: Name of the option (like 'filetype') +/// - shortname: Shortened name of the option (like 'ft') +/// - type: type of option ("string", "integer" or "boolean") +/// - default: The default value for the option +/// - was_set: Whether the option was set. +/// +/// - last_set_sid: Last set script id (if any) +/// - last_set_linenr: line number where option was set +/// - last_set_chan: Channel where option was set (0 for local) +/// +/// - scope: one of "global", "win", or "buf" +/// - global_local: whether win or buf option has a global value +/// +/// - commalist: List of comma separated values +/// - flaglist: List of single char flags /// /// /// @param name Option name -- cgit