-
Notifications
You must be signed in to change notification settings - Fork 1.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
MVVM Toolkit vNext: source generators #3873
MVVM Toolkit vNext: source generators #3873
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
618d250
to
f9987b3
Compare
bc79e56
to
ef8cbb0
Compare
682179b
to
0d739ca
Compare
bfc7d90
to
4e2796b
Compare
4e2796b
to
315bdd1
Compare
44b2a66
to
3c7c7d5
Compare
|
||
if (index != -1) | ||
{ | ||
return memberDeclaration.WithModifiers(memberDeclaration.Modifiers.RemoveAt(index)); |
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.
This may not preserve trivia if the removed modifier has any. No idea if that's okay, but wanted to note.
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.
Ah, good catch. Yeah that's fine, the generation step doesn't care about trivia at all (also to make things simpler). When we actually generate code at the end we just call NormalizeWhitespace()
anyway that will fix everything 🙂
{ | ||
string propertyName = methodSymbol.Name; | ||
|
||
if (SymbolEqualityComparer.Default.Equals(methodSymbol.ReturnType, context.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task")!) && |
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.
Why a suppression is needed? Equals parameters are null annotated
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.
Ah, you're right, thanks! Fixed in e97a60b.
I think I had originally added that suppression due to missing annotations with some older preview version of the Roslyn NuGet packages, and tghen forgot to go back and remove that here after updating the references 😄
Improved type safety, more AOT-friendly, removed Unsafe.As<T> hack
Doing this enables the JIT to devirtualize function calls through the property
Co-authored-by: Michael Hawker MSFT (XAML Llama) <24302614+michael-hawker@users.noreply.github.com>
16ba7cc
to
eb0b475
Compare
Added more info and remarks about field name conversion
Thanks @Sergio0694 looks good to me. I've been playing with them already, never going to go back! 🦙❤ @XAML-Knight think you'll find this interesting too. Feel free to give it a quick go around. |
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.
Impressive check-in - I found a couple of small items.
[NotNullWhen(false)] out DiagnosticDescriptor? descriptor) | ||
{ | ||
INamedTypeSymbol | ||
observableRecipientSymbol = context.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.ComponentModel.ObservableRecipient")!, |
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'd recommend continuing to pass in the FullName of the Type, versus relying upon magic strings, where possible
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.
"where possible" is the key phrase here, of course :)
} | ||
} | ||
|
||
INamedTypeSymbol observableValidatorSymbol = context.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.ComponentModel.ObservableValidator")!; |
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.
Same as above, recommend sending in FullName of the Type
{ | ||
if (context.Node is ClassDeclarationSyntax classDeclaration && | ||
context.SemanticModel.GetDeclaredSymbol(classDeclaration) is INamedTypeSymbol { IsGenericType: false } classSymbol && | ||
context.SemanticModel.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.ComponentModel.ObservableValidator") is INamedTypeSymbol validatorSymbol && |
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.
Same as above, recommend sending in FullName of the Type
} | ||
|
||
// Get the symbol for the ValidationAttribute type | ||
INamedTypeSymbol validationSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute")!; |
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.
Same as above, recommend sending in FullName of the Type
{ | ||
if (context.Node is ClassDeclarationSyntax classDeclaration && | ||
context.SemanticModel.GetDeclaredSymbol(classDeclaration) is INamedTypeSymbol { IsGenericType: false } classSymbol && | ||
context.SemanticModel.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.Messaging.IRecipient`1") is INamedTypeSymbol iRecipientSymbol && |
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 can see why you're just passing in a string value, here
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
Adding the type name of the generator is not necessary since Visual Studio already groups generated sources for each individual generator, which also automatically avoids conflicts
Hey @XAML-Knight, thank you for having a look, glad you liked the PR! 😄 Let me give some context as to why I was using those hardcoded strings instead of using The short version of why those usages you've highlighted in your review comments weren't using Hope this helps! 😄 |
[NotNullWhen(false)] out DiagnosticDescriptor? descriptor) | ||
{ | ||
INamedTypeSymbol | ||
observableRecipientSymbol = context.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.ComponentModel.ObservableRecipient")!, |
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.
"where possible" is the key phrase here, of course :)
Thanks for the detailed explanation, @Sergio0694 PR Approved |
@XAML-Knight No worries, glad I could help! And yeah for sure, I did see that "where possible", just figured it would be useful to share some additional context in here instead of just saying "yeah it's not possible here", either for you in case you weren't super familiar with source generators yet (as they're pretty new, or more like, still in preview themselves ahah), as well as others possibly reading through this PR. Glad everything makes sense, thank you for the review! 🙌 |
(🦙) Testing something for Discord Preview, please ignore this text at the top for now while we test it. Thanks! This is going to be great feature in the Toolkit, can't wait! (🦙)
Contributes to #3872
PR Type
What kind of change does this PR introduce?
Changelog
Changes discussed/tracked in the linked issue.
PR Checklist
Please check if your PR fulfills the following requirements: