Skip to content
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

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

van800
Copy link
Contributor

@van800 van800 commented Jan 16, 2024

Fixes JetBrains/godot-support#81

Discussion:
https://chat.godotengine.org/channel/dotnet?msg=dtyXNTdDNij3S7Jvr

I have also added a code-fix
image
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:
image
New behaviour:
image

@van800
Copy link
Contributor Author

van800 commented Jan 20, 2024

@raulsntos I have cherry-picked your change from #87342

Copy link
Member

@paulloz paulloz left a 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.

@paulloz
Copy link
Member

paulloz commented Jan 26, 2024

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 Common.cs at the moment (e.g., we're defining diagnostics as static readonly, but not using them depending on from where it is reported, see here).

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).

@van800
Copy link
Contributor Author

van800 commented Feb 15, 2024

@paulloz please take another look, when you have time. I haven't changed anything, just the #87342 was merged, and I rebased on top of master.
I think the code sets a good UX for both Rider and VSCode and sets a good example of roslyn quick fix and tests for analyzer and quick fix.

Copy link
Member

@paulloz paulloz left a 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.

@raulsntos
Copy link
Member

raulsntos commented Feb 17, 2024

The only thing I'm a bit scared about is users will now be able to compile broken projects by suppressing GD0001

@paulloz The project should still not compile if we are generating partials of a class not marked as partial.

@paulloz
Copy link
Member

paulloz commented Feb 17, 2024

But we are skipping non partial classes, so we won't generate the partials.

@raulsntos
Copy link
Member

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.

@van800 van800 force-pushed the van800/analyser branch 2 times, most recently from fe50497 to 542e0da Compare February 18, 2024 16:45
@van800
Copy link
Contributor Author

van800 commented Feb 18, 2024

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?

@AThousandShips
Copy link
Member

AThousandShips commented Feb 18, 2024

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

@van800
Copy link
Contributor Author

van800 commented Feb 19, 2024

I have also rewritten the GD0002.

@van800 van800 force-pushed the van800/analyser branch 2 times, most recently from 7eb9fdf to 557602c Compare February 19, 2024 10:52
@van800 van800 changed the title Provide a roslyn analyzer corresponding to the GD0001 Provide a roslyn analyzers corresponding to the GD0001 and GD0002 Feb 19, 2024
@paulloz
Copy link
Member

paulloz commented Feb 20, 2024

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]

This isn't happening any more 👍

@raulsntos raulsntos modified the milestones: 4.x, 4.3 Feb 21, 2024
Copy link
Member

@raulsntos raulsntos left a 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!

@akien-mga
Copy link
Member

Could you squash the commits? See PR workflow for instructions.

@van800 van800 force-pushed the van800/analyser branch 2 times, most recently from fd19b76 to 5dd3db2 Compare February 21, 2024 09:21
…tialModifierAnalyzerFix, and tests

Co-authored-by: Raul Santos <raulsntos@gmail.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@akien-mga akien-mga merged commit c6d091e into godotengine:master Feb 21, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GD0001: partial modifier static analysis for Godot 4
5 participants