diff options
author | Famiu Haque <famiuhaque@proton.me> | 2024-10-29 03:21:33 +0600 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-11-02 15:53:49 +0000 |
commit | 86e54734bf9e05605d8b7146e7b0e79025138ba2 (patch) | |
tree | 3d59b1d7266f48cf869777c72c330fdaa87fba75 /src/nvim/api/deprecated.c | |
parent | 3688a333544251c887d78e6501eec55f0fb685f8 (diff) | |
download | rneovim-86e54734bf9e05605d8b7146e7b0e79025138ba2.tar.gz rneovim-86e54734bf9e05605d8b7146e7b0e79025138ba2.tar.bz2 rneovim-86e54734bf9e05605d8b7146e7b0e79025138ba2.zip |
refactor(options): remove `get_option_value_strict`
Problem: `get_option_value_for` can perfectly replace `get_option_value_strict`, making the latter redundant.
Solution: Remove `get_option_value_strict`
Diffstat (limited to 'src/nvim/api/deprecated.c')
-rw-r--r-- | src/nvim/api/deprecated.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index 6376011106..5c0d9c0cea 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -633,6 +633,40 @@ 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); + + // Hidden option. + if (opt->var == NULL) { + return false; + } + // 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 +681,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, { |