diff options
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/deprecated.c | 42 | ||||
-rw-r--r-- | src/nvim/api/options.c | 5 |
2 files changed, 41 insertions, 6 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index 6376011106..b3ba832fec 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -633,6 +633,36 @@ void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object set_option_to(channel_id, win, kOptReqWin, name, value, err); } +/// Check if option has a value in the requested scope. +/// +/// @param opt_idx Option index in options[] table. +/// @param req_scope Requested option scope. See OptReqScope in option.h. +/// +/// @return true if option has a value in the requested scope, false otherwise. +static bool option_has_scope(OptIndex opt_idx, OptReqScope req_scope) +{ + if (opt_idx == kOptInvalid) { + return false; + } + + vimoption_T *opt = get_option(opt_idx); + + // TTY option. + if (is_tty_option(opt->fullname)) { + return req_scope == kOptReqGlobal; + } + + switch (req_scope) { + case kOptReqGlobal: + return opt->var != VAR_WIN; + case kOptReqBuf: + return opt->indir & PV_BUF; + case kOptReqWin: + return opt->indir & PV_WIN; + } + UNREACHABLE; +} + /// Gets the value of a global or local (buffer, window) option. /// /// @param[in] from Pointer to buffer or window for local option value. @@ -647,9 +677,15 @@ static Object get_option_from(void *from, OptReqScope req_scope, String name, Er return (Object)OBJECT_INIT; }); - OptVal value = get_option_value_strict(find_option(name.data), req_scope, from, err); - if (ERROR_SET(err)) { - return (Object)OBJECT_INIT; + OptIndex opt_idx = find_option(name.data); + OptVal value = NIL_OPTVAL; + + if (option_has_scope(opt_idx, req_scope)) { + value = get_option_value_for(opt_idx, req_scope == kOptReqGlobal ? OPT_GLOBAL : OPT_LOCAL, + req_scope, from, err); + if (ERROR_SET(err)) { + return (Object)OBJECT_INIT; + } } VALIDATE_S(value.type != kOptValTypeNil, "option name", name.data, { diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 1a0edd551e..96866d80ba 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -80,7 +80,7 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex * *opt_idxp = find_option(name); int flags = get_option_attrs(*opt_idxp); if (flags == 0) { - // hidden or unknown option + // unknown option api_set_error(err, kErrorTypeValidation, "Unknown option '%s'", name); } else if (*req_scope == kOptReqBuf || *req_scope == kOptReqWin) { // if 'buf' or 'win' is passed, make sure the option supports it @@ -175,7 +175,6 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) } OptVal value = get_option_value_for(opt_idx, scope, req_scope, from, err); - bool hidden = is_option_hidden(opt_idx); if (ftbuf != NULL) { // restore curwin/curbuf and a few other things @@ -189,7 +188,7 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) goto err; } - VALIDATE_S(!hidden && value.type != kOptValTypeNil, "option", name.data, { + VALIDATE_S(value.type != kOptValTypeNil, "option", name.data, { goto err; }); |