提交 24c4cd21 编写于 作者: A Andrew Hall (METAL)

Fix async ExtractInterface call, since not all callers are async. Forward to...

Fix async ExtractInterface call, since not all callers are async. Forward to private async implementation
上级 0c77c5cd
......@@ -60,7 +60,16 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
Action<string, NotificationSeverity> 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<ExtractInterfaceResult> ExtractInterfaceAsync(
Document documentWithTypeToExtractFrom,
int position,
Action<string, NotificationSeverity> errorHandler,
CancellationToken cancellationToken)
{
var typeAnalysisResult = await AnalyzeTypeAtPositionAsync(documentWithTypeToExtractFrom, position, TypeDiscoveryRule.TypeDeclaration, cancellationToken).ConfigureAwait(false);
if (!typeAnalysisResult.CanExtractInterface)
{
......@@ -68,7 +77,7 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
return new ExtractInterfaceResult(succeeded: false);
}
return ExtractInterfaceFromAnalyzedType(typeAnalysisResult, cancellationToken);
return await ExtractInterfaceFromAnalyzedType(typeAnalysisResult, cancellationToken);
}
public async Task<ExtractInterfaceTypeAnalysisResult> AnalyzeTypeAtPositionAsync(
......@@ -103,7 +112,7 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
return new ExtractInterfaceTypeAnalysisResult(this, document, typeNode, typeToExtractFrom, extractableMembers);
}
public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken)
public Task<ExtractInterfaceResult> 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<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken)
......@@ -184,7 +193,7 @@ public async Task<ExtractInterfaceResult> 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<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
document.Project.Language);
}
private Document GetUnformattedInterfaceDocument(
private async Task<Document> GetUnformattedInterfaceDocument(
Solution solution,
string containingNamespaceDisplay,
string name,
......@@ -334,40 +343,26 @@ public async Task<ExtractInterfaceResult> 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<Solution> 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<Solution> 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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册