fix(api): make nil value in nvim_set_option_value clear local value (#16710)

For special options such as 'undolevels' and 'scrolloff', this sets the
local value to the special "unset" value (e.g. -12345 for 'undolevels').
This commit is contained in:
Gregory Anders
2021-12-21 14:20:34 -07:00
committed by GitHub
parent 1b04da52b3
commit 33cd1ba00a
4 changed files with 66 additions and 5 deletions

View File

@@ -696,7 +696,17 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
rv = INTEGER_OBJ(numval);
break;
case 2:
rv = BOOLEAN_OBJ(!!numval);
switch (numval) {
case 0:
case 1:
rv = BOOLEAN_OBJ(numval);
break;
default:
// Boolean options that return something other than 0 or 1 should return nil. Currently this
// only applies to 'autoread' which uses -1 as a local value to indicate "unset"
rv = NIL;
break;
}
break;
default:
api_set_error(err, kErrorTypeValidation, "unknown option '%s'", name.data);
@@ -749,7 +759,7 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
stringval = value.data.string.data;
break;
case kObjectTypeNil:
// Do nothing
scope |= OPT_CLEAR;
break;
default:
api_set_error(err, kErrorTypeValidation, "invalid value for option");