mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api/options: cleanup the fixup
This commit is contained in:
parent
ced951c2aa
commit
17a58043a3
@ -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)
|
||||
|
||||
|
@ -971,8 +971,12 @@ Object nvim_get_option(String name, Error *err)
|
||||
}
|
||||
|
||||
/// Gets the option information for all options.
|
||||
/// @return Map<option_name, option_info>
|
||||
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
|
||||
/// - 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.
|
||||
///
|
||||
/// 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.
|
||||
/// - 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)
|
||||
///
|
||||
/// 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
|
||||
/// - 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
|
||||
|
@ -7200,32 +7200,30 @@ static Dictionary vimoption2dict(vimoption_T *opt)
|
||||
{
|
||||
Dictionary dict = ARRAY_DICT_INIT;
|
||||
|
||||
PUT(dict, "name", STRING_OBJ(cstr_to_string(opt->fullname)));
|
||||
PUT(dict, "shortname", STRING_OBJ(cstr_to_string(opt->shortname)));
|
||||
PUT(dict, "name", CSTR_TO_OBJ(opt->fullname));
|
||||
PUT(dict, "shortname", CSTR_TO_OBJ(opt->shortname));
|
||||
|
||||
#define PUT_BOOL(dict, name, condition) \
|
||||
PUT(dict, name, BOOLEAN_OBJ(condition));
|
||||
const char *scope;
|
||||
if (opt->indir & PV_BUF) {
|
||||
scope = "buf";
|
||||
} else if (opt->indir & PV_WIN) {
|
||||
scope = "win";
|
||||
} else {
|
||||
scope = "global";
|
||||
}
|
||||
|
||||
PUT_BOOL(dict, "win", opt->indir & PV_WIN);
|
||||
PUT_BOOL(dict, "buf", opt->indir & PV_BUF);
|
||||
PUT(dict, "scope", CSTR_TO_OBJ(scope));
|
||||
|
||||
// welcome to the jungle
|
||||
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(dict, "global_local", BOOL(opt->indir & PV_BOTH));
|
||||
PUT(dict, "commalist", BOOL(opt->flags & P_COMMA));
|
||||
PUT(dict, "flaglist", BOOL(opt->flags & P_FLAGLIST));
|
||||
|
||||
PUT_BOOL(dict, "was_set", opt->flags & P_WAS_SET);
|
||||
#undef PUT_BOOL
|
||||
PUT(dict, "was_set", BOOL(opt->flags & P_WAS_SET));
|
||||
|
||||
PUT(dict, "last_set_sid", INTEGER_OBJ(opt->last_set.script_ctx.sc_sid));
|
||||
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));
|
||||
PUT(dict, "last_set_linenr", INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum));
|
||||
PUT(dict, "last_set_chan", INTEGER_OBJ((int64_t)opt->last_set.channel_id));
|
||||
|
||||
const char *type;
|
||||
Object def;
|
||||
@ -7234,17 +7232,17 @@ static Dictionary vimoption2dict(vimoption_T *opt)
|
||||
? VI_DEFAULT : VIM_DEFAULT];
|
||||
if (opt->flags & P_STRING) {
|
||||
type = "string";
|
||||
def = STRING_OBJ(cstr_to_string(def_val ? (char *)def_val : ""));
|
||||
def = CSTR_TO_OBJ(def_val ? (char *)def_val : "");
|
||||
} else if (opt->flags & P_NUM) {
|
||||
type = "string";
|
||||
type = "number";
|
||||
def = INTEGER_OBJ((Integer)(intptr_t)def_val);
|
||||
} else if (opt->flags & P_BOOL) {
|
||||
type = "boolean";
|
||||
def = BOOLEAN_OBJ((intptr_t)def_val);
|
||||
def = BOOL((intptr_t)def_val);
|
||||
} else {
|
||||
type = ""; def = NIL;
|
||||
}
|
||||
PUT(dict, "type", STRING_OBJ(cstr_to_string(type)));
|
||||
PUT(dict, "type", CSTR_TO_OBJ(type));
|
||||
PUT(dict, "default", def);
|
||||
|
||||
return dict;
|
||||
|
@ -1922,56 +1922,78 @@ describe('API', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_get_options_info', function()
|
||||
describe('nvim_get_all_options_info', function()
|
||||
it('should have key value pairs of option names', function()
|
||||
local options_info = meths.get_options_info()
|
||||
local options_info = meths.get_all_options_info()
|
||||
neq(nil, options_info.listchars)
|
||||
neq(nil, options_info.tabstop)
|
||||
|
||||
eq(meths.get_option_info'winhighlight', options_info.winhighlight)
|
||||
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'))
|
||||
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')
|
||||
)
|
||||
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)
|
||||
eq({
|
||||
commalist = false;
|
||||
default = "";
|
||||
flaglist = false;
|
||||
global_local = false;
|
||||
last_set_chan = 0;
|
||||
last_set_linenr = 0;
|
||||
last_set_sid = 0;
|
||||
name = "winhighlight";
|
||||
scope = "win";
|
||||
shortname = "winhl";
|
||||
type = "string";
|
||||
was_set = false;
|
||||
}, meths.get_option_info'winhl')
|
||||
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)
|
||||
eq({
|
||||
commalist = false,
|
||||
default = "",
|
||||
flaglist = false,
|
||||
global_local = false,
|
||||
last_set_chan = 0,
|
||||
last_set_linenr = 0,
|
||||
last_set_sid = 0,
|
||||
name = "filetype",
|
||||
scope = "buf",
|
||||
shortname = "ft",
|
||||
type = "string",
|
||||
was_set = false
|
||||
}, meths.get_option_info'filetype')
|
||||
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)
|
||||
-- precondition: the option was changed from its default
|
||||
-- in test setup.
|
||||
eq(false, meths.get_option'showcmd')
|
||||
|
||||
eq({
|
||||
commalist = false,
|
||||
default = true,
|
||||
flaglist = false,
|
||||
global_local = false,
|
||||
last_set_chan = 0,
|
||||
last_set_linenr = 0,
|
||||
last_set_sid = -2,
|
||||
name = "showcmd",
|
||||
scope = "global",
|
||||
shortname = "sc",
|
||||
type = "boolean",
|
||||
was_set = true
|
||||
}, meths.get_option_info'showcmd')
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user