-
-
Notifications
You must be signed in to change notification settings - Fork 21.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
Provide a roslyn analyzers corresponding to the GD0001 and GD0002 #87253
Conversation
d3419d8
to
9a4748e
Compare
9a4748e
to
cadd17d
Compare
@raulsntos I have cherry-picked your change from #87342 |
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.
As discussed previously, this moves the diagnostics we were reporting from within the generators to its own analyzer, right? Essentially doing the job twice (i.e. the generator is already visiting all those classes, and now the analyzer does too).
I think we could probably report only from ScriptPathAttributeGenerator
, and fix the source location to not underline the entire class.
Actually, the more I think about it, the more I'm back to thinking that moving all of our diagnostics to their own analyzers is a good idea. At the same time, we could clean the mess that is It'd also reduce the work done by incremental generators once #64899 is a thing. Not to mention that the eventual shift to a GDExtension implementation, as far as I understand, will mean the generated content will be vastly different (the generators are going to change), while the public API should stay compatible (the analyzers/diagnostics should stay the same). |
752fbb5
to
a17ec21
Compare
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 have a CSC error about this analyzer, both when compiling Godot.SourceGenerators
, and when opening Godot afterwards. Not entirely sure why.
CSC : warning CS8032: An instance of analyzer Godot.SourceGenerators.ClassPartialModifierAnalyzer cannot be created from E:\Godot Worktree\godot\modules\mono\editor\G
odot.NET.Sdk\Godot.SourceGenerators\bin\Release\netstandard2.0\Godot.SourceGenerators.dll : Could not load type 'Godot.SourceGenerators.ClassPartialModifierAnalyzer'
from assembly 'Godot.SourceGenerators, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null'.. [E:\Godot Worktree\godot\modules\mono\editor\Godot.NET.Sdk\Godot.Sourc
eGenerators.Sample\Godot.SourceGenerators.Sample.csproj]
Apart from that, it seems fine.
The only thing I'm a bit scared about is users will now be able to compile broken projects by suppressing GD0001
. We say that it shouldn't be suppressed, but still... I wonder if we should find a way to still block compilation here (with something additionally reporting at Location.None
, or IDK).
Would be nice for #88295 to be merged before, to prevent regressions. And maybe #80343 too.
...s/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/ClassPartialModifierAnalyzerTest.cs
Outdated
Show resolved
Hide resolved
.../Godot.SourceGenerators.Tests/TestData/GeneratedSources/ClassPartialModifier.GD0001.fixed.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
@paulloz The project should still not compile if we are generating partials of a class not marked as partial. |
But we are skipping non partial classes, so we won't generate the partials. |
We probably shouldn't, otherwise that means we're still checking if the class is partial in the generator and we said we were moving the check to the analyzer. That said, it's probably fine to keep the skipping behavior in this PR, changing it is tricky because it's kind of mixed with GD0002 which would increase the scope of this PR. GD0002 should probably be included in the GD0001 analyzer anyway, but I didn't want to delay this PR further. And to be honest, I don't expect users to disable this diagnostic, doing so would be ignoring an error in your code so whatever happens after that can be considered undefined behavior. |
fe50497
to
542e0da
Compare
Thank you for the review and all the suggestions, I have also cleaned up redundant sealed modifiers and did a cosmetic fix, which bugged me: trimmed the repeating part of Description. Unfortunately the practice of preparing just one commit pull request makes it harder for you to follow, what was changed. For the future, should I keep multiple commits and squash them after the review? |
When this is ready to merge you will need to squash :) you can do it now but there will be some code style review once this has been approved (sorry missed you had squashed and thought you asked if you needed to, in the future you will need to always before merge, but until then it's fine to keep separate commits, though generally keep it simple to not clutter) Also in the future try using the batch suggestions to avoid making multiple commits from suggestions |
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
...r/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ClassPartialModifier.GD0001.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj
Outdated
Show resolved
Hide resolved
33882b7
to
5c35059
Compare
5c35059
to
d3f40a4
Compare
I have also rewritten the GD0002. |
7eb9fdf
to
557602c
Compare
557602c
to
0c137d8
Compare
...dk/Godot.SourceGenerators.Tests/TestData/Sources/OuterClassPartialModifierAnalyzer.GD0002.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/OuterClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
This isn't happening any more 👍 |
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
Outdated
Show resolved
Hide resolved
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.
Looks good to me. Thanks!
Could you squash the commits? See PR workflow for instructions. |
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/CSharpCodeFixVerifier.cs
Outdated
Show resolved
Hide resolved
fd19b76
to
5dd3db2
Compare
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ClassPartialModifierAnalyzer.cs
Outdated
Show resolved
Hide resolved
…tialModifierAnalyzerFix, and tests Co-authored-by: Raul Santos <raulsntos@gmail.com> Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
49d5532
to
00dc195
Compare
Thanks! |
Fixes JetBrains/godot-support#81
Discussion:
https://chat.godotengine.org/channel/dotnet?msg=dtyXNTdDNij3S7Jvr
I have also added a code-fix
Tried it in Rider and VScode
Benefit for vscode users is that report from analyzer is much nicer then multiple reports from generators.
Old behaviour:
New behaviour: