fix(api): allow scope = 'local' with buf when using nvim_get_option_value

`nvim_get_option_value` throws a warning if both `scope` and `buf`
options are used at the same time. This is because using `buf` always
implies `scope` is local, and is therefore not needed. There's however
no need to error if `scope` is already set "local" as it's the correct
value.
This commit is contained in:
dundargoc
2024-06-09 15:59:44 +02:00
committed by dundargoc
parent 20f22f75ee
commit 743c5808b6

View File

@@ -54,6 +54,10 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
} }
if (HAS_KEY_X(opts, buf)) { if (HAS_KEY_X(opts, buf)) {
VALIDATE(!(HAS_KEY_X(opts, scope) && *scope == OPT_GLOBAL), "%s",
"cannot use both global 'scope' and 'buf'", {
return FAIL;
});
*scope = OPT_LOCAL; *scope = OPT_LOCAL;
*req_scope = kOptReqBuf; *req_scope = kOptReqBuf;
*from = find_buffer_by_handle(opts->buf, err); *from = find_buffer_by_handle(opts->buf, err);
@@ -68,11 +72,6 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
return FAIL; return FAIL;
}); });
VALIDATE((!HAS_KEY_X(opts, scope) || !HAS_KEY_X(opts, buf)), "%s",
"cannot use both 'scope' and 'buf'", {
return FAIL;
});
VALIDATE((!HAS_KEY_X(opts, win) || !HAS_KEY_X(opts, buf)), VALIDATE((!HAS_KEY_X(opts, win) || !HAS_KEY_X(opts, buf)),
"%s", "cannot use both 'buf' and 'win'", { "%s", "cannot use both 'buf' and 'win'", {
return FAIL; return FAIL;