/// <summary> /// Modifies an input <see cref="Diagnostic"/> per the given options. For example, the /// severity may be escalated, or the <see cref="Diagnostic"/> may be filtered out entirely /// (by returning null). /// </summary> /// <param name="d">The input diagnostic</param> /// <param name="warningLevelOption">The maximum warning level to allow. Diagnostics with a higher warning level will be filtered out.</param> /// <param name="generalDiagnosticOption">How warning diagnostics should be reported</param> /// <param name="specificDiagnosticOptions">How specific diagnostics should be reported</param> /// <returns>A diagnostic updated to reflect the options, or null if it has been filtered out</returns> public static Diagnostic Filter(Diagnostic d, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary <string, ReportDiagnostic> specificDiagnosticOptions) { if (d == null) { return(d); } switch (d.Severity) { case DiagnosticSeverity.Error: // If it is a compiler error, keep it as it is. // TODO: We currently use .Category to detect whether the diagnostic is a compiler diagnostic. // Perhaps there should be a stronger way of checking this that avoids the possibility of an // inadvertent clash for some custom diagnostic that happens to use the same category string. if (d.Category == Diagnostic.CompilerDiagnosticCategory) { return(d); } break; case InternalDiagnosticSeverity.Void: return(null); default: break; } //In the native compiler, all warnings originating from alink.dll were issued //under the id WRN_ALinkWarn - 1607. If a customer used nowarn:1607 they would get //none of those warnings. In Roslyn, we've given each of these warnings their //own number, so that they may be configured independently. To preserve compatibility //if a user has specifically configured 1607 and we are reporting one of the alink warnings, use //the configuration specified for 1607. As implemented, this could result in customers //specifying warnaserror:1607 and getting a message saying "warning as error CS8012..." //We don't permit configuring 1607 and independently configuring the new warnings. ReportDiagnostic reportAction; if (AlinkWarnings.Contains((ErrorCode)d.Code) && specificDiagnosticOptions.Keys.Contains(CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn))) { reportAction = GetDiagnosticReport(ErrorFacts.GetSeverity(ErrorCode.WRN_ALinkWarn), d.IsEnabledByDefault, CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn), ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn), d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions); } else { reportAction = GetDiagnosticReport(d.Severity, d.IsEnabledByDefault, d.Id, d.WarningLevel, d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions); } return(d.WithReportDiagnostic(reportAction)); }
/// <summary> /// Modifies an input <see cref="Diagnostic"/> per the given options. For example, the /// severity may be escalated, or the <see cref="Diagnostic"/> may be filtered out entirely /// (by returning null). /// </summary> /// <param name="d">The input diagnostic</param> /// <param name="warningLevelOption">The maximum warning level to allow. Diagnostics with a higher warning level will be filtered out.</param> /// <param name="generalDiagnosticOption">How warning diagnostics should be reported</param> /// <param name="specificDiagnosticOptions">How specific diagnostics should be reported</param> /// <returns>A diagnostic updated to reflect the options, or null if it has been filtered out</returns> public static Diagnostic Filter(Diagnostic d, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary <string, ReportDiagnostic> specificDiagnosticOptions) { if (d == null) { return(d); } else if (d.IsNotConfigurable()) { if (d.IsEnabledByDefault) { // Enabled NotConfigurable should always be reported as it is. return(d); } else { // Disabled NotConfigurable should never be reported. return(null); } } else if (d.Severity == InternalDiagnosticSeverity.Void) { return(null); } //In the native compiler, all warnings originating from alink.dll were issued //under the id WRN_ALinkWarn - 1607. If a customer used nowarn:1607 they would get //none of those warnings. In Roslyn, we've given each of these warnings their //own number, so that they may be configured independently. To preserve compatibility //if a user has specifically configured 1607 and we are reporting one of the alink warnings, use //the configuration specified for 1607. As implemented, this could result in customers //specifying warnaserror:1607 and getting a message saying "warning as error CS8012..." //We don't permit configuring 1607 and independently configuring the new warnings. ReportDiagnostic reportAction; if (s_alinkWarnings.Contains((ErrorCode)d.Code) && specificDiagnosticOptions.Keys.Contains(CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn))) { reportAction = GetDiagnosticReport(ErrorFacts.GetSeverity(ErrorCode.WRN_ALinkWarn), d.IsEnabledByDefault, CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn), ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn), d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions); } else { reportAction = GetDiagnosticReport(d.Severity, d.IsEnabledByDefault, d.Id, d.WarningLevel, d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions); } return(d.WithReportDiagnostic(reportAction)); }
public override DiagnosticSeverity GetSeverity(int code) { return(ErrorFacts.GetSeverity((ErrorCode)code)); }