From 27b47fa19dd3b9dbe4bb3296a76c3acee43c3ede Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 31 Jul 2019 13:37:16 -0700 Subject: [PATCH] Follow new analyzer pattern --- .../UseExpressionBodyForLambdaCodeStyleProvider.cs | 4 +++- ...essionBodyForLambdaCodeStyleProvider_Analysis.cs | 3 +++ .../CodeStyle/AbstractCodeStyleProvider.Analysis.cs | 13 +++++++++++-- .../Portable/CodeStyle/AbstractCodeStyleProvider.cs | 5 +++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider.cs b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider.cs index cc52c035bbe..957a44842b6 100644 --- a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider.cs +++ b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -25,8 +26,9 @@ internal partial class UseExpressionBodyForLambdaCodeStyleProvider private static readonly LocalizableString UseExpressionBodyTitle = new LocalizableResourceString(nameof(FeaturesResources.Use_expression_body_for_lambda_expressions), FeaturesResources.ResourceManager, typeof(FeaturesResources)); private static readonly LocalizableString UseBlockBodyTitle = new LocalizableResourceString(nameof(FeaturesResources.Use_block_body_for_lambda_expressions), FeaturesResources.ResourceManager, typeof(FeaturesResources)); - public UseExpressionBodyForLambdaCodeStyleProvider() + public UseExpressionBodyForLambdaCodeStyleProvider() : base(CSharpCodeStyleOptions.PreferExpressionBodiedLambdas, + LanguageNames.CSharp, IDEDiagnosticIds.UseExpressionBodyForLambdaExpressionsDiagnosticId, UseExpressionBodyTitle, UseExpressionBodyTitle) diff --git a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs index 9c15ff1426b..24c69fb3b0d 100644 --- a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs +++ b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs @@ -17,6 +17,9 @@ protected override void DiagnosticAnalyzerInitialize(AnalysisContext context) => context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.SimpleLambdaExpression, SyntaxKind.ParenthesizedLambdaExpression); + protected override DiagnosticAnalyzerCategory GetAnalyzerCategory() + => DiagnosticAnalyzerCategory.SemanticSpanAnalysis; + private void AnalyzeSyntax(SyntaxNodeAnalysisContext context, CodeStyleOption option) { var declaration = (LambdaExpressionSyntax)context.Node; diff --git a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Analysis.cs b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Analysis.cs index c34f085b0a9..6cf7bed6516 100644 --- a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Analysis.cs +++ b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Analysis.cs @@ -3,6 +3,7 @@ using System; using System.Threading; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.CodeStyle { @@ -13,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CodeStyle internal abstract partial class AbstractCodeStyleProvider { - public abstract class DiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer + public abstract class DiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer { public readonly TCodeStyleProvider _codeStyleProvider; @@ -23,13 +24,21 @@ protected DiagnosticAnalyzer(bool configurable = true) } private DiagnosticAnalyzer(TCodeStyleProvider codeStyleProvider, bool configurable) - : base(codeStyleProvider._descriptorId, codeStyleProvider._title, codeStyleProvider._message, configurable) + : base(codeStyleProvider._descriptorId, + codeStyleProvider._option, + codeStyleProvider._language, + codeStyleProvider._title, + codeStyleProvider._message, + configurable) { _codeStyleProvider = codeStyleProvider; } protected sealed override void InitializeWorker(Diagnostics.AnalysisContext context) => _codeStyleProvider.DiagnosticAnalyzerInitialize(new AnalysisContext(_codeStyleProvider, context)); + + public sealed override DiagnosticAnalyzerCategory GetAnalyzerCategory() + => _codeStyleProvider.GetAnalyzerCategory(); } /// diff --git a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.cs b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.cs index ef33d139a5b..85d584a82c1 100644 --- a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.cs +++ b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Immutable; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; @@ -31,17 +32,20 @@ internal abstract partial class AbstractCodeStyleProvider< where TCodeStyleProvider : AbstractCodeStyleProvider, new() { private readonly Option> _option; + private readonly string _language; private readonly string _descriptorId; private readonly LocalizableString _title; private readonly LocalizableString _message; protected AbstractCodeStyleProvider( Option> option, + string language, string descriptorId, LocalizableString title, LocalizableString message) { _option = option; + _language = language; _descriptorId = descriptorId; _title = title; _message = message; @@ -63,6 +67,7 @@ protected static ReportDiagnostic GetOptionSeverity(CodeStyleOption #region analysis protected abstract void DiagnosticAnalyzerInitialize(AnalysisContext context); + protected abstract DiagnosticAnalyzerCategory GetAnalyzerCategory(); protected DiagnosticDescriptor CreateDescriptorWithId( LocalizableString title, LocalizableString message) -- GitLab