-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Try to generate more meaningful names in json converter #17115
Conversation
*count += 1; | ||
*count | ||
} else { | ||
self.names.insert(name.clone(), 1); |
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 don't want to copy if name exists, so this long if
I just remembered, that the name in json can be invalid struct name... I'll try to find a way to check that I guess |
Actually, the old code fails at this too, because it doesn't fix the names for struct member variables... |
Thanks! |
☀️ Test successful - checks-actions |
I just found out about rust-analyzer json converter, but I think it would be more convenient, if names were more useful, like using the names of the keys.
Let's look at some realistic arbitrary json:
I think, new generated code is much easier to read and to edit, than the old:
Ideally, if we drop the numbers, I can see it being usable just as is (may be rename root)
Sadly, we can't just drop them, because there can be multiple fields (recursive) with the same name, and we can't just easily retroactively add numbers if the name has 2 instances due to parsing being single pass.
We could ignore the
1
and add number only if it's > 1, but I will leave this open to discussion and right now made it the simpler wayIn sum, even with numbers, I think this PR still helps in readability