提交 58d8babc 编写于 作者: H HeeJae Chang

Merge branch 'partial_load' of https://github.com/dibarbet/roslyn into partial_load_hechang

......@@ -16,6 +16,7 @@
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
using Roslyn.Utilities;
using VSCommanding = Microsoft.VisualStudio.Commanding;
namespace Microsoft.CodeAnalysis.Editor.GoToImplementation
......@@ -34,18 +35,13 @@ internal partial class GoToImplementationCommandHandler : VSCommanding.ICommandH
_streamingPresenters = streamingPresenters;
}
private (Document, IFindUsagesService) GetDocumentAndService(ITextSnapshot snapshot)
{
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
return (document, document?.GetLanguageService<IFindUsagesService>());
}
public string DisplayName => EditorFeaturesResources.Go_To_Implementation;
public VSCommanding.CommandState GetCommandState(GoToImplementationCommandArgs args)
{
// Because this is expensive to compute, we just always say yes as long as the language allows it.
var (document, findUsagesService) = GetDocumentAndService(args.SubjectBuffer.CurrentSnapshot);
var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
var findUsagesService = document?.GetLanguageService<IFindUsagesService>();
return findUsagesService != null
? VSCommanding.CommandState.Available
: VSCommanding.CommandState.Unavailable;
......@@ -53,18 +49,24 @@ public VSCommanding.CommandState GetCommandState(GoToImplementationCommandArgs a
public bool ExecuteCommand(GoToImplementationCommandArgs args, CommandExecutionContext context)
{
var (document, findUsagesService) = GetDocumentAndService(args.SubjectBuffer.CurrentSnapshot);
if (findUsagesService != null)
using (context.OperationContext.AddScope(allowCancellation: true, EditorFeaturesResources.Locating_implementations))
{
var caret = args.TextView.GetCaretPoint(args.SubjectBuffer);
if (caret.HasValue)
var subjectBuffer = args.SubjectBuffer;
var document = subjectBuffer.CurrentSnapshot.GetFullyLoadedOpenDocumentInCurrentContextWithChangesAsync(
context.OperationContext).WaitAndGetResult(context.OperationContext.UserCancellationToken);
var findUsagesService = document?.GetLanguageService<IFindUsagesService>();
if (findUsagesService != null)
{
ExecuteCommand(document, caret.Value, findUsagesService, context);
return true;
var caret = args.TextView.GetCaretPoint(args.SubjectBuffer);
if (caret.HasValue)
{
ExecuteCommand(document, caret.Value, findUsagesService, context);
return true;
}
}
}
return false;
return false;
}
}
private void ExecuteCommand(
......@@ -80,8 +82,6 @@ public bool ExecuteCommand(GoToImplementationCommandArgs args, CommandExecutionC
string messageToShow = null;
var userCancellationToken = context.OperationContext.UserCancellationToken;
using (context.OperationContext.AddScope(allowCancellation: true, EditorFeaturesResources.Locating_implementations))
using (Logger.LogBlock(FunctionId.CommandHandler_GoToImplementation, KeyValueLogMessage.Create(LogType.UserAction), userCancellationToken))
{
StreamingGoToImplementation(
......
......@@ -12,6 +12,7 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Roslyn.Utilities;
using VSCommanding = Microsoft.VisualStudio.Commanding;
namespace Microsoft.CodeAnalysis.Editor.Implementation.ChangeSignature
......@@ -53,37 +54,36 @@ public bool ExecuteCommand(ReorderParametersCommandArgs args, CommandExecutionCo
private bool ExecuteCommand(ITextView textView, ITextBuffer subjectBuffer, CommandExecutionContext context)
{
var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return false;
}
// TODO: reuse GetCommandState instead
var workspace = document.Project.Solution.Workspace;
if (!workspace.CanApplyChange(ApplyChangesKind.ChangeDocument))
using (context.OperationContext.AddScope(allowCancellation: true, FeaturesResources.Change_signature))
{
return false;
}
var document = subjectBuffer.CurrentSnapshot.GetFullyLoadedOpenDocumentInCurrentContextWithChangesAsync(
context.OperationContext).WaitAndGetResult(context.OperationContext.UserCancellationToken);
if (document == null)
{
return false;
}
var supportsFeatureService = document.Project.Solution.Workspace.Services.GetService<IDocumentSupportsFeatureService>();
if (!supportsFeatureService.SupportsRefactorings(document))
{
return false;
}
// TODO: reuse GetCommandState instead
var workspace = document.Project.Solution.Workspace;
if (!workspace.CanApplyChange(ApplyChangesKind.ChangeDocument))
{
return false;
}
var caretPoint = textView.GetCaretPoint(subjectBuffer);
if (!caretPoint.HasValue)
{
return false;
}
var supportsFeatureService = document.Project.Solution.Workspace.Services.GetService<IDocumentSupportsFeatureService>();
if (!supportsFeatureService.SupportsRefactorings(document))
{
return false;
}
ChangeSignatureResult result = null;
var caretPoint = textView.GetCaretPoint(subjectBuffer);
if (!caretPoint.HasValue)
{
return false;
}
using (context.OperationContext.AddScope(allowCancellation: true, FeaturesResources.Change_signature))
{
var reorderParametersService = document.GetLanguageService<AbstractChangeSignatureService>();
result = reorderParametersService.ChangeSignature(
var result = reorderParametersService.ChangeSignature(
document,
caretPoint.Value.Position,
(errorMessage, severity) =>
......@@ -94,51 +94,51 @@ private bool ExecuteCommand(ITextView textView, ITextBuffer subjectBuffer, Comma
context.OperationContext.TakeOwnership();
workspace.Services.GetService<INotificationService>().SendNotification(errorMessage, severity: severity);
},
context.OperationContext.UserCancellationToken);
}
context.OperationContext.UserCancellationToken);
if (result == null || !result.Succeeded)
{
return true;
}
var finalSolution = result.UpdatedSolution;
if (result == null || !result.Succeeded)
{
return true;
}
var previewService = workspace.Services.GetService<IPreviewDialogService>();
if (previewService != null && result.PreviewChanges)
{
// We are about to show a modal UI dialog so we should take over the command execution
// wait context. That means the command system won't attempt to show its own wait dialog
// and also will take it into consideration when measuring command handling duration.
context.OperationContext.TakeOwnership();
finalSolution = previewService.PreviewChanges(
string.Format(EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Change_Signature),
"vs.csharp.refactoring.preview",
EditorFeaturesResources.Change_Signature_colon,
result.Name,
result.Glyph.GetValueOrDefault(),
result.UpdatedSolution,
document.Project.Solution);
}
var finalSolution = result.UpdatedSolution;
if (finalSolution == null)
{
// User clicked cancel.
return true;
}
var previewService = workspace.Services.GetService<IPreviewDialogService>();
if (previewService != null && result.PreviewChanges)
{
// We are about to show a modal UI dialog so we should take over the command execution
// wait context. That means the command system won't attempt to show its own wait dialog
// and also will take it into consideration when measuring command handling duration.
context.OperationContext.TakeOwnership();
finalSolution = previewService.PreviewChanges(
string.Format(EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Change_Signature),
"vs.csharp.refactoring.preview",
EditorFeaturesResources.Change_Signature_colon,
result.Name,
result.Glyph.GetValueOrDefault(),
result.UpdatedSolution,
document.Project.Solution);
}
using (var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(FeaturesResources.Change_signature))
{
if (!workspace.TryApplyChanges(finalSolution))
if (finalSolution == null)
{
// TODO: handle failure
// User clicked cancel.
return true;
}
workspaceUndoTransaction.Commit();
}
using (var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(FeaturesResources.Change_signature))
{
if (!workspace.TryApplyChanges(finalSolution))
{
// TODO: handle failure
return true;
}
workspaceUndoTransaction.Commit();
}
return true;
return true;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册