提交 26de379c 编写于 作者: S Sam Harwell

Use ReportDiagnostic instead of DiagnosticSeverity for reporting purposes

上级 65268326
......@@ -139,15 +139,56 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
throw new ArgumentNullException(nameof(descriptor));
}
var warningLevel = GetDefaultWarningLevel(effectiveSeverity);
return Create(
descriptor,
location,
effectiveSeverity.ToReportDiagnostic(),
additionalLocations,
properties,
messageArgs);
}
/// <summary>
/// Creates a <see cref="Diagnostic"/> instance.
/// </summary>
/// <param name="descriptor">A <see cref="DiagnosticDescriptor"/> describing the diagnostic.</param>
/// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param>
/// <param name="effectiveSeverity">Effective severity of the diagnostic.</param>
/// <param name="additionalLocations">
/// An optional set of additional locations related to the diagnostic.
/// Typically, these are locations of other items referenced in the message.
/// If null, <see cref="AdditionalLocations"/> will return an empty list.
/// </param>
/// <param name="properties">
/// An optional set of name-value pairs by means of which the analyzer that creates the diagnostic
/// can convey more detailed information to the fixer. If null, <see cref="Properties"/> will return
/// <see cref="ImmutableDictionary{TKey, TValue}.Empty"/>.
/// </param>
/// <param name="messageArgs">Arguments to the message of the diagnostic.</param>
/// <returns>The <see cref="Diagnostic"/> instance.</returns>
public static Diagnostic Create(
DiagnosticDescriptor descriptor,
Location location,
ReportDiagnostic effectiveSeverity,
IEnumerable<Location> additionalLocations,
ImmutableDictionary<string, string> properties,
params object[] messageArgs)
{
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
var warningLevel = GetDefaultWarningLevel(effectiveSeverity, descriptor.DefaultSeverity);
return SimpleDiagnostic.Create(
descriptor,
severity: effectiveSeverity,
severity: effectiveSeverity.ToDiagnosticSeverity(descriptor.DefaultSeverity),
warningLevel: warningLevel,
location: location ?? Location.None,
additionalLocations: additionalLocations,
messageArgs: messageArgs,
properties: properties);
properties: properties,
isSuppressed: effectiveSeverity == ReportDiagnostic.Suppress);
}
/// <summary>
......@@ -519,20 +560,22 @@ internal Diagnostic WithReportDiagnostic(ReportDiagnostic reportAction)
/// level N should also be included.
/// </summary>
/// <remarks>
/// <see cref="DiagnosticSeverity.Info"/> and <see cref="DiagnosticSeverity.Hidden"/> are treated as warning
/// <see cref="ReportDiagnostic.Info"/> and <see cref="ReportDiagnostic.Hidden"/> are treated as warning
/// level 1. In other words, these diagnostics which typically interact with editor features are enabled unless
/// the special <c>/warn:0</c> option is set.
/// </remarks>
/// <param name="severity">A <see cref="DiagnosticSeverity"/> value.</param>
/// <returns>The default compiler warning level for <paramref name="severity"/>.</returns>
internal static int GetDefaultWarningLevel(DiagnosticSeverity severity)
internal static int GetDefaultWarningLevel(ReportDiagnostic severity, DiagnosticSeverity defaultSeverity)
{
switch (severity)
{
case DiagnosticSeverity.Error:
case ReportDiagnostic.Error:
case ReportDiagnostic.Default when defaultSeverity == DiagnosticSeverity.Error:
return 0;
case DiagnosticSeverity.Warning:
case ReportDiagnostic.Warn:
case ReportDiagnostic.Default when defaultSeverity == DiagnosticSeverity.Warning:
default:
return 1;
}
......
......@@ -212,24 +212,7 @@ public ReportDiagnostic GetEffectiveSeverity(CompilationOptions compilationOptio
// Create a dummy diagnostic to compute the effective diagnostic severity for given compilation options
// TODO: Once https://github.com/dotnet/roslyn/issues/3650 is fixed, we can avoid creating a no-location diagnostic here.
var effectiveDiagnostic = compilationOptions.FilterDiagnostic(Diagnostic.Create(this, Location.None));
return effectiveDiagnostic != null ? MapSeverityToReport(effectiveDiagnostic.Severity) : ReportDiagnostic.Suppress;
}
private static ReportDiagnostic MapSeverityToReport(DiagnosticSeverity severity)
{
switch (severity)
{
case DiagnosticSeverity.Hidden:
return ReportDiagnostic.Hidden;
case DiagnosticSeverity.Info:
return ReportDiagnostic.Info;
case DiagnosticSeverity.Warning:
return ReportDiagnostic.Warn;
case DiagnosticSeverity.Error:
return ReportDiagnostic.Error;
default:
throw ExceptionUtilities.UnexpectedValue(severity);
}
return effectiveDiagnostic != null ? effectiveDiagnostic.Severity.ToReportDiagnostic() : ReportDiagnostic.Suppress;
}
/// <summary>
......
......@@ -235,7 +235,7 @@ public int WarningLevel
{
if (_effectiveSeverity != _defaultSeverity)
{
return Diagnostic.GetDefaultWarningLevel(_effectiveSeverity);
return Diagnostic.GetDefaultWarningLevel(_effectiveSeverity.ToReportDiagnostic(), _defaultSeverity);
}
return _messageProvider.GetWarningLevel(_errorCode);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
public static class DiagnosticSeverityExtensions
{
public static ReportDiagnostic ToReportDiagnostic(this DiagnosticSeverity diagnosticSeverity)
{
switch (diagnosticSeverity)
{
case DiagnosticSeverity.Hidden:
return ReportDiagnostic.Hidden;
case DiagnosticSeverity.Info:
return ReportDiagnostic.Info;
case DiagnosticSeverity.Warning:
return ReportDiagnostic.Warn;
case DiagnosticSeverity.Error:
return ReportDiagnostic.Error;
default:
throw ExceptionUtilities.UnexpectedValue(diagnosticSeverity);
}
}
}
}
......@@ -193,7 +193,7 @@ internal override Diagnostic WithSeverity(DiagnosticSeverity severity)
{
if (this.Severity != severity)
{
var warningLevel = GetDefaultWarningLevel(severity);
var warningLevel = GetDefaultWarningLevel(severity.ToReportDiagnostic(), DefaultSeverity);
return new SimpleDiagnostic(_descriptor, severity, warningLevel, _location, _additionalLocations, _messageArgs, _properties, _isSuppressed);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
public static class ReportDiagnosticExtensions
{
public static DiagnosticSeverity ToDiagnosticSeverity(this ReportDiagnostic reportDiagnostic, DiagnosticSeverity defaultSeverity)
{
switch (reportDiagnostic)
{
case ReportDiagnostic.Error:
return DiagnosticSeverity.Error;
case ReportDiagnostic.Warn:
return DiagnosticSeverity.Warning;
case ReportDiagnostic.Info:
return DiagnosticSeverity.Info;
case ReportDiagnostic.Hidden:
return DiagnosticSeverity.Hidden;
case ReportDiagnostic.Suppress:
case ReportDiagnostic.Default:
return defaultSeverity;
default:
throw ExceptionUtilities.UnexpectedValue(reportDiagnostic);
}
}
public static ReportDiagnostic WithDefaultSeverity(this ReportDiagnostic reportDiagnostic, DiagnosticSeverity defaultSeverity)
{
if (reportDiagnostic != ReportDiagnostic.Default)
{
return reportDiagnostic;
}
return defaultSeverity.ToReportDiagnostic();
}
}
}
Microsoft.CodeAnalysis.Compilation.HasImplicitConversion(Microsoft.CodeAnalysis.ITypeSymbol fromType, Microsoft.CodeAnalysis.ITypeSymbol toType) -> bool
Microsoft.CodeAnalysis.DiagnosticSeverityExtensions
Microsoft.CodeAnalysis.Diagnostics.Telemetry.AnalyzerTelemetryInfo.Concurrent.get -> bool
Microsoft.CodeAnalysis.Diagnostics.Telemetry.AnalyzerTelemetryInfo.Concurrent.set -> void
Microsoft.CodeAnalysis.Operations.CommonConversion.IsImplicit.get -> bool
Microsoft.CodeAnalysis.ReportDiagnosticExtensions
abstract Microsoft.CodeAnalysis.Compilation.ClassifyCommonConversion(Microsoft.CodeAnalysis.ITypeSymbol source, Microsoft.CodeAnalysis.ITypeSymbol destination) -> Microsoft.CodeAnalysis.Operations.CommonConversion
static Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor descriptor, Microsoft.CodeAnalysis.Location location, Microsoft.CodeAnalysis.ReportDiagnostic effectiveSeverity, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Location> additionalLocations, System.Collections.Immutable.ImmutableDictionary<string, string> properties, params object[] messageArgs) -> Microsoft.CodeAnalysis.Diagnostic
static Microsoft.CodeAnalysis.DiagnosticSeverityExtensions.ToReportDiagnostic(this Microsoft.CodeAnalysis.DiagnosticSeverity diagnosticSeverity) -> Microsoft.CodeAnalysis.ReportDiagnostic
static Microsoft.CodeAnalysis.ReportDiagnosticExtensions.ToDiagnosticSeverity(this Microsoft.CodeAnalysis.ReportDiagnostic reportDiagnostic, Microsoft.CodeAnalysis.DiagnosticSeverity defaultSeverity) -> Microsoft.CodeAnalysis.DiagnosticSeverity
static Microsoft.CodeAnalysis.ReportDiagnosticExtensions.WithDefaultSeverity(this Microsoft.CodeAnalysis.ReportDiagnostic reportDiagnostic, Microsoft.CodeAnalysis.DiagnosticSeverity defaultSeverity) -> Microsoft.CodeAnalysis.ReportDiagnostic
......@@ -72,7 +72,7 @@ private NamingStylePreferences CreateCustomFieldNamingStylePreference()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -104,7 +104,7 @@ private NamingStylePreferences CreateCustomStaticFieldNamingStylePreference()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......
......@@ -33,7 +33,7 @@ public static void TestPascalCaseRule()
var symbolSpec = result.SymbolSpecifications.Single();
Assert.Equal(namingStyle.ID, namingRule.NamingStyleID);
Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID);
Assert.Equal(DiagnosticSeverity.Warning, namingRule.EnforcementLevel);
Assert.Equal(ReportDiagnostic.Warn, namingRule.EnforcementLevel);
Assert.Equal("method_and_property_symbols", symbolSpec.Name);
var expectedApplicableSymbolKindList = new[]
{
......@@ -80,7 +80,7 @@ public static void TestAsyncMethodsRule()
var symbolSpec = result.SymbolSpecifications.Single();
Assert.Equal(namingStyle.ID, namingRule.NamingStyleID);
Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID);
Assert.Equal(DiagnosticSeverity.Error, namingRule.EnforcementLevel);
Assert.Equal(ReportDiagnostic.Error, namingRule.EnforcementLevel);
Assert.Equal("method_symbols", symbolSpec.Name);
Assert.Single(symbolSpec.ApplicableSymbolKindList);
Assert.Contains(new SymbolKindOrTypeKind(SymbolKind.Method), symbolSpec.ApplicableSymbolKindList);
......@@ -132,7 +132,7 @@ public static void TestPublicMembersCapitalizedRule()
var symbolSpec = result.SymbolSpecifications.Single();
Assert.Equal(namingStyle.ID, namingRule.NamingStyleID);
Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID);
Assert.Equal(DiagnosticSeverity.Info, namingRule.EnforcementLevel);
Assert.Equal(ReportDiagnostic.Info, namingRule.EnforcementLevel);
Assert.Equal("public_symbols", symbolSpec.Name);
var expectedApplicableSymbolKindList = new[]
{
......@@ -180,7 +180,7 @@ public static void TestNonPublicMembersLowerCaseRule()
var symbolSpec = result.SymbolSpecifications.Single();
Assert.Equal(namingStyle.ID, namingRule.NamingStyleID);
Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID);
Assert.Equal(DiagnosticSeverity.Hidden, namingRule.EnforcementLevel);
Assert.Equal(ReportDiagnostic.Hidden, namingRule.EnforcementLevel);
Assert.Equal("non_public_symbols", symbolSpec.Name);
var expectedApplicableSymbolKindList = new[]
{
......@@ -223,7 +223,7 @@ public static void TestParametersAndLocalsAreCamelCaseRule()
var symbolSpec = result.SymbolSpecifications.Single();
Assert.Equal(namingStyle.ID, namingRule.NamingStyleID);
Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID);
Assert.Equal(DiagnosticSeverity.Info, namingRule.EnforcementLevel);
Assert.Equal(ReportDiagnostic.Info, namingRule.EnforcementLevel);
Assert.Equal("parameters_and_locals", symbolSpec.Name);
var expectedApplicableSymbolKindList = new[]
......
......@@ -71,7 +71,7 @@ private static NamingStylePreferences ClassNamesArePascalCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
ImmutableArray.Create(symbolSpecification),
......@@ -102,7 +102,7 @@ private static NamingStylePreferences MethodNamesArePascalCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
ImmutableArray.Create(symbolSpecification),
......@@ -133,7 +133,7 @@ private static NamingStylePreferences ParameterNamesAreCamelCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -165,7 +165,7 @@ private static NamingStylePreferences LocalNamesAreCamelCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -197,7 +197,7 @@ private static NamingStylePreferences PropertyNamesArePascalCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -229,7 +229,7 @@ private static NamingStylePreferences InterfacesNamesStartWithIOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -263,7 +263,7 @@ private static NamingStylePreferences ConstantsAreUpperCaseOption()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......@@ -310,14 +310,14 @@ private static NamingStylePreferences LocalsAreCamelCaseConstantsAreUpperCaseOpt
{
SymbolSpecificationID = localsSymbolSpecification.ID,
NamingStyleID = camelCaseNamingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var constLocalsUpperCaseNamingRule = new SerializableNamingRule()
{
SymbolSpecificationID = constLocalsSymbolSpecification.ID,
NamingStyleID = allUpperNamingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
EnforcementLevel = ReportDiagnostic.Error
};
var info = new NamingStylePreferences(
......
......@@ -134,7 +134,7 @@ public CSharpAddAccessibilityModifiersDiagnosticAnalyzer()
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
name.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
additionalLocations: additionalLocations,
properties: null));
}
......
......@@ -81,7 +81,7 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context)
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
firstToken.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
additionalLocations: null,
properties: null,
SyntaxFacts.GetText(firstToken.Kind())));
......
......@@ -68,7 +68,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
}
var typeStyle = AnalyzeTypeName(declaredType, semanticModel, optionSet, cancellationToken);
if (typeStyle.IsStylePreferred && typeStyle.Severity != DiagnosticSeverity.Hidden)
if (typeStyle.IsStylePreferred && typeStyle.Severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) < ReportDiagnostic.Hidden)
{
// the analyzer would handle this. So we do not.
return;
......
......@@ -28,7 +28,7 @@ private static NamingRule CreateGetAsyncRule()
return new NamingRule(
new SymbolSpecification(Guid.NewGuid(), "endswithasync", kinds, ImmutableArray.Create<Accessibility>(), modifiers),
new NamingStyles.NamingStyle(Guid.NewGuid(), prefix: "Get", suffix: "Async"),
DiagnosticSeverity.Info);
ReportDiagnostic.Info);
}
private static NamingRule CreateCamelCaseFieldsAndParametersRule()
......@@ -38,7 +38,7 @@ private static NamingRule CreateCamelCaseFieldsAndParametersRule()
return new NamingRule(
new SymbolSpecification(Guid.NewGuid(), "camelcasefields", kinds, ImmutableArray.Create<Accessibility>(), modifiers),
new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.CamelCase),
DiagnosticSeverity.Info);
ReportDiagnostic.Info);
}
private static NamingRule CreateEndWithAsyncRule()
......@@ -48,7 +48,7 @@ private static NamingRule CreateEndWithAsyncRule()
return new NamingRule(
new SymbolSpecification(Guid.NewGuid(), "endswithasynct", kinds, ImmutableArray.Create<Accessibility>(), modifiers),
new NamingStyles.NamingStyle(Guid.NewGuid(), suffix: "Async"),
DiagnosticSeverity.Info);
ReportDiagnostic.Info);
}
private static NamingRule CreateMethodStartsWithGetRule()
......@@ -58,7 +58,7 @@ private static NamingRule CreateMethodStartsWithGetRule()
return new NamingRule(
new SymbolSpecification(Guid.NewGuid(), "startswithget", kinds, ImmutableArray.Create<Accessibility>(), modifiers),
new NamingStyles.NamingStyle(Guid.NewGuid(), prefix: "Get"),
DiagnosticSeverity.Info);
ReportDiagnostic.Info);
}
}
}
......@@ -93,7 +93,7 @@ internal override async Task<string> GetFieldNameAsync(Document document, IPrope
Guid.NewGuid(),
prefix: prefix,
capitalizationScheme: Capitalization.CamelCase),
DiagnosticSeverity.Hidden));
ReportDiagnostic.Hidden));
}
private string GenerateFieldName(IPropertySymbol property, ImmutableArray<NamingRule> rules)
......
......@@ -63,7 +63,7 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
var typeStyle = Helper.AnalyzeTypeName(
declaredType, semanticModel, optionSet, cancellationToken);
if (!typeStyle.IsStylePreferred ||
typeStyle.Severity == DiagnosticSeverity.Hidden ||
typeStyle.Severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) >= ReportDiagnostic.Hidden ||
!typeStyle.CanConvert())
{
return;
......@@ -74,7 +74,7 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
context.ReportDiagnostic(CreateDiagnostic(descriptor, declarationStatement, declaredType.Span, typeStyle.Severity));
}
private Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, DiagnosticSeverity severity)
private Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, ReportDiagnostic severity)
=> Diagnostic.Create(descriptor, declaration.SyntaxTree.GetLocation(diagnosticSpan), severity, additionalLocations: null, properties: null);
}
}
......@@ -243,7 +243,7 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
reportNode.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
additionalLocations: allLocations,
properties: null));
}
......
......@@ -49,7 +49,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
return;
}
var severity = styleOption.Notification.Value;
var severity = styleOption.Notification.Severity;
// look for the form "if (a != null)" or "if (null != a)"
var ifStatement = (IfStatementSyntax)syntaxContext.Node;
......@@ -119,7 +119,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
BinaryExpressionSyntax condition,
ExpressionStatementSyntax expressionStatement,
InvocationExpressionSyntax invocationExpression,
DiagnosticSeverity severity)
ReportDiagnostic severity)
{
var cancellationToken = syntaxContext.CancellationToken;
......@@ -161,7 +161,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
StatementSyntax firstStatement,
IfStatementSyntax ifStatement,
ExpressionStatementSyntax expressionStatement,
DiagnosticSeverity severity,
ReportDiagnostic severity,
List<Location> additionalLocations,
string kind)
{
......@@ -200,7 +200,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
BinaryExpressionSyntax condition,
ExpressionStatementSyntax expressionStatement,
InvocationExpressionSyntax invocationExpression,
DiagnosticSeverity severity)
ReportDiagnostic severity)
{
var cancellationToken = syntaxContext.CancellationToken;
cancellationToken.ThrowIfCancellationRequested();
......
......@@ -22,7 +22,7 @@ public CSharpOrderModifiersDiagnosticAnalyzer()
protected override void Recurse(
SyntaxTreeAnalysisContext context,
Dictionary<int, int> preferredOrder,
DiagnosticSeverity severity,
ReportDiagnostic severity,
SyntaxNode root)
{
foreach (var child in root.ChildNodesAndTokens())
......
......@@ -56,16 +56,16 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
switch (context.Node)
{
case VariableDeclarationSyntax variableDeclaration:
AnalyzeVariableDeclaration(context, variableDeclaration, option.Notification.Value);
AnalyzeVariableDeclaration(context, variableDeclaration, option.Notification.Severity);
return;
case ForEachStatementSyntax forEachStatement:
AnalyzeForEachStatement(context, forEachStatement, option.Notification.Value);
AnalyzeForEachStatement(context, forEachStatement, option.Notification.Severity);
return;
}
}
private void AnalyzeVariableDeclaration(
SyntaxNodeAnalysisContext context, VariableDeclarationSyntax variableDeclaration, DiagnosticSeverity severity)
SyntaxNodeAnalysisContext context, VariableDeclarationSyntax variableDeclaration, ReportDiagnostic severity)
{
if (!TryAnalyzeVariableDeclaration(
context.SemanticModel, variableDeclaration, out _,
......@@ -83,7 +83,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
private void AnalyzeForEachStatement(
SyntaxNodeAnalysisContext context, ForEachStatementSyntax forEachStatement, DiagnosticSeverity severity)
SyntaxNodeAnalysisContext context, ForEachStatementSyntax forEachStatement, ReportDiagnostic severity)
{
if (!TryAnalyzeForEachStatement(
context.SemanticModel, forEachStatement, out _,
......
......@@ -53,7 +53,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
Diagnostic.Create(
Descriptor,
defaultExpression.GetLocation(),
optionSet.GetOption(CSharpCodeStyleOptions.PreferSimpleDefaultExpression).Notification.Value,
optionSet.GetOption(CSharpCodeStyleOptions.PreferSimpleDefaultExpression).Notification.Severity,
additionalLocations: null,
properties: null));
......
......@@ -86,11 +86,11 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
OptionSet optionSet, SyntaxNode declaration, UseExpressionBodyHelper helper)
{
var preferExpressionBodiedOption = optionSet.GetOption(helper.Option);
var severity = preferExpressionBodiedOption.Notification.Value;
var severity = preferExpressionBodiedOption.Notification.Severity;
if (helper.CanOfferUseExpressionBody(optionSet, declaration, forAnalyzer: true))
{
var location = severity == DiagnosticSeverity.Hidden
var location = severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden
? declaration.GetLocation()
: helper.GetDiagnosticLocation(declaration);
......@@ -106,7 +106,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
{
// They have an expression body. Create a diagnostic to convert it to a block
// if they don't want expression bodies for this member.
var location = severity == DiagnosticSeverity.Hidden
var location = severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden
? declaration.GetLocation()
: helper.GetExpressionBody(declaration).GetLocation();
......
......@@ -51,7 +51,7 @@ private void ReportDiagnosticsIfNeeded(NameColonSyntax nameColon, SyntaxNodeAnal
Diagnostic.Create(
Descriptor,
nameColon.GetLocation(),
optionSet.GetOption(CodeStyleOptions.PreferInferredTupleNames, context.Compilation.Language).Notification.Value,
optionSet.GetOption(CodeStyleOptions.PreferInferredTupleNames, context.Compilation.Language).Notification.Severity,
additionalLocations: null,
properties: null));
......@@ -82,7 +82,7 @@ private void ReportDiagnosticsIfNeeded(NameEqualsSyntax nameEquals, SyntaxNodeAn
Diagnostic.Create(
Descriptor,
nameEquals.GetLocation(),
optionSet.GetOption(CodeStyleOptions.PreferInferredAnonymousTypeMemberNames, context.Compilation.Language).Notification.Value,
optionSet.GetOption(CodeStyleOptions.PreferInferredAnonymousTypeMemberNames, context.Compilation.Language).Notification.Severity,
additionalLocations: null,
properties: null));
......
......@@ -30,7 +30,7 @@ public override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.UseLocalFunctionDiagnosticId);
protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic)
=> diagnostic.Severity != DiagnosticSeverity.Hidden;
=> diagnostic.Severity != DiagnosticSeverity.Hidden && !diagnostic.IsSuppressed;
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
......
......@@ -85,7 +85,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
return;
}
var severity = styleOption.Notification.Value;
var severity = styleOption.Notification.Severity;
var anonymousFunction = (AnonymousFunctionExpressionSyntax)syntaxContext.Node;
var semanticModel = syntaxContext.SemanticModel;
......@@ -130,7 +130,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
additionalLocations = additionalLocations.AddRange(explicitInvokeCallLocations);
if (severity != DiagnosticSeverity.Hidden)
if (severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) < ReportDiagnostic.Hidden)
{
// If the diagnostic is not hidden, then just place the user visible part
// on the local being initialized with the lambda.
......
......@@ -197,7 +197,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
syntaxContext.ReportDiagnostic(Diagnostic.Create(
Descriptor,
declarationStatement.GetLocation(),
styleOption.Notification.Value,
styleOption.Notification.Severity,
additionalLocations,
properties: null));
}
......
......@@ -61,7 +61,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
return;
}
var severity = styleOption.Notification.Value;
var severity = styleOption.Notification.Severity;
// "x is Type y" is only available in C# 7.0 and above. Don't offer this refactoring
// in projects targetting a lesser version.
......
......@@ -122,12 +122,12 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
// To make this user experience more pleasant, we will place the diagnostic on
// both *'s.
AddDiagnostics(
context, binaryLike, precedence, preference.Notification.Value,
context, binaryLike, precedence, preference.Notification.Severity,
additionalLocations, equivalenceKey, includeInFixAll: true);
}
private void AddDiagnostics(
SyntaxNodeAnalysisContext context, TBinaryLikeExpressionSyntax binaryLikeOpt, int precedence,
DiagnosticSeverity severity, ImmutableArray<Location> additionalLocations,
ReportDiagnostic severity, ImmutableArray<Location> additionalLocations,
string equivalenceKey, bool includeInFixAll)
{
if (binaryLikeOpt != null &&
......
......@@ -90,27 +90,10 @@ public static bool HasNonHiddenDescriptor(this DiagnosticAnalyzerService service
public static ReportDiagnostic GetEffectiveSeverity(this DiagnosticDescriptor descriptor, CompilationOptions options)
{
return options == null
? descriptor.DefaultSeverity.MapSeverityToReport()
? descriptor.DefaultSeverity.ToReportDiagnostic()
: descriptor.GetEffectiveSeverity(options);
}
public static ReportDiagnostic MapSeverityToReport(this DiagnosticSeverity severity)
{
switch (severity)
{
case DiagnosticSeverity.Hidden:
return ReportDiagnostic.Hidden;
case DiagnosticSeverity.Info:
return ReportDiagnostic.Info;
case DiagnosticSeverity.Warning:
return ReportDiagnostic.Warn;
case DiagnosticSeverity.Error:
return ReportDiagnostic.Error;
default:
throw ExceptionUtilities.UnexpectedValue(severity);
}
}
public static bool IsCompilerAnalyzer(this DiagnosticAnalyzer analyzer)
{
// TODO: find better way.
......
......@@ -119,7 +119,7 @@ void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
var namingStyleRules = namingPreferences.Rules;
if (!namingStyleRules.TryGetApplicableRule(symbol, out var applicableRule) ||
applicableRule.EnforcementLevel == DiagnosticSeverity.Hidden)
applicableRule.EnforcementLevel.WithDefaultSeverity(DiagnosticSeverity.Hidden) >= ReportDiagnostic.Hidden)
{
return null;
}
......
......@@ -121,7 +121,7 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
/// Detects the context of this occurrence of predefined type and determines if we should report it.
/// </summary>
private bool ShouldReportDiagnostic(TPredefinedTypeSyntax predefinedTypeNode, OptionSet optionSet, string language,
out DiagnosticDescriptor descriptor, out DiagnosticSeverity severity)
out DiagnosticDescriptor descriptor, out ReportDiagnostic severity)
{
CodeStyleOption<bool> optionValue;
......@@ -138,7 +138,7 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
optionValue = optionSet.GetOption(GetOptionForDeclarationContext, language);
}
severity = optionValue.Notification.Value;
severity = optionValue.Notification.Severity;
return OptionSettingPrefersFrameworkType(optionValue, severity);
}
......@@ -149,14 +149,14 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
private bool IsFrameworkTypePreferred(OptionSet optionSet, PerLanguageOption<CodeStyleOption<bool>> option, string language)
{
var optionValue = optionSet.GetOption(option, language);
return OptionSettingPrefersFrameworkType(optionValue, optionValue.Notification.Value);
return OptionSettingPrefersFrameworkType(optionValue, optionValue.Notification.Severity);
}
/// <summary>
/// checks if style is preferred and the enforcement is not None.
/// </summary>
/// <remarks>if predefined type is not preferred, it implies the preference is framework type.</remarks>
private static bool OptionSettingPrefersFrameworkType(CodeStyleOption<bool> optionValue, DiagnosticSeverity severity) =>
!optionValue.Value && severity != DiagnosticSeverity.Hidden;
private static bool OptionSettingPrefersFrameworkType(CodeStyleOption<bool> optionValue, ReportDiagnostic severity) =>
!optionValue.Value && severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) < ReportDiagnostic.Hidden;
}
}
......@@ -122,17 +122,17 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
PerLanguageOption<CodeStyleOption<bool>> option;
DiagnosticDescriptor descriptor;
DiagnosticSeverity severity;
ReportDiagnostic severity;
switch (diagnosticId)
{
case IDEDiagnosticIds.SimplifyNamesDiagnosticId:
descriptor = s_descriptorSimplifyNames;
severity = descriptor.DefaultSeverity;
severity = descriptor.DefaultSeverity.ToReportDiagnostic();
break;
case IDEDiagnosticIds.SimplifyMemberAccessDiagnosticId:
descriptor = s_descriptorSimplifyMemberAccess;
severity = descriptor.DefaultSeverity;
severity = descriptor.DefaultSeverity.ToReportDiagnostic();
break;
case IDEDiagnosticIds.RemoveQualificationDiagnosticId:
......@@ -168,12 +168,12 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
return true;
}
private (DiagnosticDescriptor descriptor, DiagnosticSeverity severity) GetApplicablePredefinedTypeDiagnosticDescriptor<T>(string id, PerLanguageOption<T> option, OptionSet optionSet) where T : CodeStyleOption<bool>
private (DiagnosticDescriptor descriptor, ReportDiagnostic severity) GetApplicablePredefinedTypeDiagnosticDescriptor<T>(string id, PerLanguageOption<T> option, OptionSet optionSet) where T : CodeStyleOption<bool>
{
var optionValue = optionSet.GetOption(option, GetLanguageName());
DiagnosticDescriptor descriptor = null;
if (optionValue.Notification.Value != DiagnosticSeverity.Hidden)
if (optionValue.Notification.Severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) < ReportDiagnostic.Hidden)
{
switch (id)
{
......@@ -190,10 +190,10 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
}
}
return (descriptor, optionValue.Notification.Value);
return (descriptor, optionValue.Notification.Severity);
}
private (DiagnosticDescriptor descriptor, DiagnosticSeverity severity) GetRemoveQualificationDiagnosticDescriptor(SemanticModel model, SyntaxNode node, OptionSet optionSet, CancellationToken cancellationToken)
private (DiagnosticDescriptor descriptor, ReportDiagnostic severity) GetRemoveQualificationDiagnosticDescriptor(SemanticModel model, SyntaxNode node, OptionSet optionSet, CancellationToken cancellationToken)
{
var symbolInfo = model.GetSymbolInfo(node, cancellationToken);
if (symbolInfo.Symbol == null)
......@@ -203,7 +203,7 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
var applicableOption = QualifyMembersHelpers.GetApplicableOptionFromSymbolKind(symbolInfo.Symbol.Kind);
var optionValue = optionSet.GetOption(applicableOption, GetLanguageName());
var severity = optionValue.Notification.Value;
var severity = optionValue.Notification.Severity;
return (s_descriptorRemoveThisOrMe, severity);
}
......
......@@ -47,17 +47,17 @@ internal abstract partial class AbstractInitializeMemberFromParameterCodeRefacto
Guid.NewGuid(), "Property",
ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Property))),
new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.PascalCase),
enforcementLevel: DiagnosticSeverity.Hidden),
enforcementLevel: ReportDiagnostic.Hidden),
new NamingRule(new SymbolSpecification(
Guid.NewGuid(), "Field",
ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))),
new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.CamelCase),
enforcementLevel: DiagnosticSeverity.Hidden),
enforcementLevel: ReportDiagnostic.Hidden),
new NamingRule(new SymbolSpecification(
Guid.NewGuid(), "FieldWithUnderscore",
ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))),
new NamingStyles.NamingStyle(Guid.NewGuid(), prefix: "_", capitalizationScheme: Capitalization.CamelCase),
enforcementLevel: DiagnosticSeverity.Hidden));
enforcementLevel: ReportDiagnostic.Hidden));
protected abstract SyntaxNode TryGetLastStatement(IBlockOperation blockStatementOpt);
......
......@@ -94,7 +94,7 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
var diagnostic = Diagnostic.Create(
Descriptor,
symbol.Locations[0],
option.Notification.Value,
option.Notification.Severity,
additionalLocations: null,
properties: null);
context.ReportDiagnostic(diagnostic);
......
......@@ -54,25 +54,25 @@ private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
return;
}
Recurse(context, preferredOrder, option.Notification.Value, root);
Recurse(context, preferredOrder, option.Notification.Severity, root);
}
protected abstract void Recurse(
SyntaxTreeAnalysisContext context,
Dictionary<int, int> preferredOrder,
DiagnosticSeverity severity,
ReportDiagnostic severity,
SyntaxNode root);
protected void CheckModifiers(
SyntaxTreeAnalysisContext context,
Dictionary<int, int> preferredOrder,
DiagnosticSeverity severity,
ReportDiagnostic severity,
SyntaxNode memberDeclaration)
{
var modifiers = _syntaxFacts.GetModifiers(memberDeclaration);
if (!IsOrdered(preferredOrder, modifiers))
{
if (severity == DiagnosticSeverity.Hidden)
if (severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden)
{
// If the severity is hidden, put the marker on all the modifiers so that the
// user can bring up the fix anywhere in the modifier list.
......
......@@ -112,8 +112,8 @@ private void AnalyzeOperation(OperationAnalysisContext context)
var isQualificationPresent = IsAlreadyQualifiedMemberAccess(instanceSyntaxOpt);
if (shouldOptionBePresent && !isQualificationPresent)
{
var severity = optionValue.Notification.Value;
if (severity != DiagnosticSeverity.Hidden)
var severity = optionValue.Notification.Severity;
if (severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) < ReportDiagnostic.Hidden)
{
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
......
......@@ -105,7 +105,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
Debug.Assert(preference.Value == ParenthesesPreference.NeverIfUnnecessary ||
!clarifiesPrecedence);
var severity = preference.Notification.Value;
var severity = preference.Notification.Severity;
var additionalLocations = ImmutableArray.Create(parenthesizedExpression.GetLocation());
......
......@@ -314,12 +314,18 @@ private void Process(AnalysisResult result, SemanticModelAnalysisContext context
propertyDeclaration.GetLocation(), variableDeclarator.GetLocation());
var option = optionSet.GetOption(CodeStyleOptions.PreferAutoProperties, propertyDeclaration.Language);
if (option.Notification.Severity == ReportDiagnostic.Suppress)
{
// Avoid reporting diagnostics when the feature is disabled. This primarily avoids reporting the hidden
// helper diagnostic which is not otherwise influenced by the severity settings.
return;
}
// Place the appropriate marker on the field depending on the user option.
var diagnostic1 = Diagnostic.Create(
UnnecessaryWithSuggestionDescriptor,
nodeToFade.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
additionalLocations: additionalLocations,
properties: null);
......
......@@ -132,7 +132,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
conditionalExpression.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
locations,
properties: null));
}
......
......@@ -131,7 +131,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
conditionalExpression.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
locations,
properties: null));
}
......
......@@ -110,7 +110,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context, INamedTypeSymbol ien
var locations = ImmutableArray.Create(objectCreationExpression.GetLocation());
var severity = option.Notification.Value;
var severity = option.Notification.Severity;
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
objectCreationExpression.GetLocation(),
......
......@@ -71,7 +71,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
ifStatement.GetFirstToken().GetLocation(),
option.Notification.Value,
option.Notification.Severity,
additionalLocations,
properties: null));
}
......
......@@ -40,8 +40,8 @@ private void AnalyzeOperation(OperationAnalysisContext context)
}
var option = optionSet.GetOption(CodeStyleOptions.PreferExplicitTupleNames, context.Compilation.Language);
var severity = option.Notification.Value;
if (severity == DiagnosticSeverity.Hidden)
var severity = option.Notification.Severity;
if (severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) >= ReportDiagnostic.Hidden)
{
return;
}
......
......@@ -141,7 +141,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context, IMethodSymbol refe
properties = properties.Add(AbstractUseIsNullCheckCodeFixProvider.Negated, "");
}
var severity = option.Notification.Value;
var severity = option.Notification.Severity;
context.ReportDiagnostic(
Diagnostic.Create(
Descriptor, nameNode.GetLocation(),
......
......@@ -181,7 +181,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context, INamedTypeSymbol e
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
conditionalExpression.GetLocation(),
option.Notification.Value,
option.Notification.Severity,
locations,
properties));
}
......
......@@ -87,7 +87,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
var locations = ImmutableArray.Create(objectCreationExpression.GetLocation());
var severity = option.Notification.Value;
var severity = option.Notification.Severity;
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
objectCreationExpression.GetLocation(),
......
......@@ -147,7 +147,7 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
assignmentExpression.Value.Syntax.GetLocation());
context.ReportDiagnostic(
Diagnostic.Create(Descriptor, throwStatementSyntax.GetLocation(), option.Notification.Value, additionalLocations: allLocations, properties: null));
Diagnostic.Create(Descriptor, throwStatementSyntax.GetLocation(), option.Notification.Severity, additionalLocations: allLocations, properties: null));
// Fade out the rest of the if that surrounds the 'throw' exception.
......
......@@ -85,7 +85,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddAccessibilityModifiers
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
name.GetLocation(),
[option].Notification.Value,
[option].Notification.Severity,
additionalLocations:=additionalLocations,
properties:=Nothing))
End Sub
......
......@@ -19,7 +19,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.OrderModifiers
Protected Overrides Sub Recurse(
context As SyntaxTreeAnalysisContext,
preferredOrder As Dictionary(Of Integer, Integer),
severity As DiagnosticSeverity,
severity As ReportDiagnostic,
root As SyntaxNode)
For Each child In root.ChildNodesAndTokens()
......
......@@ -51,7 +51,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseInferredMemberName
Diagnostic.Create(
Descriptor,
nameColonEquals.GetLocation(),
optionSet.GetOption(CodeStyleOptions.PreferInferredTupleNames, context.Compilation.Language).Notification.Value,
optionSet.GetOption(CodeStyleOptions.PreferInferredTupleNames, context.Compilation.Language).Notification.Severity,
additionalLocations:=Nothing,
properties:=Nothing))
......@@ -82,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseInferredMemberName
Diagnostic.Create(
Descriptor,
syntaxTree.GetLocation(fadeSpan),
optionSet.GetOption(CodeStyleOptions.PreferInferredAnonymousTypeMemberNames, context.Compilation.Language).Notification.Value,
optionSet.GetOption(CodeStyleOptions.PreferInferredAnonymousTypeMemberNames, context.Compilation.Language).Notification.Severity,
additionalLocations:=Nothing,
properties:=Nothing))
......
......@@ -33,7 +33,7 @@ public CheckBoxWithComboOptionViewModel(IOption option, string description, stri
var codeStyleOption = ((CodeStyleOption<bool>)options.GetOption(new OptionKey(option, option.IsPerLanguage ? info.Language : null)));
SetProperty(ref _isChecked, codeStyleOption.Value);
var notificationViewModel = items.Where(i => i.Notification.Value == codeStyleOption.Notification.Value).Single();
var notificationViewModel = items.Where(i => i.Notification.Severity == codeStyleOption.Notification.Severity).Single();
SetProperty(ref _selectedNotificationOption, notificationViewModel);
}
......
......@@ -37,8 +37,8 @@ internal class BooleanCodeStyleOptionViewModel : AbstractCodeStyleOptionViewMode
var codeStyleOption = ((CodeStyleOption<bool>)options.GetOption(new OptionKey(option, option.IsPerLanguage ? info.Language : null)));
_selectedPreference = Preferences.Single(c => c.IsChecked == codeStyleOption.Value);
var notificationViewModel = NotificationPreferences.Single(i => i.Notification.Value == codeStyleOption.Notification.Value);
_selectedNotificationPreference = NotificationPreferences.Single(p => p.Notification.Value == notificationViewModel.Notification.Value);
var notificationViewModel = NotificationPreferences.Single(i => i.Notification.Severity == codeStyleOption.Notification.Severity);
_selectedNotificationPreference = NotificationPreferences.Single(p => p.Notification.Severity == notificationViewModel.Notification.Severity);
NotifyPropertyChanged(nameof(SelectedPreference));
NotifyPropertyChanged(nameof(SelectedNotificationPreference));
......
......@@ -90,8 +90,8 @@ static EnumCodeStyleOptionViewModel()
_selectedPreference = Preferences[enumIndex];
var notificationViewModel = NotificationPreferences.Single(i => i.Notification.Value == codeStyleOption.Notification.Value);
_selectedNotificationPreference = NotificationPreferences.Single(p => p.Notification.Value == notificationViewModel.Notification.Value);
var notificationViewModel = NotificationPreferences.Single(i => i.Notification.Severity == codeStyleOption.Notification.Severity);
_selectedNotificationPreference = NotificationPreferences.Single(p => p.Notification.Severity == notificationViewModel.Notification.Severity);
NotifyPropertyChanged(nameof(SelectedPreference));
NotifyPropertyChanged(nameof(SelectedNotificationPreference));
......
......@@ -154,7 +154,7 @@ internal override void SaveSettings()
var rule = new SerializableNamingRule()
{
EnforcementLevel = item.SelectedNotificationPreference.Notification.Value,
EnforcementLevel = item.SelectedNotificationPreference.Notification.Severity,
NamingStyleID = item.SelectedStyle.ID,
SymbolSpecificationID = item.SelectedSpecification.ID
};
......
......@@ -44,7 +44,7 @@ public NamingStyleOptionPageViewModel(NamingStylePreferences info)
viewModel.SelectedSpecification = viewModel.Specifications.Single(s => s.ID == namingRule.SymbolSpecificationID);
viewModel.SelectedStyle= viewModel.NamingStyles.Single(s => s.ID == namingRule.NamingStyleID);
viewModel.SelectedNotificationPreference = viewModel.NotificationPreferences.Single(n => n.Notification.Value == namingRule.EnforcementLevel);
viewModel.SelectedNotificationPreference = viewModel.NotificationPreferences.Single(n => n.Notification.Severity == namingRule.EnforcementLevel);
viewModels.Add(viewModel);
}
......
......@@ -16,7 +16,7 @@ internal partial class CSharpTypeStyleHelper
{
protected class State
{
private readonly Dictionary<TypeStylePreference, DiagnosticSeverity> _styleToSeverityMap;
private readonly Dictionary<TypeStylePreference, ReportDiagnostic> _styleToSeverityMap;
public TypeStylePreference TypeStylePreference { get; private set; }
public bool IsInIntrinsicTypeContext { get; private set; }
......@@ -26,7 +26,7 @@ protected class State
private State(bool isVariableDeclarationContext)
{
this.IsInVariableDeclarationContext = isVariableDeclarationContext;
_styleToSeverityMap = new Dictionary<TypeStylePreference, DiagnosticSeverity>();
_styleToSeverityMap = new Dictionary<TypeStylePreference, ReportDiagnostic>();
}
public static State Generate(
......@@ -39,7 +39,7 @@ private State(bool isVariableDeclarationContext)
return state;
}
public DiagnosticSeverity GetDiagnosticSeverityPreference()
public ReportDiagnostic GetDiagnosticSeverityPreference()
{
if (IsInIntrinsicTypeContext)
{
......@@ -170,9 +170,9 @@ private TypeStylePreference GetCurrentTypeStylePreferences(OptionSet optionSet)
var styleForApparent = optionSet.GetOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent);
var styleForElsewhere = optionSet.GetOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeForIntrinsicTypes, styleForIntrinsicTypes.Notification.Value);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeWhereApparent, styleForApparent.Notification.Value);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeWherePossible, styleForElsewhere.Notification.Value);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeForIntrinsicTypes, styleForIntrinsicTypes.Notification.Severity);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeWhereApparent, styleForApparent.Notification.Severity);
_styleToSeverityMap.Add(TypeStylePreference.ImplicitTypeWherePossible, styleForElsewhere.Notification.Severity);
if (styleForIntrinsicTypes.Value)
{
......
......@@ -29,9 +29,9 @@ internal struct TypeStyleResult
/// things quickly, even if it's going against their stated style.
/// </summary>
public readonly bool IsStylePreferred;
public readonly DiagnosticSeverity Severity;
public readonly ReportDiagnostic Severity;
public TypeStyleResult(CSharpTypeStyleHelper helper, TypeSyntax typeName, SemanticModel semanticModel, OptionSet optionSet, bool isStylePreferred, DiagnosticSeverity severity, CancellationToken cancellationToken) : this()
public TypeStyleResult(CSharpTypeStyleHelper helper, TypeSyntax typeName, SemanticModel semanticModel, OptionSet optionSet, bool isStylePreferred, ReportDiagnostic severity, CancellationToken cancellationToken) : this()
{
_helper = helper;
_typeName = typeName;
......
......@@ -49,7 +49,7 @@ public CodeStyleOption(T value, NotificationOption notification)
new XAttribute(nameof(SerializationVersion), SerializationVersion),
new XAttribute("Type", GetTypeNameForSerialization()),
new XAttribute(nameof(Value), GetValueForSerialization()),
new XAttribute(nameof(DiagnosticSeverity), Notification.Value));
new XAttribute(nameof(DiagnosticSeverity), Notification.Severity.ToDiagnosticSeverity(DiagnosticSeverity.Hidden)));
private object GetValueForSerialization()
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.CodeAnalysis.CodeStyle
{
/// <summary>
......@@ -14,17 +16,28 @@ public class NotificationOption
{
public string Name { get; set; }
public DiagnosticSeverity Value { get; set; }
public ReportDiagnostic Severity
{
get;
set;
}
[Obsolete("Use " + nameof(Severity) + " instead.")]
public DiagnosticSeverity Value
{
get => Severity.ToDiagnosticSeverity(DiagnosticSeverity.Hidden);
set => Severity = value.ToReportDiagnostic();
}
public static readonly NotificationOption Silent = new NotificationOption(WorkspacesResources.None, DiagnosticSeverity.Hidden);
public static readonly NotificationOption Suggestion = new NotificationOption(WorkspacesResources.Suggestion, DiagnosticSeverity.Info);
public static readonly NotificationOption Warning = new NotificationOption(WorkspacesResources.Warning, DiagnosticSeverity.Warning);
public static readonly NotificationOption Error = new NotificationOption(WorkspacesResources.Error, DiagnosticSeverity.Error);
public static readonly NotificationOption Silent = new NotificationOption(WorkspacesResources.None, ReportDiagnostic.Hidden);
public static readonly NotificationOption Suggestion = new NotificationOption(WorkspacesResources.Suggestion, ReportDiagnostic.Info);
public static readonly NotificationOption Warning = new NotificationOption(WorkspacesResources.Warning, ReportDiagnostic.Warn);
public static readonly NotificationOption Error = new NotificationOption(WorkspacesResources.Error, ReportDiagnostic.Error);
private NotificationOption(string name, DiagnosticSeverity severity)
private NotificationOption(string name, ReportDiagnostic severity)
{
Name = name;
Value = severity;
Severity = severity;
}
public override string ToString() => Name;
......
......@@ -33,7 +33,7 @@ internal static partial class EditorConfigNamingStyleParser
private static bool TryGetRuleSeverity(
string namingRuleName,
IReadOnlyDictionary<string, object> conventionsDictionary,
out DiagnosticSeverity severity)
out ReportDiagnostic severity)
{
if (conventionsDictionary.TryGetValue($"dotnet_naming_rule.{namingRuleName}.severity", out object result))
{
......@@ -45,18 +45,18 @@ internal static partial class EditorConfigNamingStyleParser
return false;
}
private static DiagnosticSeverity ParseEnforcementLevel(string ruleSeverity)
private static ReportDiagnostic ParseEnforcementLevel(string ruleSeverity)
{
switch (ruleSeverity)
{
case EditorConfigSeverityStrings.None:
case EditorConfigSeverityStrings.Silent:
return DiagnosticSeverity.Hidden;
return ReportDiagnostic.Hidden;
case EditorConfigSeverityStrings.Suggestion: return DiagnosticSeverity.Info;
case EditorConfigSeverityStrings.Warning: return DiagnosticSeverity.Warning;
case EditorConfigSeverityStrings.Error: return DiagnosticSeverity.Error;
default: return DiagnosticSeverity.Hidden;
case EditorConfigSeverityStrings.Suggestion: return ReportDiagnostic.Info;
case EditorConfigSeverityStrings.Warning: return ReportDiagnostic.Warn;
case EditorConfigSeverityStrings.Error: return ReportDiagnostic.Error;
default: return ReportDiagnostic.Hidden;
}
}
}
......
......@@ -8,9 +8,9 @@ internal struct NamingRule
{
public readonly SymbolSpecification SymbolSpecification;
public readonly NamingStyle NamingStyle;
public readonly DiagnosticSeverity EnforcementLevel;
public readonly ReportDiagnostic EnforcementLevel;
public NamingRule(SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
public NamingRule(SymbolSpecification symbolSpecification, NamingStyle namingStyle, ReportDiagnostic enforcementLevel)
{
SymbolSpecification = symbolSpecification;
NamingStyle = namingStyle;
......
......@@ -9,7 +9,7 @@ internal class SerializableNamingRule
{
public Guid SymbolSpecificationID;
public Guid NamingStyleID;
public DiagnosticSeverity EnforcementLevel;
public ReportDiagnostic EnforcementLevel;
public NamingRule GetRule(NamingStylePreferences info)
{
......@@ -24,7 +24,7 @@ internal XElement CreateXElement()
var element = new XElement(nameof(SerializableNamingRule),
new XAttribute(nameof(SymbolSpecificationID), SymbolSpecificationID),
new XAttribute(nameof(NamingStyleID), NamingStyleID),
new XAttribute(nameof(EnforcementLevel), EnforcementLevel));
new XAttribute(nameof(EnforcementLevel), EnforcementLevel.ToDiagnosticSeverity(DiagnosticSeverity.Hidden)));
return element;
}
......@@ -33,7 +33,7 @@ internal static SerializableNamingRule FromXElement(XElement namingRuleElement)
{
return new SerializableNamingRule()
{
EnforcementLevel = (DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), namingRuleElement.Attribute(nameof(EnforcementLevel)).Value),
EnforcementLevel = ((DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), namingRuleElement.Attribute(nameof(EnforcementLevel)).Value)).ToReportDiagnostic(),
NamingStyleID = Guid.Parse(namingRuleElement.Attribute(nameof(NamingStyleID)).Value),
SymbolSpecificationID = Guid.Parse(namingRuleElement.Attribute(nameof(SymbolSpecificationID)).Value)
};
......
*REMOVED*static readonly Microsoft.CodeAnalysis.CodeStyle.NotificationOption.None -> Microsoft.CodeAnalysis.CodeStyle.NotificationOption
Microsoft.CodeAnalysis.CodeStyle.NotificationOption.Severity.get -> Microsoft.CodeAnalysis.ReportDiagnostic
Microsoft.CodeAnalysis.CodeStyle.NotificationOption.Severity.set -> void
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AliasImportDeclaration(string aliasIdentifierName, Microsoft.CodeAnalysis.SyntaxNode name) -> Microsoft.CodeAnalysis.SyntaxNode
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.NameExpression(Microsoft.CodeAnalysis.INamespaceOrTypeSymbol namespaceOrTypeSymbol) -> Microsoft.CodeAnalysis.SyntaxNode
const Microsoft.CodeAnalysis.WorkspaceKind.MSBuild = "MSBuildWorkspace" -> string
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -13,35 +13,35 @@ namespace Microsoft.CodeAnalysis.UnitTests.CodeStyle
public class EditorConfigCodeStyleParserTests
{
[Theory]
[InlineData("true:none", true, DiagnosticSeverity.Hidden)]
[InlineData("true:silent", true, DiagnosticSeverity.Hidden)]
[InlineData("true:suggestion", true, DiagnosticSeverity.Info)]
[InlineData("true:warning", true, DiagnosticSeverity.Warning)]
[InlineData("true:error", true, DiagnosticSeverity.Error)]
[InlineData("true", false, DiagnosticSeverity.Hidden)]
[InlineData("false:none", false, DiagnosticSeverity.Hidden)]
[InlineData("false:silent", false, DiagnosticSeverity.Hidden)]
[InlineData("false:suggestion", false, DiagnosticSeverity.Info)]
[InlineData("false:warning", false, DiagnosticSeverity.Warning)]
[InlineData("false:error", false, DiagnosticSeverity.Error)]
[InlineData("false", false, DiagnosticSeverity.Hidden)]
[InlineData("*", false, DiagnosticSeverity.Hidden)]
[InlineData("false:false", false, DiagnosticSeverity.Hidden)]
static void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, DiagnosticSeverity severity)
[InlineData("true:none", true, ReportDiagnostic.Hidden)]
[InlineData("true:silent", true, ReportDiagnostic.Hidden)]
[InlineData("true:suggestion", true, ReportDiagnostic.Info)]
[InlineData("true:warning", true, ReportDiagnostic.Warn)]
[InlineData("true:error", true, ReportDiagnostic.Error)]
[InlineData("true", false, ReportDiagnostic.Hidden)]
[InlineData("false:none", false, ReportDiagnostic.Hidden)]
[InlineData("false:silent", false, ReportDiagnostic.Hidden)]
[InlineData("false:suggestion", false, ReportDiagnostic.Info)]
[InlineData("false:warning", false, ReportDiagnostic.Warn)]
[InlineData("false:error", false, ReportDiagnostic.Error)]
[InlineData("false", false, ReportDiagnostic.Hidden)]
[InlineData("*", false, ReportDiagnostic.Hidden)]
[InlineData("false:false", false, ReportDiagnostic.Hidden)]
static void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, ReportDiagnostic severity)
{
var notificationOption = NotificationOption.Silent;
switch (severity)
{
case DiagnosticSeverity.Hidden:
case ReportDiagnostic.Hidden:
notificationOption = NotificationOption.Silent;
break;
case DiagnosticSeverity.Info:
case ReportDiagnostic.Info:
notificationOption = NotificationOption.Suggestion;
break;
case DiagnosticSeverity.Warning:
case ReportDiagnostic.Warn:
notificationOption = NotificationOption.Warning;
break;
case DiagnosticSeverity.Error:
case ReportDiagnostic.Error:
notificationOption = NotificationOption.Error;
break;
}
......@@ -51,8 +51,8 @@ static void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, Di
CodeStyleHelpers.TryParseBoolEditorConfigCodeStyleOption(args, out var result);
Assert.True(result.Value == isEnabled,
$"Expected {nameof(isEnabled)} to be {isEnabled}, was {result.Value}");
Assert.True(result.Notification.Value == severity,
$"Expected {nameof(severity)} to be {severity}, was {result.Notification.Value}");
Assert.True(result.Notification.Severity == severity,
$"Expected {nameof(severity)} to be {severity}, was {result.Notification.Severity}");
}
}
}
......@@ -73,7 +73,7 @@ public static void TestNonEmptyDictionaryReturnsTrue()
Assert.True(result, "Expected non-empty dictionary to return true");
var isNamingStylePreferencesObject = combinedNamingStyles is NamingStylePreferences;
Assert.True(isNamingStylePreferencesObject, $"Expected returned object to be of type '{nameof(NamingStylePreferences)}'");
Assert.Equal(DiagnosticSeverity.Error, ((NamingStylePreferences)combinedNamingStyles).Rules.NamingRules[0].EnforcementLevel);
Assert.Equal(ReportDiagnostic.Error, ((NamingStylePreferences)combinedNamingStyles).Rules.NamingRules[0].EnforcementLevel);
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册