Inheritance: IREditorDocument
コード例 #1
0
        private int? GetSmartIndent(string content, int lineNumber) {
            AstRoot ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = EditorShell.Current.ExportProvider.GetExport<ISmartIndentProvider>().Value;
            ISmartIndent indenter = provider.CreateSmartIndent(textView);

            return indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber));
        }
コード例 #2
0
ファイル: SmartIndentTest.cs プロジェクト: Microsoft/RTVS
        public void Scope(string content, int lineNum, int expectedIndent) {
            AstRoot ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = _exportProvider.GetExportedValue<ISmartIndentProvider>("ContentTypes", RContentTypeDefinition.ContentType);
            ISmartIndent indenter = provider.CreateSmartIndent(textView);
            int? indent = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNum));
            indent.Should().HaveValue().And.Be(expectedIndent);
        }
コード例 #3
0
        public void SmartIndentTest05() {
            AstRoot ast;
            ITextView textView = TextViewTest.MakeTextView("  x <- 1\r\n", 0, out ast);
            var document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = EditorShell.Current.ExportProvider.GetExportedValue<ISmartIndentProvider>();
            SmartIndenter indenter = (SmartIndenter)provider.CreateSmartIndent(textView);

            int? indent = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1), IndentStyle.Block);

            indent.Should().HaveValue().And.Be(2);
        }
コード例 #4
0
ファイル: OutlineTest.cs プロジェクト: Microsoft/RTVS
 public static OutlineRegionCollection BuildOutlineRegions(IEditorShell editorShell, string content) {
     TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
     using (var tree = new EditorTree(textBuffer, editorShell)) {
         tree.Build();
         using (var editorDocument = new EditorDocumentMock(tree)) {
             using (var ob = new ROutlineRegionBuilder(editorDocument, editorShell)) {
                 OutlineRegionCollection rc = new OutlineRegionCollection(0);
                 ob.BuildRegions(rc);
                 return rc;
             }
         }
     }
 }
コード例 #5
0
ファイル: OutlineTest.cs プロジェクト: AlexanderSher/RTVS-Old
        public static OutlineRegionCollection BuildOutlineRegions(string content)
        {
            TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            using (EditorTree tree = new EditorTree(textBuffer)) {
                tree.Build();

                EditorDocumentMock editorDocument = new EditorDocumentMock(tree);
                ROutlineRegionBuilder ob = new ROutlineRegionBuilder(editorDocument);
                OutlineRegionCollection rc = new OutlineRegionCollection(0);
                ob.BuildRegions(rc);

                return rc;
            }
        }
コード例 #6
0
        public async Task ParameterTest_ComputeCurrentParameter01() {
            ITextBuffer textBuffer = new TextBufferMock("aov(", RContentTypeDefinition.ContentType);
            SignatureHelpSource source = new SignatureHelpSource(textBuffer, EditorShell);
            SignatureHelpSessionMock session = new SignatureHelpSessionMock(textBuffer, 0);
            TextViewMock textView = session.TextView as TextViewMock;
            List<ISignature> signatures = new List<ISignature>();

            using (var tree = new EditorTree(textBuffer, EditorShell)) {
                tree.Build();
                using (var document = new EditorDocumentMock(tree)) {

                    session.TrackingPoint = new TrackingPointMock(textBuffer, 4, PointTrackingMode.Positive, TrackingFidelityMode.Forward);
                    await PackageIndexUtility.GetFunctionInfoAsync(FunctionIndex, "aov");

                    tree.TakeThreadOwnerShip();
                    await source.AugmentSignatureHelpSessionAsync(session, signatures, tree.AstRoot);

                    signatures.Should().ContainSingle();

                    int index = GetCurrentParameterIndex(signatures[0] as SignatureHelp, signatures[0].CurrentParameter);
                    index.Should().Be(0);

                    textView.Caret = new TextCaretMock(textView, 5);
                    TextBufferUtility.ApplyTextChange(textBuffer, 4, 0, 1, "a");
                    index = GetCurrentParameterIndex(signatures[0] as SignatureHelp, signatures[0].CurrentParameter);
                    index.Should().Be(0);

                    textView.Caret = new TextCaretMock(textView, 6);
                    TextBufferUtility.ApplyTextChange(textBuffer, 5, 0, 1, ",");
                    tree.EnsureTreeReady();
                    index = GetCurrentParameterIndex(signatures[0] as SignatureHelp, signatures[0].CurrentParameter);
                    index.Should().Be(1);

                    textView.Caret = new TextCaretMock(textView, 7);
                    TextBufferUtility.ApplyTextChange(textBuffer, 6, 0, 1, ",");
                    tree.EnsureTreeReady();
                    index = GetCurrentParameterIndex(signatures[0] as SignatureHelp, signatures[0].CurrentParameter);
                    index.Should().Be(2);
                }
            }
        }
コード例 #7
0
        public void RRegionBuilder_ConstructionTest() {
            TextBufferMock textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            EditorTree tree = new EditorTree(textBuffer);
            EditorDocumentMock editorDocument = new EditorDocumentMock(tree);

            ROutlineRegionBuilder ob = new ROutlineRegionBuilder(editorDocument);

            ob.EditorDocument.Should().NotBeNull();
            ob.EditorTree.Should().NotBeNull();

            editorDocument.DocumentClosing.GetInvocationList().Should().ContainSingle();

            FieldInfo treeUpdateField = tree.GetType().GetField("UpdateCompleted", BindingFlags.Instance | BindingFlags.NonPublic);
            var d = (MulticastDelegate)treeUpdateField.GetValue(tree);
            d.GetInvocationList().Should().ContainSingle();

            ob.Dispose();

            editorDocument.DocumentClosing.Should().BeNull();
            treeUpdateField.GetValue(tree).Should().BeNull();
        }
