diff options
-rw-r--r-- | runtime/doc/api.txt | 44 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 26 | ||||
-rw-r--r-- | src/nvim/option.c | 39 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 53 |
4 files changed, 142 insertions, 20 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 58633455c3..755e7becb3 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -933,6 +933,39 @@ nvim_get_option({name}) *nvim_get_option()* Return: ~ Option value (global) +nvim_get_option_info({name}) *nvim_get_option_info()* + 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 + + Parameters: ~ + {name} Option name + + Return: ~ + Option Information + +nvim_get_options_info() *nvim_get_options_info()* + Gets the option information for all options. + + Return: ~ + Map<option_name, option_info> + nvim_get_proc({pid}) *nvim_get_proc()* Gets info describing process `pid` . @@ -950,11 +983,16 @@ nvim_get_runtime_file({name}, {all}) *nvim_get_runtime_file()* 'name' can contain wildcards. For example nvim_get_runtime_file("colors/*.vim", true) will return all - color scheme files. + color scheme files. Always use forward slashes (/) in the + search pattern for subdirectories regardless of platform. It is not an error to not find any files. An empty array is returned then. + To find a directory, `name` must end with a forward slash, + like "rplugin/python/". Without the slash it would instead + look for an ordinary file called "rplugin/python". + Attributes: ~ {fast} @@ -1535,7 +1573,9 @@ nvim_set_hl({ns_id}, {name}, {val}) *nvim_set_hl()* {ns_id} number of namespace for this highlight {name} highlight group name, like ErrorMsg {val} highlight definiton map, like - |nvim_get_hl_by_name|. + |nvim_get_hl_by_name|. in addition the following + keys are also recognized: `default` : don't + override existing definition, like `hi default` nvim_set_hl_ns({ns_id}) *nvim_set_hl_ns()* Set active namespace for highlights. 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<option_name, option_info> 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) { diff --git a/src/nvim/option.c b/src/nvim/option.c index 12468adbe8..85f38b02ae 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7180,7 +7180,7 @@ Dictionary get_vimoption(String name, Error *err) { int opt_idx = findoption_len((const char *)name.data, name.size); if (opt_idx < 0) { - api_set_error(err, kErrorTypeValidation, "no such option %s", name.data); + api_set_error(err, kErrorTypeValidation, "no such option: '%s'", name.data); return (Dictionary)ARRAY_DICT_INIT; } return vimoption2dict(&options[opt_idx]); @@ -7202,27 +7202,30 @@ static Dictionary vimoption2dict(vimoption_T *opt) PUT(dict, "name", STRING_OBJ(cstr_to_string(opt->fullname))); PUT(dict, "shortname", STRING_OBJ(cstr_to_string(opt->shortname))); -#define PUT_IF(dict, name, condition) do if (condition) \ - { PUT(dict, name, BOOLEAN_OBJ(true)); } while (0) - PUT_IF(dict, "win", opt->indir & PV_WIN); - PUT_IF(dict, "buf", opt->indir & PV_BUF); + +#define PUT_BOOL(dict, name, condition) \ + PUT(dict, name, BOOLEAN_OBJ(condition)); + + PUT_BOOL(dict, "win", opt->indir & PV_WIN); + PUT_BOOL(dict, "buf", opt->indir & PV_BUF); + // welcome to the jungle - PUT_IF(dict, "global_local", opt->indir & PV_BOTH); - PUT_IF(dict, "commalist", opt->flags & P_COMMA); - PUT_IF(dict, "flaglist", opt->flags & P_FLAGLIST); + PUT_BOOL(dict, "global_local", opt->indir & PV_BOTH); + PUT_BOOL(dict, "commalist", opt->flags & P_COMMA); + PUT_BOOL(dict, "flaglist", opt->flags & P_FLAGLIST); - PUT_IF(dict, "was_set", opt->flags & P_WAS_SET); + PUT_BOOL(dict, "was_set", opt->flags & P_WAS_SET); +#undef PUT_BOOL - PUT(dict, "flag", INTEGER_OBJ(opt->flags)); // TODO(bfredl): lol tj PUT(dict, "last_set_sid", INTEGER_OBJ(opt->last_set.script_ctx.sc_sid)); - if (opt->last_set.script_ctx.sc_lnum > 0) { - PUT(dict, "last_set_linenr", - INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum)); - } - if (opt->last_set.channel_id > 0) { - PUT(dict, "last_set_lchan", - INTEGER_OBJ((int64_t)opt->last_set.channel_id)); - } + PUT(dict, "last_set_linenr", + opt->last_set.script_ctx.sc_lnum > 0 + ? INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum) + : INTEGER_OBJ(-1)); + PUT(dict, "last_set_lchan", + opt->last_set.channel_id > 0 + ? INTEGER_OBJ((int64_t)opt->last_set.channel_id) + : INTEGER_OBJ(-1)); const char *type; Object def; diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index eb5fd7eca7..8880d88f5e 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1921,4 +1921,57 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) end) + + describe('nvim_get_options_info', function() + it('should have key value pairs of option names', function() + local options_info = meths.get_options_info() + neq(nil, options_info.listchars) + neq(nil, options_info.tabstop) + end) + end) + + describe('nvim_get_option_info', function() + it('should error for unknown options', function() + eq("no such option: 'bogus'", + pcall_err(meths.get_option_info, 'bogus')) + end) + + it('should return the same options for short and long name', function() + eq( + meths.get_option_info('winhl'), + meths.get_option_info('winhighlight') + ) + end) + + it('should have information about window options', function() + local winhl_info = meths.get_option_info('winhl') + eq(true, winhl_info.win) + eq(false, winhl_info.buf) + eq('string', winhl_info.type) + eq('winhighlight', winhl_info.name) + eq('winhl', winhl_info.shortname) + eq('', winhl_info.default) + end) + + it('should have information about buffer options', function() + local filetype_info = meths.get_option_info('filetype') + eq(false, filetype_info.win) + eq(true, filetype_info.buf) + eq('string', filetype_info.type) + eq('filetype', filetype_info.name) + eq('ft', filetype_info.shortname) + eq('', filetype_info.default) + end) + + it('should have information about global options', function() + local showcmd_info = meths.get_option_info('showcmd') + eq(false, showcmd_info.win) + eq(false, showcmd_info.buf) + eq(false, showcmd_info.global_local) + eq('boolean', showcmd_info.type) + eq('showcmd', showcmd_info.name) + eq('sc', showcmd_info.shortname) + eq(true, showcmd_info.default) + end) + end) end) |