mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Source gen reorganizations + component unpause generator. This commit (and subsequent commits) aims to clean up our Roslyn plugin (source gens + analyzers) stack to more sanely re-use common code I also built a new source-gen that automatically generates unpausing implementations for components, incrementing attributed TimeSpan field when unpaused. * Fix warnings in all Roslyn projects
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.Diagnostics;
|
|
using Robust.Roslyn.Shared;
|
|
|
|
namespace Robust.Analyzers
|
|
{
|
|
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
|
public class MeansImplicitAssigmentSuppressor : DiagnosticSuppressor
|
|
{
|
|
const string MeansImplicitAssignmentAttribute = "Robust.Shared.MeansImplicitAssignmentAttribute";
|
|
|
|
public override void ReportSuppressions(SuppressionAnalysisContext context)
|
|
{
|
|
var implAttr = context.Compilation.GetTypeByMetadataName(MeansImplicitAssignmentAttribute);
|
|
foreach (var reportedDiagnostic in context.ReportedDiagnostics)
|
|
{
|
|
if(reportedDiagnostic.Id != Diagnostics.MeansImplicitAssignment.SuppressedDiagnosticId) continue;
|
|
|
|
var node = reportedDiagnostic.Location.SourceTree?.GetRoot(context.CancellationToken).FindNode(reportedDiagnostic.Location.SourceSpan);
|
|
if (node == null) continue;
|
|
|
|
var symbol = context.GetSemanticModel(reportedDiagnostic.Location.SourceTree).GetDeclaredSymbol(node);
|
|
|
|
if (symbol == null || !symbol.GetAttributes().Any(a =>
|
|
a.AttributeClass?.GetAttributes().Any(attr =>
|
|
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, implAttr)) == true))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
context.ReportSuppression(Suppression.Create(
|
|
Diagnostics.MeansImplicitAssignment,
|
|
reportedDiagnostic));
|
|
}
|
|
}
|
|
|
|
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions => ImmutableArray.Create(Diagnostics.MeansImplicitAssignment);
|
|
}
|
|
}
|