This namespace allows you to report or suppress diagnostics from your aspect code.
Conceptual Documentation
Refer to Reporting and suppressing diagnostics.
Class diagram
classDiagram
class SuppressionDefinition {
SuppressedDiagnosticId
}
class ScopedDiagnosticSink {
Report(IDiagnosticLocation, IDiagnostic)
Suppress(IDiagnosticLocation, SuppressionDefinition)
Suggest(IDiagnosticLocation, CodeFix)
}
class ScopedDiagnosticSink {
Declaration
Location
Report(IDiagnostic)
Suppress(SuppressionDefinition)
Suggest(CodeFix)
}
class DiagnosticSeverity {
None
Hidden
Information
Warning
Error
}
class IDiagnostic {
Id
Message
Title
Category
Severity
CodeFixes
WithCodeFixes(CodeFix[])
}
class CodeFix {
}
IDiagnostic *-- CodeFix : can contain
DiagnosticDefinition~T~ <|-- `DiagnosticDefinition ` : derives from
class `DiagnosticDefinition ` {
}
class DiagnosticDefinition~T~ {
Id
Category
Severity
MessageFormat
Title
WithArguments(T) IDiagnostic
}
class IAspectBuilder {
Diagnostics
}
class ValidationContext {
Diagnostics
}
IDiagnostic <|.. `DiagnosticDefinition ` : implements
IDiagnostic <.. DiagnosticDefinition~T~ : WithArguments instantiates
DiagnosticSeverity <-- IDiagnostic : Severity
IDiagnostic <.. ScopedDiagnosticSink : accepts
SuppressionDefinition <.. ScopedDiagnosticSink : accepts
CodeFix <.. ScopedDiagnosticSink : accepts
ScopedDiagnosticSink <-- IAspectBuilder : exposes
ScopedDiagnosticSink <-- ValidationContext : exposes
CodeFix <-- CodeFixFactory : creates
Reporting diagnostics
To report a diagnostic, first define a static field of type DiagnosticDefinition or DiagnosticDefinition<T> in your aspect class. Use DiagnosticDefinition for parameterless diagnostics, and DiagnosticDefinition<T> for parametric diagnostics.
To report parametric diagnostics, first call the WithArguments method. This step is not necessary for parameterless diagnostics.
To report a diagnostic, call the Report method. This object is exposed on the Diagnostics property of the argument of the IAspectBuilder.BuildAspect method of your aspect. You can also report a diagnostic from a validator.
When reporting a diagnostic, you can specify the location of the diagnostic, i.e., the code element to which it will be reported (which determines the file and line of the error message). If you don't specify the location, the default location for the current context will be used.
You can add code fixes to diagnostics. For details, refer to the Metalama.Extensions.CodeFixes namespace.
Suppressing diagnostics
To suppress a diagnostic, first define it as a static field of type SuppressionDefinition in your aspect class. You can then suppress a diagnostic from any declaration from an aspect using the Suppress method.
For more information, refer to Reporting and suppressing diagnostics.
Suggesting code actions
Refer to Metalama.Extensions.CodeFixes.
Namespace members
Classes
CodeFixHelper
Provides helper members for working with code fixes in diagnostics.
DiagnosticDefinition
Defines a diagnostic that does not accept any parameters. For diagnostics with parameters, use DiagnosticDefinition<T>.
DiagnosticDefinition<T>
Defines a diagnostic with strongly-typed parameters.
DiagnosticsQueryExtensions
Extension methods for IQuery<TDeclaration> and ITaggedQuery<TDeclaration, TTag> that enable reporting and suppressing diagnostics on sets of declarations in fabrics.
SuppressionDefinition
Defines a diagnostic suppression that can be applied by aspect code to prevent specific compiler or analyzer diagnostics from being reported in target code.
Structs
ScopedDiagnosticSink
A diagnostic sink that combines an IDiagnosticSink with default target location and declaration, simplifying diagnostic reporting and suppression.
Interfaces
IDiagnostic
Represents an instance of a diagnostic, including its definition, arguments, and optional extensions.
IDiagnosticDefinition
A non-generic base interface for DiagnosticDefinition<T>.
IDiagnosticExtension
IDiagnosticLocation
A base interface for objects to which a diagnostic can be reported.
IDiagnosticSink
A sink that reports diagnostics and suppressions from aspect code.
IDiagnosticSource
Represents the source of a diagnostic or suppression, typically an aspect, fabric, or other compile-time code component.
IScopedDiagnosticSink
A diagnostic sink with a default scope that simplifies reporting diagnostics and suppressions.
ISuppressibleDiagnostic
Represents a compiler or analyzer diagnostic that can be selectively suppressed using filtered suppressions.
ISuppression
Represents an instance of a diagnostic suppression that can be applied to declarations.
Enums
Severity
Specifies the severity level of a diagnostic.