From d30cac3c9731d62faee4eaef3a5d2ac86be555ee Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 08:33:33 -0700 Subject: [PATCH] Remove diagnostic category flag --- .../DiagnosticAnalyzerDriverTests.cs | 2 +- .../Diagnostics/DiagnosticAnalyzerExtensions.cs | 16 +++++----------- .../Diagnostics/DiagnosticAnalyzerCategory.cs | 5 ----- .../Core/Diagnostics/IBuiltInAnalyzer.cs | 2 -- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs index 3f008e7634ab4..94eda2b4424d4 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs @@ -187,7 +187,7 @@ private class ThrowingDoNotCatchDiagnosticAnalyzer : Throwing public bool IsHighPriority => false; public DiagnosticAnalyzerCategory GetAnalyzerCategory() - => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis | DiagnosticAnalyzerCategory.ProjectAnalysis; + => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis; } [Fact] diff --git a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs index 229f85a8d1e32..f76d51c050d14 100644 --- a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs +++ b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs @@ -11,16 +11,16 @@ internal static partial class DiagnosticAnalyzerExtensions public static DiagnosticAnalyzerCategory GetDiagnosticAnalyzerCategory(this DiagnosticAnalyzer analyzer) => analyzer switch { - FileContentLoadAnalyzer _ => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis, - DocumentDiagnosticAnalyzer _ => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis, - ProjectDiagnosticAnalyzer _ => DiagnosticAnalyzerCategory.ProjectAnalysis, + FileContentLoadAnalyzer => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis, + DocumentDiagnosticAnalyzer => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis, + ProjectDiagnosticAnalyzer => DiagnosticAnalyzerCategory.None, IBuiltInAnalyzer builtInAnalyzer => builtInAnalyzer.GetAnalyzerCategory(), // Compiler analyzer supports syntax diagnostics, span-based semantic diagnostics and project level diagnostics. // For a public analyzer it is not possible to know the diagnostic categorization, so return a worst-case categorization. _ => analyzer.IsCompilerAnalyzer() - ? DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticSpanAnalysis | DiagnosticAnalyzerCategory.ProjectAnalysis - : DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis | DiagnosticAnalyzerCategory.ProjectAnalysis + ? DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticSpanAnalysis + : DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis, }; public static bool SupportAnalysisKind(this DiagnosticAnalyzer analyzer, AnalysisKind kind) @@ -48,10 +48,4 @@ public static bool SupportsSpanBasedSemanticDiagnosticAnalysis(this DiagnosticAn var category = analyzer.GetDiagnosticAnalyzerCategory(); return (category & DiagnosticAnalyzerCategory.SemanticSpanAnalysis) != 0; } - - public static bool SupportsProjectDiagnosticAnalysis(this DiagnosticAnalyzer analyzer) - { - var category = analyzer.GetDiagnosticAnalyzerCategory(); - return (category & DiagnosticAnalyzerCategory.ProjectAnalysis) != 0; - } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/DiagnosticAnalyzerCategory.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/DiagnosticAnalyzerCategory.cs index a7ab346aff75a..4e1f15ffb6fea 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/DiagnosticAnalyzerCategory.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/DiagnosticAnalyzerCategory.cs @@ -35,9 +35,4 @@ internal enum DiagnosticAnalyzerCategory /// It needs to re-analyze the whole document for reporting semantic diagnostics even for method body editing scenarios. /// SemanticDocumentAnalysis = 0x0100, - - /// - /// Analyzer reports project diagnostics (i.e. registers a Compilation action and/or Compilation end action diagnostics). - /// - ProjectAnalysis = 0x1000 } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/IBuiltInAnalyzer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/IBuiltInAnalyzer.cs index dfd4995fb5704..cddc36dce3814 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/IBuiltInAnalyzer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/IBuiltInAnalyzer.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CodeAnalysis.Simplification; - namespace Microsoft.CodeAnalysis.Diagnostics; ///