Skip to content

Commit

Permalink
refactor(options): remove getoption_T and introduce OptVal (#23850)
Browse files Browse the repository at this point in the history
Removes the `getoption_T` struct and also introduces the `OptVal` struct
to unify the methods of getting/setting different option value types.
This is the first of many PRs to reduce code duplication in the Vim
option code as well as to make options easier to maintain. It also
increases the flexibility and extensibility of options. Which opens the
door for things like Array and Dictionary options.
  • Loading branch information
famiu committed Jun 7, 2023
1 parent 0370e4d commit b3d5138
Show file tree
Hide file tree
Showing 29 changed files with 672 additions and 367 deletions.
11 changes: 5 additions & 6 deletions src/nvim/api/deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,13 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
}
}

long numval = 0;
char *stringval = NULL;
OptVal optval = NIL_OPTVAL;

if (flags & SOPT_BOOL) {
VALIDATE(value.type == kObjectTypeBoolean, "Option '%s' value must be Boolean", name.data, {
return;
});
numval = value.data.boolean;
optval = BOOLEAN_OPTVAL(value.data.boolean);
} else if (flags & SOPT_NUM) {
VALIDATE(value.type == kObjectTypeInteger, "Option '%s' value must be Integer", name.data, {
return;
Expand All @@ -725,12 +724,12 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
"Option '%s' value is out of range", name.data, {
return;
});
numval = (int)value.data.integer;
optval = NUMBER_OPTVAL(value.data.integer);
} else {
VALIDATE(value.type == kObjectTypeString, "Option '%s' value must be String", name.data, {
return;
});
stringval = value.data.string.data;
optval = STRING_OPTVAL(value.data.string);
}

// For global-win-local options -> setlocal
Expand All @@ -739,6 +738,6 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
(type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;

WITH_SCRIPT_CONTEXT(channel_id, {
access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
set_option_value_for(name.data, optval, opt_flags, type, to, err);
});
}
Loading

0 comments on commit b3d5138

Please sign in to comment.