diff --git a/samples/CSharp/MakeConst/MakeConst.Implementation/MakeConstCodeFixProvider.cs b/samples/CSharp/MakeConst/MakeConst.Implementation/MakeConstCodeFixProvider.cs index 38dc6717a..87bb23a6f 100644 --- a/samples/CSharp/MakeConst/MakeConst.Implementation/MakeConstCodeFixProvider.cs +++ b/samples/CSharp/MakeConst/MakeConst.Implementation/MakeConstCodeFixProvider.cs @@ -17,17 +17,15 @@ namespace MakeConst { [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MakeConstCodeFixProvider)), Shared] - public class MakeConstCodeFixProvider : CodeFixProvider + public sealed class MakeConstCodeFixProvider : CodeFixProvider { - private const string title = "Make uppercase"; - public sealed override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create(MakeConstAnalyzer.MakeConstDiagnosticId); public sealed override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { - SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken); + SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); Diagnostic diagnostic = context.Diagnostics.First(); Microsoft.CodeAnalysis.Text.TextSpan diagnosticSpan = diagnostic.Location.SourceSpan; @@ -44,7 +42,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix(action, diagnostic); } - private async Task MakeConstAsync(Document document, LocalDeclarationStatementSyntax localDeclaration, CancellationToken cancellationToken) + private static async Task MakeConstAsync(Document document, LocalDeclarationStatementSyntax localDeclaration, CancellationToken cancellationToken) { // Remove the leading trivia from the local declaration. SyntaxToken firstToken = localDeclaration.GetFirstToken(); @@ -64,15 +62,15 @@ private async Task MakeConstAsync(Document document, LocalDeclarationS TypeSyntax variableTypeName = variableDeclaration.Type; if (variableTypeName.IsVar) { - SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken); + SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); // Special case: Ensure that 'var' isn't actually an alias to another type // (e.g. using var = System.String). - IAliasSymbol aliasInfo = semanticModel.GetAliasInfo(variableTypeName); + IAliasSymbol aliasInfo = semanticModel.GetAliasInfo(variableTypeName, cancellationToken); if (aliasInfo == null) { // Retrieve the type inferred for var. - ITypeSymbol type = semanticModel.GetTypeInfo(variableTypeName).ConvertedType; + ITypeSymbol type = semanticModel.GetTypeInfo(variableTypeName, cancellationToken).ConvertedType; // Special case: Ensure that 'var' isn't actually a type named 'var'. if (type.Name != "var") @@ -100,7 +98,7 @@ private async Task MakeConstAsync(Document document, LocalDeclarationS LocalDeclarationStatementSyntax formattedLocal = newLocal.WithAdditionalAnnotations(Formatter.Annotation); // Replace the old local declaration with the new local declaration. - SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken); + SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); SyntaxNode newRoot = root.ReplaceNode(localDeclaration, formattedLocal); // Return document with transformed tree. diff --git a/samples/VisualBasic/MakeConst/MakeConst/MakeConstCodeFixProvider.vb b/samples/VisualBasic/MakeConst/MakeConst/MakeConstCodeFixProvider.vb index 33bbecbc0..3c47cdf00 100644 --- a/samples/VisualBasic/MakeConst/MakeConst/MakeConstCodeFixProvider.vb +++ b/samples/VisualBasic/MakeConst/MakeConst/MakeConstCodeFixProvider.vb @@ -12,23 +12,24 @@ Imports Microsoft.CodeAnalysis.VisualBasic Imports Microsoft.CodeAnalysis.VisualBasic.Syntax -Public Class MakeConstCodeFixProvider +Public NotInheritable Class MakeConstCodeFixProvider Inherits CodeFixProvider - Public NotOverridable Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String) + Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String) Get Return ImmutableArray.Create(MakeConstAnalyzer.MakeConstDiagnosticId) End Get End Property - Public NotOverridable Overrides Function GetFixAllProvider() As FixAllProvider - Return Nothing + Public Overrides Function GetFixAllProvider() As FixAllProvider + ' See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers + Return WellKnownFixAllProviders.BatchFixer End Function - Public NotOverridable Overrides Async Function RegisterCodeFixesAsync(context As CodeFixContext) As Task + Public Overrides Async Function RegisterCodeFixesAsync(context As CodeFixContext) As Task Dim diagnostic = context.Diagnostics.First() Dim diagnosticSpan = diagnostic.Location.SourceSpan - Dim root = Await context.Document.GetSyntaxRootAsync(context.CancellationToken) + Dim root = Await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(False) ' Find the local declaration identified by the diagnostic. Dim declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType(Of LocalDeclarationStatementSyntax)().First() @@ -42,7 +43,7 @@ Public Class MakeConstCodeFixProvider context.RegisterCodeFix(action, diagnostic) End Function - Private Async Function MakeConstAsync(document As Document, localDeclaration As LocalDeclarationStatementSyntax, cancellationToken As CancellationToken) As Task(Of Document) + Private Shared Async Function MakeConstAsync(document As Document, localDeclaration As LocalDeclarationStatementSyntax, cancellationToken As CancellationToken) As Task(Of Document) ' Create a const token with the leading trivia from the local declaration. Dim firstToken = localDeclaration.GetFirstToken() Dim constToken = SyntaxFactory.Token( @@ -58,7 +59,7 @@ Public Class MakeConstCodeFixProvider Dim formattedLocalDeclaration = newLocalDeclaration.WithAdditionalAnnotations(Formatter.Annotation) ' Replace the old local declaration with the new local declaration. - Dim root = Await document.GetSyntaxRootAsync(cancellationToken) + Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) Dim newRoot = root.ReplaceNode(localDeclaration, formattedLocalDeclaration) ' Return document with transformed tree.