-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert most of our JSON deserializers to use type-based conversion #6590
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm certainly not about to block this while I'm gone, though, there are still TODOs and I've got questions, so I'm just gonna "comment"
{ "keys": ["ctrl+g"], "command": { "action": "splitPane" } }, | ||
{ "keys": ["ctrl+h"], "command": { "action": "splitPane", "split": "auto" } }, | ||
{ "keys": ["ctrl+i"], "command": { "action": "splitPane", "split": "foo" } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add back a test case that ensures a warning was returned for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this causes a whole settings parsing failure... but the specific case of deserializing an unknown enum member is actually handled in the JsonUtilsTests. Should we have one specifically for a "known type of flag"?
@@ -334,6 +363,18 @@ namespace TerminalApp::JsonUtils | |||
template<typename T, typename Converter> | |||
bool GetValue(const Json::Value& json, T& target, Converter&& conv) | |||
{ | |||
if constexpr (Detail::DeduceOptional<T>::IsOptional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wat the heck is this witchcraft
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if constexpr
is SO GOOD. It's like, "only compile this block of code if this thing is true"
it's like std::enable_if
but for an actual individual block of code instead of how enable_if uses the failure of a type to be well-formed to "hide" it from existence
6122eb8
to
f20b623
Compare
…6890) This commit updates JsonUtilsNew to support winrt `Windows::Foundation::IReference<T>` as an option type, and cleans up the optional support code by removing the optional overload on `GetValue(...)`. Instead of using an overload with a partial specialization, we're using a constexpr if with a type trait to determine option-type-ness. In addition, Carlos reported an issue with deriving from `FlagMapper` (itself templated) and referring to the base type's members without fully qualifying them. To make derivation easier, `EnumMapper` and `FlagMapper` now provide `BaseEnumMapper` and `BaseFlagMapper` type aliases. I've taken the opportunity to add a `winrt::hstring` conversion trait. Lastly, in casual use, I found out that I'd written the til::color converter wrong: it supports color strings of length 7 (`#rrggbb`) and length 4 (`#rgb`). I mistyped (and failed to test) support for 4-length color strings by pretending they were only 3 characters long. ## References Merged JsonUtils changes from #6004 and #6590. ## PR Checklist * [x] Unblocks aforementioned PRs * [x] cla * [x] Tests added/passed * [x] Documentation N/A * [x] Schema N/A * [x] Kid tested, mother approved.
x include the profile traits? PRO: remove -DH, switch smth to value PRO: remove spaces PCT: non-static PCT
GAS: remove -DH GAS: nonstatic GAS
f20b623
to
16ab0ae
Compare
Move all settings types out of globalapp/profile into SettingsTypes. **EVENTUALLY** they will become exported types from the Terminal Settings Model library. This is a temporary stopgap. I added a ValueType convenience helper to EnumMapper so you don't have to repeat a really obscenely long fully-qualified namespace name for every mapped value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ship this, this is great. It'll break all the in-flight PRs, but hey, lets just do it.
forgot the ones in binding serialization, thanks |
Net code removed: 773 lines. |
I am blocking this until 1.3. |
Hello @DHowett! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
🎉 Handy links: |
This pull request converts the following JSON deserializers to use the
new JSON deserializer pattern:
This is the completion of a long-term JSON refactoring that makes our
parser and deserializer more type-safe and robust. We're finally able to
get rid of all our manual enum conversion code and unify JSON conversion
around types instead of around keys.
I've introduced another file filled with template specializations,
TerminalSettingsSerializationHelpers.h, which comprises a single unit
that holds all of the JSON deserializers (and eventually serializers)
for every type that comes from TerminalApp or TerminalSettings.
I've also moved some types out of Profile and GlobalAppSettings into a
new SettingsTypes.h to improve settings locality.
This does to some extent constitute a breaking change for already-broken
settings. Instead of parsing "successfully" (where invalid values are
null or 0 or unknown or unset), deserialization will now fail when
there's a type mismatch. Because of that, some tests had to be removed.
While I was on a refactoring spree, I removed a number of helpless
helpers, like GetWstringFromJson (which converted a u8 string to an
hstring to make a wstring out of its data pointer :|) and
_ConvertJsonToBool.
In the future, we can make the error types more robust and give them
position and type information such that a conformant application can
display rich error information ("line 3 column 3, I expected a string,
you gave me an integer").
Closes #2550.