-
Notifications
You must be signed in to change notification settings - Fork 5
Make it an Incremental Source Generator #6
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
Open
Hamunii
wants to merge
23
commits into
BepInEx:master
Choose a base branch
from
Hamunii:incremental-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7385f20
strip version metadata for BepInEx 5
Hamunii 437436f
fix not setting version if not BepInEx 5
Hamunii 9438783
make it incremental
Hamunii a6c5eb1
add .g.cs to BepInAutoPluginAttribute source
Hamunii 517f349
target oldest roslyn version possible for maximum support
Hamunii 5d8e3db
remove probably stupid code
Hamunii 74bc4ad
resolve most issues
Hamunii f079d14
upgrade to latest CodeAnalysis references
Hamunii 1f5b443
don't generate for invalid classes
Hamunii 3f6098f
introduce analyzer for missing partial modifier
Hamunii d7e3b44
more proper nullable handling
Hamunii 94ab940
change ToPluginClass nullability handling
Hamunii 0fbea64
make record structs readonly
Hamunii a0d9942
downgrade Microsoft.CodeAnalysis.CSharp to oldest supported version
Hamunii 09d2f61
this needs to be changed due to the downgraded version, whoops
Hamunii 1ce922b
use ds5678's method for analyzer
Hamunii 872ad75
cleanup
Hamunii e62cd4b
update readme to be more comprehensive
Hamunii 211dfb0
use Title for project name with Product as a fallback
Hamunii 808b719
take info from assembly attributes instead & reintroduce BepInAutoPlu…
Hamunii 1793b01
update readme to be up to date again
Hamunii d7961dc
switch from using FAWMN for getting attribute arguments
Hamunii a7e309c
ignore all warnings in generated file
Hamunii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| artifacts/ | ||
| bin/ | ||
| obj/ | ||
| /packages/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ; Shipped analyzer releases | ||
| ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; Unshipped analyzer release | ||
| ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md | ||
|
|
||
| ### New Rules | ||
|
|
||
| Rule ID | Category | Severity | Notes | ||
| --------|----------|----------|------- | ||
| AutoPlugin0001 | BepInEx.AutoPlugin | Warning | AutoPluginAnalyzer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| using System.Collections.Immutable; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
|
|
||
| namespace BepInEx.AutoPlugin.Analyzers; | ||
|
|
||
| [DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
| public sealed class PluginClassAnalyzer : DiagnosticAnalyzer | ||
| { | ||
| const string Category = "BepInEx.AutoPlugin"; | ||
|
|
||
| public static readonly DiagnosticDescriptor PluginClassMustBeMarkedPartial = new( | ||
| "AutoPlugin0001", | ||
| "Plugin class must be marked partial", | ||
| "Plugin class '{0}' must be marked partial for use with AutoPlugin", | ||
| Category, | ||
| DiagnosticSeverity.Warning, | ||
| isEnabledByDefault: true | ||
| ); | ||
|
|
||
| public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = | ||
| ImmutableArray.Create(PluginClassMustBeMarkedPartial); | ||
|
|
||
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); | ||
| context.EnableConcurrentExecution(); | ||
|
|
||
| context.RegisterSymbolAction(AnalyzeClassSymbol, SymbolKind.NamedType); | ||
| } | ||
|
|
||
| static void AnalyzeClassSymbol(SymbolAnalysisContext context) | ||
| { | ||
| var typeSymbol = (INamedTypeSymbol)context.Symbol; | ||
|
|
||
| bool isNotClassOrIsPartialClass = typeSymbol.DeclaringSyntaxReferences.All( | ||
| static syntaxReference => | ||
| syntaxReference.GetSyntax() is not ClassDeclarationSyntax classSyntax | ||
| || classSyntax.Modifiers.Any(SyntaxKind.PartialKeyword) | ||
| ); | ||
|
|
||
| if (isNotClassOrIsPartialClass) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| foreach (AttributeData attribute in typeSymbol.GetAttributes()) | ||
| { | ||
| var attributeClass = attribute.AttributeClass; | ||
| if (attributeClass is null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| switch (attributeClass.Name) | ||
| { | ||
| case AutoPluginGenerator.BepInAutoPluginAttributeName: | ||
| string attributeFullName = attributeClass.ToDisplayString(); | ||
| if (attributeFullName != AutoPluginGenerator.BepInAutoPluginAttributeFullName) | ||
| { | ||
| continue; | ||
| } | ||
| break; | ||
|
|
||
| case AutoPluginGenerator.PatcherAutoPluginAttributeName: | ||
| attributeFullName = attributeClass.ToDisplayString(); | ||
| if (attributeFullName != AutoPluginGenerator.PatcherAutoPluginAttributeFullName) | ||
| { | ||
| continue; | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| continue; | ||
| } | ||
|
|
||
| if ( | ||
| attribute.ApplicationSyntaxReference?.GetSyntax() | ||
| is not AttributeSyntax attributeSyntax | ||
| ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if ( | ||
| attributeSyntax.Parent is not AttributeListSyntax attributeList | ||
| || attributeList.Parent is not ClassDeclarationSyntax classDeclaration | ||
| ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var diagnostic = Diagnostic.Create( | ||
| PluginClassMustBeMarkedPartial, | ||
| classDeclaration.Identifier.GetLocation(), | ||
| classDeclaration.Identifier.ToString() | ||
| ); | ||
|
|
||
| context.ReportDiagnostic(diagnostic); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.