提交 4648361f 编写于 作者: A Andrew Hall (METAL)

Code cleanup and styling

上级 a401308c
......@@ -11,6 +11,7 @@
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using VSCommanding = Microsoft.VisualStudio.Commanding;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.ExtractInterface
{
......@@ -70,11 +71,11 @@ public bool ExecuteCommand(ExtractInterfaceCommandArgs args, CommandExecutionCon
// and also will take it into consideration when measuring command handling duration.
context.OperationContext.TakeOwnership();
var extractInterfaceService = document.GetLanguageService<AbstractExtractInterfaceService>();
var result = extractInterfaceService.ExtractInterface(
var result = extractInterfaceService.ExtractInterfaceAsync(
document,
caretPoint.Value.Position,
(errorMessage, severity) => workspace.Services.GetService<INotificationService>().SendNotification(errorMessage, severity: severity),
CancellationToken.None);
CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
if (result == null || !result.Succeeded)
{
......
......@@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.VisualBasic.ExtractInterface;
using Microsoft.VisualStudio.Composition;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.UnitTests.ExtractInterface
{
......@@ -77,7 +78,7 @@ public Task<ExtractInterfaceTypeAnalysisResult> GetTypeAnalysisResultAsync(TypeD
public ExtractInterfaceResult ExtractViaCommand()
{
return ExtractInterfaceService.ExtractInterface(
return ExtractInterfaceService.ExtractInterfaceAsync(
ExtractFromDocument,
_testDocument.CursorPosition.Value,
(errorMessage, severity) =>
......@@ -85,7 +86,7 @@ public ExtractInterfaceResult ExtractViaCommand()
this.ErrorMessage = errorMessage;
this.ErrorSeverity = severity;
},
CancellationToken.None);
CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
}
public void Dispose()
......
......@@ -54,22 +54,17 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
: ImmutableArray<ExtractInterfaceCodeAction>.Empty;
}
public ExtractInterfaceResult ExtractInterface(
public async Task<ExtractInterfaceResult> ExtractInterfaceAsync(
Document documentWithTypeToExtractFrom,
int position,
Action<string, NotificationSeverity> errorHandler,
CancellationToken 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);
var typeAnalysisResult = await AnalyzeTypeAtPositionAsync(
documentWithTypeToExtractFrom,
position,
TypeDiscoveryRule.TypeDeclaration,
cancellationToken).ConfigureAwait(false);
if (!typeAnalysisResult.CanExtractInterface)
{
......@@ -77,7 +72,7 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
return new ExtractInterfaceResult(succeeded: false);
}
return await ExtractInterfaceFromAnalyzedType(typeAnalysisResult, cancellationToken);
return await ExtractInterfaceFromAnalyzedTypeAsync(typeAnalysisResult, cancellationToken).ConfigureAwait(false);
}
public async Task<ExtractInterfaceTypeAnalysisResult> AnalyzeTypeAtPositionAsync(
......@@ -112,7 +107,7 @@ public async Task<ImmutableArray<ExtractInterfaceCodeAction>> GetExtractInterfac
return new ExtractInterfaceTypeAnalysisResult(this, document, typeNode, typeToExtractFrom, extractableMembers);
}
public Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedType(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken)
public Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken)
{
var containingNamespaceDisplay = refactoringResult.TypeToExtractFrom.ContainingNamespace.IsGlobalNamespace
? string.Empty
......@@ -133,7 +128,10 @@ public Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedType(ExtractInte
return ExtractInterfaceFromAnalyzedTypeAsync(refactoringResult, extractInterfaceOptions, cancellationToken);
}
public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, ExtractInterfaceOptionsResult extractInterfaceOptions, CancellationToken cancellationToken)
public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
ExtractInterfaceTypeAnalysisResult refactoringResult,
ExtractInterfaceOptionsResult extractInterfaceOptions,
CancellationToken cancellationToken)
{
var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;
......@@ -193,7 +191,7 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
var interfaceDocumentId = DocumentId.CreateNewId(projectId, debugName: fileName);
var unformattedInterfaceDocument = await GetUnformattedInterfaceDocument(
var unformattedInterfaceDocument = await GetUnformattedInterfaceDocumentAsync(
solution,
containingNamespaceDisplay,
fileName,
......@@ -202,7 +200,10 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
interfaceDocumentId,
cancellationToken);
var solutionWithFormattedInterfaceDocument = await GetFormattedSolutionAsync(unformattedInterfaceDocument.Project.Solution, SpecializedCollections.SingletonList(unformattedInterfaceDocument.Id)).ConfigureAwait(false);
var solutionWithFormattedInterfaceDocument = await GetFormattedSolutionAsync(
unformattedInterfaceDocument.Project.Solution,
SpecializedCollections.SingletonList(unformattedInterfaceDocument.Id),
cancellationToken).ConfigureAwait(false);
var completedSolution = await GetSolutionWithOriginalTypeUpdatedAsync(
solutionWithFormattedInterfaceDocument,
......@@ -246,9 +247,9 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
var interfaceNode = codeGenService.CreateNamedTypeDeclaration(extractedInterfaceSymbol).WithAdditionalAnnotations(SimplificationHelpers.SimplifyModuleNameAnnotation);
typeDeclaration = currentRoot.GetCurrentNode(typeDeclaration);
editor.InsertBefore(typeDeclaration, interfaceNode.WithAdditionalAnnotations(Simplifier.Annotation));
editor.InsertBefore(typeDeclaration, interfaceNode);
var unformattedSolution = solution.WithDocumentSyntaxRoot(documentId, editor.GetChangedRoot(), PreservationMode.PreserveIdentity);
var unformattedSolution = document.WithSyntaxRoot(editor.GetChangedRoot()).Project.Solution;
var completedSolution = await GetSolutionWithOriginalTypeUpdatedAsync(
unformattedSolution, documentIds,
......@@ -299,7 +300,7 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
foreach (var root in currentRoots)
{
var document = solution.GetDocument(root.Key);
solution = solution.WithDocumentSyntaxRoot(document.Id, root.Value, PreservationMode.PreserveIdentity);
solution = document.WithSyntaxRoot(root.Value).Project.Solution;
}
return symbolToDeclarationAnnotationMap;
......@@ -331,7 +332,7 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
document.Project.Language);
}
private async Task<Document> GetUnformattedInterfaceDocument(
private async Task<Document> GetUnformattedInterfaceDocumentAsync(
Solution solution,
string containingNamespaceDisplay,
string name,
......@@ -355,7 +356,7 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
return unformattedInterfaceDocument;
}
private static async Task<Solution> GetSolutionWithFormattedInterfaceDocument(Document unformattedInterfaceDocument, CancellationToken cancellationToken)
private static async Task<Solution> GetSolutionWithFormattedInterfaceDocumentAsync(Document unformattedInterfaceDocument, CancellationToken cancellationToken)
{
Solution solutionWithInterfaceDocument;
var formattedRoot = Formatter.Format(unformattedInterfaceDocument.GetSyntaxRootSynchronously(cancellationToken),
......@@ -414,7 +415,7 @@ private async Task<Solution> GetFormattedSolutionAsync(Solution unformattedSolut
{
editor.AddInterfaceType(typeDeclaration, typeReference);
}
unformattedSolution = unformattedSolution.WithDocumentSyntaxRoot(documentId, editor.GetChangedRoot(), PreservationMode.PreserveIdentity);
unformattedSolution = document.WithSyntaxRoot(editor.GetChangedRoot()).Project.Solution;
}
var updatedUnformattedSolution = UpdateMembersWithExplicitImplementations(
......
using System;
using System.Collections.Generic;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册