コード例 #1
0
        private static void UncommentSelection(string markup, string expected)
        {
            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(markup))
            {
                var doc = workspace.Documents.First();
                SetupSelection(doc.GetTextView(), doc.SelectedSpans.Select(s => Span.FromBounds(s.Start, s.End)));

                var commandHandler = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default);
                var textView = doc.GetTextView();
                var textBuffer = doc.GetTextBuffer();
                commandHandler.ExecuteCommand(textView, textBuffer, CommentUncommentSelectionCommandHandler.Operation.Uncomment);

                Assert.Equal(expected, doc.TextBuffer.CurrentSnapshot.GetText());
            }
        }
コード例 #2
0
        private static void UncommentSelection(string markup, string expected)
        {
            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(markup))
            {
                var doc = workspace.Documents.First();
                SetupSelection(doc.GetTextView(), doc.SelectedSpans.Select(s => Span.FromBounds(s.Start, s.End)));

                var commandHandler = new CommentUncommentSelectionCommandHandler(
                    TestWaitIndicator.Default,
                    workspace.ExportProvider.GetExportedValue <ITextUndoHistoryRegistry>(),
                    workspace.ExportProvider.GetExportedValue <IEditorOperationsFactoryService>());
                var textView   = doc.GetTextView();
                var textBuffer = doc.GetTextBuffer();
                commandHandler.ExecuteCommand(textView, textBuffer, CommentUncommentSelectionCommandHandler.Operation.Uncomment);

                Assert.Equal(expected, doc.TextBuffer.CurrentSnapshot.GetText());
            }
        }
コード例 #3
0
        private static void UncommentSelection(string markup, string expected)
        {
            using var workspace = TestWorkspace.CreateCSharp(markup);
            var doc = workspace.Documents.First();

            SetupSelection(doc.GetTextView(), doc.SelectedSpans.Select(s => Span.FromBounds(s.Start, s.End)));

            var commandHandler = new CommentUncommentSelectionCommandHandler(
                workspace.GetService <ITextUndoHistoryRegistry>(),
                workspace.GetService <IEditorOperationsFactoryService>(),
                workspace.GlobalOptions);

            var textView   = doc.GetTextView();
            var textBuffer = doc.GetTextBuffer();

            commandHandler.ExecuteCommand(textView, textBuffer, Operation.Uncomment, TestCommandExecutionContext.Create());

            Assert.Equal(expected, doc.GetTextBuffer().CurrentSnapshot.GetText());
        }
コード例 #4
0
        private static void CommentOrUncommentSelection(
            ITextView textView,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            Operation operation)
        {
            var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <ITextUndoHistoryRegistry>();
            var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IEditorOperationsFactoryService>();
            var commandHandler          = new CommentUncommentSelectionCommandHandler(textUndoHistoryRegistry, editorOperationsFactory);
            var service = new MockCommentSelectionService(supportBlockComments);

            var edits = commandHandler.CollectEditsAsync(
                null, service, textView.TextBuffer, textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), operation, CancellationToken.None).GetAwaiter().GetResult();

            Roslyn.Test.Utilities.AssertEx.SetEqual(expectedChanges, edits.TextChanges);

            var trackingSpans = edits.TrackingSpans
                                .Select(textSpan => AbstractCommentSelectionBase <Operation> .CreateTrackingSpan(
                                            edits.ResultOperation, textView.TextBuffer.CurrentSnapshot, textSpan.TrackingTextSpan))
                                .ToList();

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                edits.TextChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextBuffer.CurrentSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                Roslyn.Test.Utilities.AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }
コード例 #5
0
        private static void CommentOrUncommentSelection(
            ITextView textView,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <ITextUndoHistoryRegistry>();
            var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IEditorOperationsFactoryService>();
            var commandHandler          = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default, textUndoHistoryRegistry, editorOperationsFactory);
            var service = new MockCommentSelectionService(supportBlockComments);

            var trackingSpans = new List <ITrackingSpan>();
            var textChanges   = new List <TextChange>();

            commandHandler.CollectEdits(
                null, service, textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer),
                textChanges, trackingSpans, operation, CancellationToken.None);

            AssertEx.SetEqual(expectedChanges, textChanges);

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }
コード例 #6
0
        private static void CommentOrUncommentSelection(

            ITextView textView,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var commandHandler = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default);
            var service        = new MockCommentUncommentService(supportBlockComments);

            var trackingSpans = new List <ITrackingSpan>();
            var textChanges   = new List <TextChange>();

            commandHandler.CollectEdits(service,
                                        textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), textChanges, trackingSpans, operation);

            AssertEx.SetEqual(expectedChanges, textChanges);

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }
コード例 #7
0
        private static async Task UncommentSelectionAsync(string markup, string expected)
        {
            using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromLinesAsync(markup))
            {
                var doc = workspace.Documents.First();
                SetupSelection(doc.GetTextView(), doc.SelectedSpans.Select(s => Span.FromBounds(s.Start, s.End)));

                var commandHandler = new CommentUncommentSelectionCommandHandler(
                    TestWaitIndicator.Default,
                    workspace.ExportProvider.GetExportedValue<ITextUndoHistoryRegistry>(),
                    workspace.ExportProvider.GetExportedValue<IEditorOperationsFactoryService>());
                var textView = doc.GetTextView();
                var textBuffer = doc.GetTextBuffer();
                commandHandler.ExecuteCommand(textView, textBuffer, CommentUncommentSelectionCommandHandler.Operation.Uncomment);

                Assert.Equal(expected, doc.TextBuffer.CurrentSnapshot.GetText());
            }
        }
        private static void CommentOrUncommentSelection(
            ITextView textView,
            IEnumerable<TextChange> expectedChanges,
            IEnumerable<Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue<ITextUndoHistoryRegistry>();
            var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue<IEditorOperationsFactoryService>();
            var commandHandler = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default, textUndoHistoryRegistry, editorOperationsFactory);
            var service = new MockCommentUncommentService(supportBlockComments);

            var trackingSpans = new List<ITrackingSpan>();
            var textChanges = new List<TextChange>();

            commandHandler.CollectEdits(service,
                textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), textChanges, trackingSpans, operation);

            AssertEx.SetEqual(expectedChanges, textChanges);

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }
        private static void CommentOrUncommentSelection(
            string code,
            IEnumerable<TextChange> expectedChanges,
            IEnumerable<Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var textView = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, code);
            var selectedSpans = SetupSelection(textView);

            CommentOrUncommentSelection(textView, expectedChanges, expectedSelectedSpans, supportBlockComments, operation);
        }