From 24c4cd219d6e9265672f911768e0bfc9756e3a07 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Thu, 15 Nov 2018 17:04:41 -0800 Subject: [PATCH] Fix async ExtractInterface call, since not all callers are async. Forward to private async implementation --- .../AbstractExtractInterfaceService.cs | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs index af6cdf2e4c6..0ee373043ef 100644 --- a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs +++ b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs @@ -60,7 +60,16 @@ public async Task> GetExtractInterfac Action errorHandler, CancellationToken cancellationToken) { - var typeAnalysisResult = AnalyzeTypeAtPositionAsync(documentWithTypeToExtractFrom, position, TypeDiscoveryRule.TypeDeclaration, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + return ExtractInterfaceAsync(documentWithTypeToExtractFrom, position, errorHandler, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + } + + private async Task ExtractInterfaceAsync( + Document documentWithTypeToExtractFrom, + int position, + Action errorHandler, + CancellationToken cancellationToken) + { + var typeAnalysisResult = await AnalyzeTypeAtPositionAsync(documentWithTypeToExtractFrom, position, TypeDiscoveryRule.TypeDeclaration, cancellationToken).ConfigureAwait(false); if (!typeAnalysisResult.CanExtractInterface) { @@ -68,7 +77,7 @@ public async Task> GetExtractInterfac return new ExtractInterfaceResult(succeeded: false); } - return ExtractInterfaceFromAnalyzedType(typeAnalysisResult, cancellationToken); + return await ExtractInterfaceFromAnalyzedType(typeAnalysisResult, cancellationToken); } public async Task AnalyzeTypeAtPositionAsync( @@ -103,7 +112,7 @@ public async Task> GetExtractInterfac return new ExtractInterfaceTypeAnalysisResult(this, document, typeNode, typeToExtractFrom, extractableMembers); } - public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken) + public Task ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken) { var containingNamespaceDisplay = refactoringResult.TypeToExtractFrom.ContainingNamespace.IsGlobalNamespace ? string.Empty @@ -118,10 +127,10 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT if (extractInterfaceOptions.IsCancelled) { - return new ExtractInterfaceResult(succeeded: false); + return Task.FromResult(new ExtractInterfaceResult(succeeded: false)); } - return ExtractInterfaceFromAnalyzedTypeAsync(refactoringResult, extractInterfaceOptions, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + return ExtractInterfaceFromAnalyzedTypeAsync(refactoringResult, extractInterfaceOptions, cancellationToken); } public async Task ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken) @@ -184,7 +193,7 @@ public async Task ExtractInterfaceFromAnalyzedTypeAsync( var interfaceDocumentId = DocumentId.CreateNewId(projectId, debugName: fileName); - var unformattedInterfaceDocument = GetUnformattedInterfaceDocument( + var unformattedInterfaceDocument = await GetUnformattedInterfaceDocument( solution, containingNamespaceDisplay, fileName, @@ -323,7 +332,7 @@ public async Task ExtractInterfaceFromAnalyzedTypeAsync( document.Project.Language); } - private Document GetUnformattedInterfaceDocument( + private async Task GetUnformattedInterfaceDocument( Solution solution, string containingNamespaceDisplay, string name, @@ -334,40 +343,26 @@ public async Task ExtractInterfaceFromAnalyzedTypeAsync( { var solutionWithInterfaceDocument = solution.AddDocument(interfaceDocumentId, name, text: "", folders: folders); var interfaceDocument = solutionWithInterfaceDocument.GetDocument(interfaceDocumentId); - var interfaceDocumentSemanticModel = interfaceDocument.GetSemanticModelAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + var interfaceDocumentSemanticModel = await interfaceDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var namespaceParts = containingNamespaceDisplay.Split('.').Where(s => !string.IsNullOrEmpty(s)); - var unformattedInterfaceDocument = CodeGenerator.AddNamespaceOrTypeDeclarationAsync( + var unformattedInterfaceDocument = await CodeGenerator.AddNamespaceOrTypeDeclarationAsync( interfaceDocument.Project.Solution, interfaceDocumentSemanticModel.GetEnclosingNamespace(0, cancellationToken), extractedInterfaceSymbol.GenerateRootNamespaceOrType(namespaceParts.ToArray()), options: new CodeGenerationOptions(interfaceDocumentSemanticModel.SyntaxTree.GetLocation(new TextSpan())), - cancellationToken: cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + cancellationToken: cancellationToken).ConfigureAwait(false); return unformattedInterfaceDocument; } - private Document GetUnformattedInterfaceDocument( - Solution solution, - INamedTypeSymbol extractedInterfaceSymbol, - INamedTypeSymbol originalType, - DocumentId interfaceDocumentId, - CancellationToken cancellationToken) - { - return CodeGenerator.AddNamedTypeDeclarationAsync( - solution: solution, - destination: originalType.ContainingNamespace, - namedType: extractedInterfaceSymbol, - cancellationToken: cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); - } - - private static Solution GetSolutionWithFormattedInterfaceDocument(Document unformattedInterfaceDocument, CancellationToken cancellationToken) + private static async Task GetSolutionWithFormattedInterfaceDocument(Document unformattedInterfaceDocument, CancellationToken cancellationToken) { Solution solutionWithInterfaceDocument; var formattedRoot = Formatter.Format(unformattedInterfaceDocument.GetSyntaxRootSynchronously(cancellationToken), unformattedInterfaceDocument.Project.Solution.Workspace, cancellationToken: cancellationToken); var rootToSimplify = formattedRoot.WithAdditionalAnnotations(Simplifier.Annotation); - var finalInterfaceDocument = Simplifier.ReduceAsync(unformattedInterfaceDocument.WithSyntaxRoot(rootToSimplify), cancellationToken: cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + var finalInterfaceDocument = await Simplifier.ReduceAsync(unformattedInterfaceDocument.WithSyntaxRoot(rootToSimplify), cancellationToken: cancellationToken).ConfigureAwait(false); solutionWithInterfaceDocument = finalInterfaceDocument.Project.Solution; return solutionWithInterfaceDocument; @@ -436,10 +431,10 @@ private async Task GetFormattedSolutionAsync(Solution unformattedSolut foreach (var docId in documentIds) { - var formattedDoc = Formatter.FormatAsync( + var formattedDoc = await Formatter.FormatAsync( formattedSolution.GetDocument(docId), Formatter.Annotation, - cancellationToken: cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); + cancellationToken: cancellationToken).ConfigureAwait(false); formattedSolution = formattedDoc.Project.Solution; } -- GitLab