From f1045fddbafb4acbb988a7f87dcfb82e8a53bd9d Mon Sep 17 00:00:00 2001 From: Shyam N Date: Fri, 6 Mar 2015 00:39:49 -0800 Subject: [PATCH] Delete the public TriggerDiagnosticDescriptor type. And seal its base type DiagnosticDescriptor. (Fixes #789) --- .../Diagnostics/DiagnosticAnalyzerTests.cs | 16 ++++---- .../Core/Portable/CodeAnalysis.csproj | 1 - .../Diagnostic/DiagnosticDescriptor.cs | 5 +-- .../Diagnostic/TriggerDiagnosticDescriptor.cs | 25 ------------ src/Compilers/Core/Portable/PublicAPI.txt | 4 +- .../Diagnostics/DiagnosticAnalyzerTests.vb | 4 +- .../UnusedDeclarationsAnalyzer.cs | 3 +- .../DiagnosticAnalyzerDriverTests.cs | 3 +- .../FixAllProvider/BatchFixerTests.cs | 2 +- .../RenameTrackingDiagnosticAnalyzer.cs | 5 ++- .../Diagnostics/DiagnosticServiceTests.vb | 23 +++++------ ...nnecessaryImportsDiagnosticAnalyzerBase.cs | 10 ++++- src/Test/Utilities/DescriptorFactory.cs | 30 +++++++++++++++ src/Test/Utilities/TestUtilities.csproj | 3 +- .../PreviewPane/PreviewPaneService.cs | 38 ++++++++++--------- 15 files changed, 90 insertions(+), 82 deletions(-) delete mode 100644 src/Compilers/Core/Portable/Diagnostic/TriggerDiagnosticDescriptor.cs create mode 100644 src/Test/Utilities/DescriptorFactory.cs diff --git a/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs b/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs index 380647aa1c593..5ec8dd67b1da8 100644 --- a/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs @@ -3,10 +3,8 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Globalization; using System.Linq; using System.Runtime.Serialization; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Diagnostics; @@ -841,12 +839,12 @@ public class CodeBlockOrSyntaxNodeAnalyzer : DiagnosticAnalyzer { private readonly bool _isCodeBlockAnalyzer; - public static DiagnosticDescriptor Desciptor1 = new TriggerDiagnosticDescriptor("CodeBlockDiagnostic"); - public static DiagnosticDescriptor Desciptor2 = new TriggerDiagnosticDescriptor("EqualsValueDiagnostic"); - public static DiagnosticDescriptor Desciptor3 = new TriggerDiagnosticDescriptor("ConstructorInitializerDiagnostic"); - public static DiagnosticDescriptor Desciptor4 = new TriggerDiagnosticDescriptor("PropertyExpressionBodyDiagnostic"); - public static DiagnosticDescriptor Desciptor5 = new TriggerDiagnosticDescriptor("IndexerExpressionBodyDiagnostic"); - public static DiagnosticDescriptor Desciptor6 = new TriggerDiagnosticDescriptor("MethodExpressionBodyDiagnostic"); + public static DiagnosticDescriptor Desciptor1 = DescriptorFactory.CreateSimpleDescriptor("CodeBlockDiagnostic"); + public static DiagnosticDescriptor Desciptor2 = DescriptorFactory.CreateSimpleDescriptor("EqualsValueDiagnostic"); + public static DiagnosticDescriptor Desciptor3 = DescriptorFactory.CreateSimpleDescriptor("ConstructorInitializerDiagnostic"); + public static DiagnosticDescriptor Desciptor4 = DescriptorFactory.CreateSimpleDescriptor("PropertyExpressionBodyDiagnostic"); + public static DiagnosticDescriptor Desciptor5 = DescriptorFactory.CreateSimpleDescriptor("IndexerExpressionBodyDiagnostic"); + public static DiagnosticDescriptor Desciptor6 = DescriptorFactory.CreateSimpleDescriptor("MethodExpressionBodyDiagnostic"); public CodeBlockOrSyntaxNodeAnalyzer(bool isCodeBlockAnalyzer) { @@ -936,6 +934,6 @@ public override void Initialize(AnalysisContext context) ctxt.ReportDiagnostic(CodeAnalysis.Diagnostic.Create(Desciptor1, method.Locations[0], method.ToDisplayString())); }, SymbolKind.Method); } - } + } } } diff --git a/src/Compilers/Core/Portable/CodeAnalysis.csproj b/src/Compilers/Core/Portable/CodeAnalysis.csproj index 5949952aa4cd3..6af428587b5d2 100644 --- a/src/Compilers/Core/Portable/CodeAnalysis.csproj +++ b/src/Compilers/Core/Portable/CodeAnalysis.csproj @@ -174,7 +174,6 @@ - diff --git a/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs b/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs index 3e2e11d4d3ec5..7cc6fac40af30 100644 --- a/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs +++ b/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs @@ -1,18 +1,17 @@ // 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; using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Globalization; using Microsoft.CodeAnalysis.Diagnostics; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis { /// /// Provides a description about a /// - public class DiagnosticDescriptor : IEquatable + public sealed class DiagnosticDescriptor : IEquatable { /// /// An unique identifier for the diagnostic. diff --git a/src/Compilers/Core/Portable/Diagnostic/TriggerDiagnosticDescriptor.cs b/src/Compilers/Core/Portable/Diagnostic/TriggerDiagnosticDescriptor.cs deleted file mode 100644 index e1f24a7d1d5dd..0000000000000 --- a/src/Compilers/Core/Portable/Diagnostic/TriggerDiagnosticDescriptor.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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.Collections.Immutable; -using System.Linq; -using Roslyn.Utilities; - -namespace Microsoft.CodeAnalysis -{ - /// - /// Provides a description about a that is a trigger for some custom behavior for code analyis clients. - /// - public class TriggerDiagnosticDescriptor : DiagnosticDescriptor - { - /// - /// Create a TriggerDiagnosticDescriptor, which provides description about a that is a trigger for some custom behavior for code analyis clients. - /// - /// A unique identifier for the diagnostic. For example, code analysis diagnostic ID "CA1001". - /// Optional custom tags for the diagnostic. See for some well known tags. - public TriggerDiagnosticDescriptor(string id, params string[] customTags) - : base(id, title: "", messageFormat: "", category: "", defaultSeverity: DiagnosticSeverity.Hidden, isEnabledByDefault: true, - customTags: customTags.Append(WellKnownDiagnosticTags.NotConfigurable)) - { - } - } -} diff --git a/src/Compilers/Core/Portable/PublicAPI.txt b/src/Compilers/Core/Portable/PublicAPI.txt index 1befc33dc47b1..d76317129421c 100644 --- a/src/Compilers/Core/Portable/PublicAPI.txt +++ b/src/Compilers/Core/Portable/PublicAPI.txt @@ -1383,8 +1383,6 @@ Microsoft.CodeAnalysis.Text.TextSpan.Overlap(Microsoft.CodeAnalysis.Text.TextSpa Microsoft.CodeAnalysis.Text.TextSpan.OverlapsWith(Microsoft.CodeAnalysis.Text.TextSpan span) Microsoft.CodeAnalysis.Text.TextSpan.Start.get Microsoft.CodeAnalysis.Text.TextSpan.TextSpan(int start, int length) -Microsoft.CodeAnalysis.TriggerDiagnosticDescriptor -Microsoft.CodeAnalysis.TriggerDiagnosticDescriptor.TriggerDiagnosticDescriptor(string id, params string[] customTags) Microsoft.CodeAnalysis.TypeInfo Microsoft.CodeAnalysis.TypeInfo.ConvertedType.get Microsoft.CodeAnalysis.TypeInfo.Equals(Microsoft.CodeAnalysis.TypeInfo other) @@ -2128,4 +2126,4 @@ virtual Microsoft.CodeAnalysis.Text.SourceText.ToString(Microsoft.CodeAnalysis.T virtual Microsoft.CodeAnalysis.Text.SourceText.WithChanges(System.Collections.Generic.IEnumerable changes) virtual Microsoft.CodeAnalysis.Text.SourceText.Write(System.IO.TextWriter writer, Microsoft.CodeAnalysis.Text.TextSpan span, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) virtual Microsoft.CodeAnalysis.Text.TextLineCollection.GetLineFromPosition(int position) -virtual Microsoft.CodeAnalysis.Text.TextLineCollection.GetLinePosition(int position) \ No newline at end of file +virtual Microsoft.CodeAnalysis.Text.TextLineCollection.GetLinePosition(int position) diff --git a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb index 14901222663d2..0014dd69d2ac6 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb @@ -1,9 +1,7 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Collections.Immutable -Imports System.Globalization Imports System.Runtime.Serialization -Imports System.Threading Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Diagnostics.VisualBasic Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -523,7 +521,7 @@ End Namespace Private Class CodeBlockAnalyzer Inherits DiagnosticAnalyzer - Private Shared Descriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("CodeBlockDiagnostic") + Private Shared Descriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("CodeBlockDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get diff --git a/src/Diagnostics/Roslyn/Core/Maintainability/UnusedDeclarationsAnalyzer.cs b/src/Diagnostics/Roslyn/Core/Maintainability/UnusedDeclarationsAnalyzer.cs index a49fffcbb239a..080394c7d0fe2 100644 --- a/src/Diagnostics/Roslyn/Core/Maintainability/UnusedDeclarationsAnalyzer.cs +++ b/src/Diagnostics/Roslyn/Core/Maintainability/UnusedDeclarationsAnalyzer.cs @@ -20,7 +20,8 @@ internal abstract partial class UnusedDeclarationsAnalyzer : internal static readonly DiagnosticDescriptor s_rule = new DiagnosticDescriptor(RoslynDiagnosticIds.DeadCodeRuleId, s_title, s_messageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true); - internal static readonly DiagnosticDescriptor s_triggerRule = new TriggerDiagnosticDescriptor(RoslynDiagnosticIds.DeadCodeTriggerRuleId, WellKnownDiagnosticTags.Unnecessary, WellKnownDiagnosticTags.Telemetry); + internal static readonly DiagnosticDescriptor s_triggerRule = new DiagnosticDescriptor(RoslynDiagnosticIds.DeadCodeTriggerRuleId, title: "", messageFormat: "", category: "", defaultSeverity: DiagnosticSeverity.Hidden, isEnabledByDefault: true, + customTags: new[] { WellKnownDiagnosticTags.NotConfigurable, WellKnownDiagnosticTags.Unnecessary, WellKnownDiagnosticTags.Telemetry }); public override ImmutableArray SupportedDiagnostics { diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs index c6bbc38b15e29..0bd3c57783d3e 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Diagnostics; @@ -253,7 +252,7 @@ void F(int x = 0, int y = 1, int z = 2) private class CodeBlockAnalyzerFactory : DiagnosticAnalyzer { - public static DiagnosticDescriptor Desciptor = new TriggerDiagnosticDescriptor("DummyDiagnostic"); + public static DiagnosticDescriptor Desciptor = DescriptorFactory.CreateSimpleDescriptor("DummyDiagnostic"); public override ImmutableArray SupportedDiagnostics { diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs index 83d58407431a1..bc3967151b2fd 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs @@ -23,7 +23,7 @@ internal override Tuple CreateDiagnosticPro [DiagnosticAnalyzer(LanguageNames.CSharp)] private class QualifyWithThisAnalyzer : DiagnosticAnalyzer { - public static readonly DiagnosticDescriptor Descriptor = new TriggerDiagnosticDescriptor("QualifyWithThis"); + public static readonly DiagnosticDescriptor Descriptor = DescriptorFactory.CreateSimpleDescriptor("QualifyWithThis"); public override ImmutableArray SupportedDiagnostics { diff --git a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingDiagnosticAnalyzer.cs b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingDiagnosticAnalyzer.cs index 08a9675643bfe..558e438ab6f41 100644 --- a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingDiagnosticAnalyzer.cs +++ b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingDiagnosticAnalyzer.cs @@ -10,8 +10,9 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.RenameTracking internal sealed class RenameTrackingDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer { public const string DiagnosticId = "RenameTracking"; - public static DiagnosticDescriptor DiagnosticDescriptor = new TriggerDiagnosticDescriptor( - DiagnosticId, + public static DiagnosticDescriptor DiagnosticDescriptor = new DiagnosticDescriptor( + DiagnosticId, title: "", messageFormat: "", category: "", + defaultSeverity: DiagnosticSeverity.Hidden, isEnabledByDefault: true, customTags: DiagnosticCustomTags.Microsoft.Append(WellKnownDiagnosticTags.NotConfigurable)); internal const string RenameFromPropertyKey = "RenameFrom"; diff --git a/src/EditorFeatures/Test2/Diagnostics/DiagnosticServiceTests.vb b/src/EditorFeatures/Test2/Diagnostics/DiagnosticServiceTests.vb index 5b531c91986f4..088ebe458786c 100644 --- a/src/EditorFeatures/Test2/Diagnostics/DiagnosticServiceTests.vb +++ b/src/EditorFeatures/Test2/Diagnostics/DiagnosticServiceTests.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Diagnostics.EngineV1 Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.Text Imports Roslyn.Utilities Imports Xunit.Sdk @@ -1124,7 +1125,7 @@ public class B Me.indexOfDeclToReportDiagnostic = indexOfDeclToReportDiagnostic End Sub - Public Shared ReadOnly DiagDescriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("DummyDiagnostic") + Public Shared ReadOnly DiagDescriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("DummyDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get @@ -1168,7 +1169,7 @@ public class B Private Class CodeBlockStartedAnalyzer(Of TLanguageKindEnum As Structure) Inherits DiagnosticAnalyzer - Public Shared Descriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("DummyDiagnostic") + Public Shared Descriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("DummyDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get @@ -1196,7 +1197,7 @@ public class B Private Class CodeBlockEndedAnalyzer Inherits DiagnosticAnalyzer - Public Shared Descriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("DummyDiagnostic") + Public Shared Descriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("DummyDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get @@ -1222,7 +1223,7 @@ public class B Private Class CodeBlockStartedAndEndedAnalyzer(Of TLanguageKindEnum As Structure) Inherits DiagnosticAnalyzer - Public Shared Descriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("DummyDiagnostic") + Public Shared Descriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("DummyDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get @@ -1248,7 +1249,7 @@ public class B Private Class CompilationEndedAnalyzer Inherits DiagnosticAnalyzer - Public Shared Descriptor As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("CompilationEndedAnalyzerDiagnostic") + Public Shared Descriptor As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("CompilationEndedAnalyzerDiagnostic") Public Overrides ReadOnly Property SupportedDiagnostics As ImmutableArray(Of DiagnosticDescriptor) Get @@ -1312,12 +1313,12 @@ public class B Private ReadOnly _isCodeBlockAnalyzer As Boolean - Public Shared Desciptor1 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("CodeBlockDiagnostic") - Public Shared Desciptor2 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("EqualsValueDiagnostic") - Public Shared Desciptor3 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("ConstructorInitializerDiagnostic") - Public Shared Desciptor4 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("PropertyExpressionBodyDiagnostic") - Public Shared Desciptor5 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("IndexerExpressionBodyDiagnostic") - Public Shared Desciptor6 As DiagnosticDescriptor = New TriggerDiagnosticDescriptor("MethodExpressionBodyDiagnostic") + Public Shared Desciptor1 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("CodeBlockDiagnostic") + Public Shared Desciptor2 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("EqualsValueDiagnostic") + Public Shared Desciptor3 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("ConstructorInitializerDiagnostic") + Public Shared Desciptor4 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("PropertyExpressionBodyDiagnostic") + Public Shared Desciptor5 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("IndexerExpressionBodyDiagnostic") + Public Shared Desciptor6 As DiagnosticDescriptor = DescriptorFactory.CreateSimpleDescriptor("MethodExpressionBodyDiagnostic") Public Sub New(isCodeBlockAnalyzer As Boolean) _isCodeBlockAnalyzer = isCodeBlockAnalyzer diff --git a/src/Features/Core/Diagnostics/Analyzers/RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs b/src/Features/Core/Diagnostics/Analyzers/RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs index e26552b79e899..e5600373086c0 100644 --- a/src/Features/Core/Diagnostics/Analyzers/RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs +++ b/src/Features/Core/Diagnostics/Analyzers/RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs @@ -5,7 +5,6 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -27,7 +26,14 @@ internal abstract class RemoveUnnecessaryImportsDiagnosticAnalyzerBase : Diagnos isEnabledByDefault: true, customTags: DiagnosticCustomTags.Unnecessary); - private static readonly DiagnosticDescriptor s_fixableIdDescriptor = new TriggerDiagnosticDescriptor(DiagnosticFixableId); + // The NotConfigurable custom tag ensures that user can't turn this diagnostic into a warning / error via + // ruleset editor or solution explorer. Setting messageFormat to empty string ensures that we won't display + // this diagnostic in the preview pane header. + private static readonly DiagnosticDescriptor s_fixableIdDescriptor = new DiagnosticDescriptor(DiagnosticFixableId, + title: "", messageFormat: "", category: "", + defaultSeverity: DiagnosticSeverity.Hidden, + isEnabledByDefault: true, + customTags: WellKnownDiagnosticTags.NotConfigurable); private static readonly ImmutableArray s_descriptors = ImmutableArray.Create(s_fixableIdDescriptor, s_classificationIdDescriptor); diff --git a/src/Test/Utilities/DescriptorFactory.cs b/src/Test/Utilities/DescriptorFactory.cs new file mode 100644 index 0000000000000..0f19f174bc12f --- /dev/null +++ b/src/Test/Utilities/DescriptorFactory.cs @@ -0,0 +1,30 @@ +// 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 Microsoft.CodeAnalysis; + +namespace Roslyn.Test.Utilities +{ + /// + /// Factory for creating different kinds of s for use in tests. + /// + public static class DescriptorFactory + { + /// + /// Creates a with specified . + /// + /// + /// Returned has + /// - empty , and + /// - set to + /// - custom tag added in . + /// + /// The value for . + /// A with specified . + public static DiagnosticDescriptor CreateSimpleDescriptor(string id) + { + return new DiagnosticDescriptor(id, title: "", messageFormat: "", category: "", + defaultSeverity: DiagnosticSeverity.Hidden, isEnabledByDefault: true, + customTags: WellKnownDiagnosticTags.NotConfigurable); + } + } +} diff --git a/src/Test/Utilities/TestUtilities.csproj b/src/Test/Utilities/TestUtilities.csproj index abef6740c2a0f..bf3a10d18f63b 100644 --- a/src/Test/Utilities/TestUtilities.csproj +++ b/src/Test/Utilities/TestUtilities.csproj @@ -123,6 +123,7 @@ + @@ -229,4 +230,4 @@ - + \ No newline at end of file diff --git a/src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPaneService.cs b/src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPaneService.cs index 90e72657c4288..00973f880a4e4 100644 --- a/src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPaneService.cs +++ b/src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPaneService.cs @@ -65,29 +65,31 @@ private Image GetSeverityIconForDiagnostic(Diagnostic diagnostic) object IPreviewPaneService.GetPreviewPane(Diagnostic diagnostic, object previewContent) { - var telemetry = diagnostic == null ? false : diagnostic.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry); + var title = diagnostic?.GetMessage(); - if ((diagnostic == null) && (previewContent == null)) + if (string.IsNullOrWhiteSpace(title)) { - // Bail out in cases where there is no diagnostic (which means there is nothing to put in - // the header section of the preview pane) as well as no preview content (i.e. no diff view). - return null; - } + if (previewContent == null) + { + // Bail out in cases where there is nothing to put in the header section + // of the preview pane and no preview content (i.e. no diff view) either. + return null; + } - if ((diagnostic == null) || (diagnostic.Descriptor is TriggerDiagnosticDescriptor)) - { return new PreviewPane( - null, null, null, null, null, null, telemetry, previewContent, _serviceProvider); - } - else - { - return new PreviewPane( - GetSeverityIconForDiagnostic(diagnostic), - diagnostic.Id, diagnostic.GetMessage(), - diagnostic.Descriptor.MessageFormat.ToString(DiagnosticData.USCultureInfo), - diagnostic.Descriptor.Description.ToString(CultureInfo.CurrentUICulture), - diagnostic.Descriptor.HelpLinkUri, telemetry, previewContent, _serviceProvider); + severityIcon: null, id: null, title: null, helpMessage: null, + description: null, helpLink: null, telemetry: false, + previewContent: previewContent, serviceProvider: _serviceProvider); } + + return new PreviewPane( + GetSeverityIconForDiagnostic(diagnostic), + diagnostic.Id, title, + diagnostic.Descriptor.MessageFormat.ToString(DiagnosticData.USCultureInfo), + diagnostic.Descriptor.Description.ToString(CultureInfo.CurrentUICulture), + diagnostic.Descriptor.HelpLinkUri, + diagnostic.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry), + previewContent, _serviceProvider); } } }