コード例 #8
0
            public async Task ParameterTest_ComputeCurrentParameter04() {
                await FunctionIndexUtility.GetFunctionInfoAsync("legend");

                REditorSettings.PartialArgumentNameMatch = true;

                ITextBuffer textBuffer = new TextBufferMock("legend(an=1)", RContentTypeDefinition.ContentType);
                SignatureHelpSource source = new SignatureHelpSource(textBuffer);
                SignatureHelpSessionMock session = new SignatureHelpSessionMock(textBuffer, 0);
                TextViewMock textView = session.TextView as TextViewMock;
                List<ISignature> signatures = new List<ISignature>();

                EditorTree tree = new EditorTree(textBuffer);
                tree.Build();
                var document = new EditorDocumentMock(tree);

                session.TrackingPoint = new TrackingPointMock(textBuffer, 7, PointTrackingMode.Positive, TrackingFidelityMode.Forward);

                tree.TakeThreadOwnerShip();
                await source.AugmentSignatureHelpSessionAsync(session, signatures, tree.AstRoot);

                signatures.Should().ContainSingle();

                textView.Caret = new TextCaretMock(textView, 8);
                SignatureHelp sh = signatures[0] as SignatureHelp;
                int index = sh.ComputeCurrentParameter(tree.TextSnapshot, tree.AstRoot, 8);
                index.Should().Be(9);
            }
コード例 #9
0
ファイル: OutlineBuilderTest.cs プロジェクト: Microsoft/RTVS
        public void Sections() {
            string content =
@"# NAME1 -----
x <- 1


# NAME2 -----


";
            TextBufferMock textBuffer = null;
            int calls = 0;
            OutlineRegionsChangedEventArgs args = null;

            textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            using (var tree = new EditorTree(textBuffer, _editorShell)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, _editorShell)) {
                        var rc1 = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc1);

                        rc1.Should().HaveCount(2);
                        rc1[0].DisplayText.Should().Be("# NAME1");
                        rc1[1].DisplayText.Should().Be("# NAME2");

                        rc1[0].Length.Should().Be(21);
                        rc1[1].Length.Should().Be(13);

                        ob.RegionsChanged += (s, e) => {
                            calls++;
                            args = e;
                        };

                        textBuffer.Insert(2, "A");
                        editorDocument.EditorTree.EnsureTreeReady();

                        // Wait for background/idle tasks to complete
                        var start = DateTime.Now;
                        while (calls == 0 && (DateTime.Now - start).TotalMilliseconds < 2000) {
                            _editorShell.DoIdle();
                        }

                        calls.Should().Be(1);
                        args.Should().NotBeNull();
                        args.ChangedRange.Start.Should().Be(0);
                        args.ChangedRange.End.Should().Be(textBuffer.CurrentSnapshot.Length);
                        args.Regions.Should().HaveCount(2);

                        args.Regions[0].DisplayText.Should().Be("# ANAME1");
                        args.Regions[1].DisplayText.Should().Be("# NAME2");

                        args.Regions[0].Length.Should().Be(22);
                        args.Regions[1].Length.Should().Be(13);
                    }
                }
            }
        }
コード例 #10
0
ファイル: FormatCommandTest.cs プロジェクト: Microsoft/RTVS
        private string FormatFromClipboard(string content) {
            ITextBuffer textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            ITextView textView = new TextViewMock(textBuffer);
            var clipboard = new ClipboardDataProvider();

            using (var command = new FormatOnPasteCommand(textView, textBuffer, _editorShell)) {
                command.ClipboardDataProvider = clipboard;

                clipboard.Format = DataFormats.UnicodeText;
                clipboard.Data = content;

                var ast = RParser.Parse(textBuffer.CurrentSnapshot.GetText());
                using (var document = new EditorDocumentMock(new EditorTreeMock(textBuffer, ast))) {
                    object o = new object();
                    command.Invoke(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste, null, ref o);
                }
            }

            return textBuffer.CurrentSnapshot.GetText();
        }
コード例 #11
0
ファイル: GotoDefinitionTest.cs プロジェクト: Microsoft/RTVS
 private TextViewMock SetupTextView(string content, int startLineNumber, int startColumn) {
     var document = new EditorDocumentMock(content);
     var tv = new TextViewMock(document.TextBuffer);
     var line = document.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(startLineNumber);
     tv.Caret.MoveTo(new SnapshotPoint(tv.TextBuffer.CurrentSnapshot, line.Start + startColumn));
     return tv;
 }
コード例 #12
0
        private void GetPeekableItems(string content, int position, IList<IPeekableItem> items, ITextRange selection = null) {
            var document = new EditorDocumentMock(content, @"C:\file.r");

            TextViewMock textView = new TextViewMock(document.TextBuffer, position);

            if (selection != null) {
                textView.Selection.Select(new SnapshotSpan(document.TextBuffer.CurrentSnapshot, new Span(selection.Start, selection.Length)), isReversed: false);
                textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, selection.End));
            } else {
                textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, position));
            }

            var peekSession = PeekSessionMock.Create(textView, position);
            var factory = PeekResultFactoryMock.Create();
            var peekSource = new PeekableItemSource(textView.TextBuffer, factory, _exportProvider.GetExportedValue<ICoreShell>());

            peekSource.AugmentPeekSession(peekSession, items);
        }