mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 08:56:29 +00:00
api/options: fixup
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user