private void UpdateWorkspaceForResetOfTypedIdentifier(Workspace workspace, Solution newSolution, int trackingSessionId) { _stateMachine.ThreadingContext.ThrowIfNotOnUIThread(); // Update document in an ITextUndoTransaction with custom behaviors on undo/redo to // deal with the state machine. var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using var localUndoTransaction = undoHistory.CreateTransaction(EditorFeaturesResources.Text_Buffer_Change); var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: true); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { Contract.Fail("Rename Tracking could not update solution."); } // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); }
private (NotificationSeverity, string)? TryUpdateWorkspaceForResetOfTypedIdentifier(Workspace workspace, Solution newSolution, int trackingSessionId) { _stateMachine.ThreadingContext.ThrowIfNotOnUIThread(); // Update document in an ITextUndoTransaction with custom behaviors on undo/redo to // deal with the state machine. var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using var localUndoTransaction = undoHistory.CreateTransaction(EditorFeaturesResources.Text_Buffer_Change); var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: true); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { return(NotificationSeverity.Error, EditorFeaturesResources.Rename_operation_could_not_complete_due_to_external_change_to_workspace); } // If we successfully updated the workspace then make sure the undo transaction is committed and is // always able to undo anything any other external listener did. // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); return(null); }
private (NotificationSeverity, string)? TryUpdateWorkspaceForGlobalIdentifierRename( Workspace workspace, Solution newSolution, string undoName, IEnumerable <DocumentId> changedDocuments, ISymbol symbol, string newName, int trackingSessionId) { _stateMachine.ThreadingContext.ThrowIfNotOnUIThread(); // Perform rename in a workspace undo action so that undo will revert all // references. It should also be performed in an ITextUndoTransaction to handle var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(undoName); using var localUndoTransaction = undoHistory.CreateTransaction(undoName); var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { return(NotificationSeverity.Error, EditorFeaturesResources.Rename_operation_could_not_complete_due_to_external_change_to_workspace); } try { if (!_refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: false)) { return(NotificationSeverity.Information, EditorFeaturesResources.Rename_operation_was_not_properly_completed_Some_file_might_not_have_been_updated); } return(null); } finally { // If we successfully updated the workspace then make sure the undo transaction is committed and is // always able to undo anything any other external listener did. // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); workspaceUndoTransaction.Commit(); } }
private void UpdateWorkspaceForGlobalIdentifierRename( Workspace workspace, Solution newSolution, Solution oldSolution, string undoName, IEnumerable <DocumentId> changedDocuments, ISymbol symbol, string newName, int trackingSessionId) { AssertIsForeground(); // Perform rename in a workspace undo action so that undo will revert all // references. It should also be performed in an ITextUndoTransaction to handle var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(undoName); using var localUndoTransaction = undoHistory.CreateTransaction(undoName); var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { Contract.Fail("Rename Tracking could not update solution."); } if (!_refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: false)) { var notificationService = workspace.Services.GetService <INotificationService>(); notificationService.SendNotification( EditorFeaturesResources.Rename_operation_was_not_properly_completed_Some_file_might_not_have_been_updated, EditorFeaturesResources.Rename_Symbol, NotificationSeverity.Information); } // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); workspaceUndoTransaction.Commit(); }
private void UpdateWorkspaceForGlobalIdentifierRename( Workspace workspace, Solution newSolution, Solution oldSolution, string undoName, IEnumerable<DocumentId> changedDocuments, ISymbol symbol, string newName, int trackingSessionId) { AssertIsForeground(); // Perform rename in a workspace undo action so that undo will revert all // references. It should also be performed in an ITextUndoTransaction to handle var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using (var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(undoName)) using (var localUndoTransaction = undoHistory.CreateTransaction(undoName)) { var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { Contract.Fail("Rename Tracking could not update solution."); } if (!_refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: false)) { var notificationService = workspace.Services.GetService<INotificationService>(); notificationService.SendNotification( EditorFeaturesResources.RenameOperationWasNotProperlyCompleted, EditorFeaturesResources.RenameSymbol, NotificationSeverity.Information); } // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); workspaceUndoTransaction.Commit(); } }
private void UpdateWorkspaceForResetOfTypedIdentifier(Workspace workspace, Solution newSolution, int trackingSessionId) { AssertIsForeground(); // Update document in an ITextUndoTransaction with custom behaviors on undo/redo to // deal with the state machine. var undoHistory = _undoHistoryRegistry.RegisterHistory(_stateMachine.Buffer); using (var localUndoTransaction = undoHistory.CreateTransaction(EditorFeaturesResources.TextBufferChange)) { var undoPrimitiveBefore = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: true); localUndoTransaction.AddUndo(undoPrimitiveBefore); if (!workspace.TryApplyChanges(newSolution)) { Contract.Fail("Rename Tracking could not update solution."); } // Never resume tracking session on redo var undoPrimitiveAfter = new UndoPrimitive(_stateMachine.Buffer, trackingSessionId, shouldRestoreStateOnUndo: false); localUndoTransaction.AddUndo(undoPrimitiveAfter); localUndoTransaction.Complete(); } }