protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken) { SourceText text; StateMachine stateMachine; ITextBuffer textBuffer; if (_document.TryGetText(out text)) { textBuffer = text.Container.TryGetTextBuffer(); if (textBuffer == null) { Environment.FailFast(string.Format("document with name {0} is open but textBuffer is null. Textcontainer is of type {1}. SourceText is: {2}", _document.Name, text.Container.GetType().FullName, text.ToString())); } if (textBuffer.Properties.TryGetProperty(typeof(StateMachine), out stateMachine)) { TrackingSession trackingSession; if (stateMachine.CanInvokeRename(out trackingSession, cancellationToken: cancellationToken)) { var snapshotSpan = stateMachine.TrackingSession.TrackingSpan.GetSpan(stateMachine.Buffer.CurrentSnapshot); var str = string.Format(EditorFeaturesResources.RenameTo, stateMachine.TrackingSession.OriginalName, snapshotSpan.GetText()); var committerOperation = new RenameTrackingCommitterOperation(new RenameTrackingCommitter(stateMachine, snapshotSpan, _refactorNotifyServices, _undoHistoryRegistry, str, showPreview: _showPreview)); return(Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation))); } Debug.Assert(false, "RenameTracking codefix invoked on a document with a StateMachine which cannot invoke rename."); } } Debug.Assert(false, "RenameTracking codefix invoked on a document for which the text or StateMachine is not available."); return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>()); }
protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken) { SourceText text; StateMachine stateMachine; ITextBuffer textBuffer; if (_document.TryGetText(out text)) { textBuffer = text.Container.TryGetTextBuffer(); if (textBuffer == null) { Environment.FailFast(string.Format("document with name {0} is open but textBuffer is null. Textcontainer is of type {1}. SourceText is: {2}", _document.Name, text.Container.GetType().FullName, text.ToString())); } if (textBuffer.Properties.TryGetProperty(typeof(StateMachine), out stateMachine)) { TrackingSession trackingSession; if (stateMachine.CanInvokeRename(out trackingSession, cancellationToken: cancellationToken)) { var snapshotSpan = stateMachine.TrackingSession.TrackingSpan.GetSpan(stateMachine.Buffer.CurrentSnapshot); var str = string.Format(EditorFeaturesResources.RenameTo, stateMachine.TrackingSession.OriginalName, snapshotSpan.GetText()); var committerOperation = new RenameTrackingCommitterOperation(new RenameTrackingCommitter(stateMachine, snapshotSpan, _refactorNotifyServices, _undoHistoryRegistry, str, showPreview: _showPreview)); return Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation)); } Debug.Assert(false, "RenameTracking codefix invoked on a document with a StateMachine which cannot invoke rename."); } } Debug.Assert(false, "RenameTracking codefix invoked on a document for which the text or StateMachine is not available."); return SpecializedTasks.EmptyEnumerable<CodeActionOperation>(); }
protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken) { // Invoked directly without previewing. if (_renameTrackingCommitter == null) { if (!TryInitializeRenameTrackingCommitter(cancellationToken)) { return SpecializedTasks.EmptyEnumerable<CodeActionOperation>(); } } var committerOperation = new RenameTrackingCommitterOperation(_renameTrackingCommitter); return Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation)); }
protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken) { // Invoked directly without previewing. if (_renameTrackingCommitter == null) { if (!TryInitializeRenameTrackingCommitter(cancellationToken)) { return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>()); } } var committerOperation = new RenameTrackingCommitterOperation(_renameTrackingCommitter); return(Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation))); }
protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken) { SourceText text; StateMachine stateMachine; ITextBuffer textBuffer; if (_document.TryGetText(out text)) { textBuffer = text.Container.TryGetTextBuffer(); if (textBuffer == null) { Environment.FailFast(string.Format("document with name {0} is open but textBuffer is null. Textcontainer is of type {1}. SourceText is: {2}", _document.Name, text.Container.GetType().FullName, text.ToString())); } if (textBuffer.Properties.TryGetProperty(typeof(StateMachine), out stateMachine)) { TrackingSession trackingSession; if (stateMachine.CanInvokeRename(out trackingSession, cancellationToken: cancellationToken)) { var snapshotSpan = stateMachine.TrackingSession.TrackingSpan.GetSpan(stateMachine.Buffer.CurrentSnapshot); var str = string.Format(EditorFeaturesResources.RenameTo, stateMachine.TrackingSession.OriginalName, snapshotSpan.GetText()); var committerOperation = new RenameTrackingCommitterOperation(new RenameTrackingCommitter(stateMachine, snapshotSpan, _refactorNotifyServices, _undoHistoryRegistry, str, showPreview: _showPreview)); return Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation)); } // The rename tracking could be dismissed while a codefix is still cached // in the lightbulb. If this happens, do not perform the rename requested // and instead let the user know their fix will not be applied. _document.Project.Solution.Workspace.Services.GetService<INotificationService>() ?.SendNotification(EditorFeaturesResources.TheRenameTrackingSessionWasCancelledAndIsNoLongerAvailable, severity: NotificationSeverity.Error); return SpecializedTasks.EmptyEnumerable<CodeActionOperation>(); } } Debug.Assert(false, "RenameTracking codefix invoked on a document for which the text or StateMachine is not available."); return SpecializedTasks.EmptyEnumerable<CodeActionOperation>(); }
protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken) { SourceText text; StateMachine stateMachine; ITextBuffer textBuffer; if (_document.TryGetText(out text)) { textBuffer = text.Container.TryGetTextBuffer(); if (textBuffer == null) { Environment.FailFast(string.Format("document with name {0} is open but textBuffer is null. Textcontainer is of type {1}. SourceText is: {2}", _document.Name, text.Container.GetType().FullName, text.ToString())); } if (textBuffer.Properties.TryGetProperty(typeof(StateMachine), out stateMachine)) { TrackingSession trackingSession; if (stateMachine.CanInvokeRename(out trackingSession, cancellationToken: cancellationToken)) { var snapshotSpan = stateMachine.TrackingSession.TrackingSpan.GetSpan(stateMachine.Buffer.CurrentSnapshot); var str = string.Format(EditorFeaturesResources.RenameTo, stateMachine.TrackingSession.OriginalName, snapshotSpan.GetText()); var committerOperation = new RenameTrackingCommitterOperation(new RenameTrackingCommitter(stateMachine, snapshotSpan, _refactorNotifyServices, _undoHistoryRegistry, str, showPreview: _showPreview)); return(Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation))); } // The rename tracking could be dismissed while a codefix is still cached // in the lightbulb. If this happens, do not perform the rename requested // and instead let the user know their fix will not be applied. _document.Project.Solution.Workspace.Services.GetService <INotificationService>() ?.SendNotification(EditorFeaturesResources.TheRenameTrackingSessionWasCancelledAndIsNoLongerAvailable, severity: NotificationSeverity.Error); return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>()); } } Debug.Assert(false, "RenameTracking codefix invoked on a document for which the text or StateMachine is not available."); return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>()); }