예제 #1
0
        public async Task ParameterTest_ComputeCurrentParameter02()
        {
            await PackageIndexUtility.GetFunctionInfoAsync(FunctionIndex, "legend");

            REditorSettings.PartialArgumentNameMatch = true;

            ITextBuffer              textBuffer = new TextBufferMock("legend(bty=1, lt=3)", 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, 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(11);

                    textView.Caret = new TextCaretMock(textView, 15);
                    index          = sh.ComputeCurrentParameter(tree.TextSnapshot, tree.AstRoot, 15);
                    index.Should().Be(6);
                }
            }
        }
예제 #2
0
        public async Task ParameterTest_ComputeCurrentParameter02()
        {
            await FunctionIndex.GetPackageNameAsync("legend");

            _settings.PartialArgumentNameMatch.Returns(true);

            var textBuffer = new TextBufferMock("legend(bty=1, lt=3)", RContentTypeDefinition.ContentType);
            var eb         = textBuffer.ToEditorBuffer();
            var source     = new RSignatureHelpSource(textBuffer, Services);
            var session    = new SignatureHelpSessionMock(Services, textBuffer, 0);
            var textView   = session.TextView as TextViewMock;
            var signatures = new List <ISignature>();

            using (var tree = new EditorTree(eb, Services)) {
                tree.Build();
                using (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);
                    var sh    = ((RSignatureHelp)signatures[0]).FunctionSignatureHelp;
                    var index = sh.SignatureInfo.ComputeCurrentParameter(tree.BufferSnapshot, tree.AstRoot, 8, _settings);
                    index.Should().Be(11);

                    textView.Caret = new TextCaretMock(textView, 15);
                    index          = sh.SignatureInfo.ComputeCurrentParameter(tree.BufferSnapshot, tree.AstRoot, 15, _settings);
                    index.Should().Be(6);
                }
            }
        }
예제 #3
0
        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, _shell)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, _shell)) {
                        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)
                        {
                            ((IIdleTimeSource)_shell).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);
                    }
                }
            }
        }
예제 #4
0
        public static EditorTree ApplyTextChange(string expression, int start, int oldLength, int newLength, string newText)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            TextChange tc = new TextChange();

            tc.OldRange        = new TextRange(start, oldLength);
            tc.NewRange        = new TextRange(start, newLength);
            tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot);

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new Span(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new Span(start, oldLength));
            }

            return(tree);
        }
예제 #5
0
        public static EditorTree MakeTree(IServiceContainer services, string expression)
        {
            var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer();
            var tree       = new EditorTree(textBuffer, services);

            tree.Build();
            return(tree);
        }
예제 #6
0
        public static EditorTree MakeTree(string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            return(tree);
        }
예제 #7
0
        public static EditorTree MakeTree(ICoreShell coreShell, string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            var tree = new EditorTree(textBuffer, coreShell);

            tree.Build();

            return(tree);
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        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);
                    }
                }
            }
        }
예제 #10
0
        public REditorDocument(IEditorBuffer editorBuffer, IServiceContainer services, IExpressionTermFilter termFilter = null)
        {
            EditorBuffer = editorBuffer;
            _services    = services;

            EditorBuffer.Services.AddService(this);
            EditorBuffer.Closing += OnBufferClosing;

            var tree = new EditorTree(EditorBuffer, services, termFilter);

            tree.Build();
            EditorTree = tree;

            TreeValidator.FromEditorBuffer(EditorTree, services);
        }
예제 #11
0
        public static OutlineRegionCollection BuildOutlineRegions(IServiceContainer services, string content)
        {
            var textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var eb         = textBuffer.ToEditorBuffer();

            using (var tree = new EditorTree(eb, services)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, services)) {
                        var rc = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc);
                        return(rc);
                    }
                }
            }
        }
예제 #12
0
        public REditorDocument(IEditorBuffer editorBuffer, IServiceContainer services, bool isRepl)
        {
            EditorBuffer = editorBuffer;
            IsRepl       = isRepl;

            _services = services;

            EditorBuffer.Services.AddService(this);
            EditorBuffer.Closing += OnBufferClosing;

            var tree = new EditorTree(EditorBuffer, services);

            tree.Build();
            EditorTree = tree;

            _validator = new TreeValidator(EditorTree, services);
        }
예제 #13
0
        public REditorDocument(ITextBuffer textBuffer, ICoreShell shell)
        {
            _shell = shell;
            _textDocumentFactoryService = _shell.ExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            _textDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            this.TextBuffer = textBuffer;
            IsClosed        = false;

            ServiceManager.AddService(this, TextBuffer, shell);

            _editorTree = new EditorTree(textBuffer, shell);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(EditorTree, shell);
            }

            _editorTree.Build();
        }
예제 #14
0
        public REditorDocument(ITextBuffer textBuffer)
        {
            _textDocumentFactoryService = EditorShell.Current.ExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            _textDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            this.TextBuffer = textBuffer;
            IsClosed        = false;

            ServiceManager.AddService <REditorDocument>(this, TextBuffer);

            _editorTree = new EditorTree(textBuffer);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(this.EditorTree);
            }

            _editorTree.Build();
            RCompletionEngine.Initialize();
        }
예제 #15
0
        public async Task ParameterTest_ComputeCurrentParameter01()
        {
            var textBuffer   = new TextBufferMock("aov(", RContentTypeDefinition.ContentType);
            var editorBuffer = textBuffer.ToEditorBuffer();
            var source       = new RSignatureHelpSource(textBuffer, Services);
            var session      = new SignatureHelpSessionMock(Services, textBuffer, 0);
            var textView     = session.TextView as TextViewMock;
            var signatures   = new List <ISignature>();

            using (var tree = new EditorTree(editorBuffer, Services)) {
                tree.Build();
                using (var document = new EditorDocumentMock(tree)) {
                    session.TrackingPoint = new TrackingPointMock(textBuffer, 4, PointTrackingMode.Positive, TrackingFidelityMode.Forward);
                    await FunctionIndex.GetPackageNameAsync("aov");

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

                    signatures.Should().ContainSingle();

                    var index = GetCurrentParameterIndex(signatures[0], signatures[0].CurrentParameter);
                    index.Should().Be(0);

                    textView.Caret = new TextCaretMock(textView, 5);
                    TextBufferUtility.ApplyTextChange(textBuffer, 4, 0, 1, "a");
                    index = GetCurrentParameterIndex(signatures[0], 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], 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], signatures[0].CurrentParameter);
                    index.Should().Be(2);
                }
            }
        }
예제 #16
0
        public REditorDocument(ITextBuffer textBuffer, ICoreShell shell)
        {
            _shell = shell;
            _textDocumentFactoryService = _shell.ExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            _textDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            TextBuffer = textBuffer;
            IsClosed   = false;

            ServiceManager.AddService(this, TextBuffer, shell);
            var clh = ServiceManager.GetService <IContainedLanguageHost>(textBuffer);

            _editorTree = new EditorTree(textBuffer, shell, new ExpressionTermFilter(clh));
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(EditorTree, shell);
            }

            _editorTree.Build();
        }
예제 #17
0
        public REditorDocument(ITextBuffer textBuffer)
        {
            EditorShell.Current.CompositionService.SatisfyImportsOnce(this);

            this.TextBuffer = textBuffer;

            IsClosed = false;
            TextDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            ServiceManager.AddService <REditorDocument>(this, TextBuffer);

            _editorTree = new EditorTree(textBuffer);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(this.EditorTree);
            }

            _editorTree.Build();

            RCompletionEngine.Initialize();
        }
예제 #18
0
            public async Task ParameterTest_ComputeCurrentParameter01()
            {
                ITextBuffer              textBuffer = new TextBufferMock("aov(", 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, 4, PointTrackingMode.Positive, TrackingFidelityMode.Forward);
                await FunctionIndexUtility.GetFunctionInfoAsync("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, ",");
                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, ",");
                index = GetCurrentParameterIndex(signatures[0] as SignatureHelp, signatures[0].CurrentParameter);
                index.Should().Be(2);
            }
예제 #19
0
        public static EditorTree ApplyTextChange(IServiceContainer services, string expression, int start, int oldLength, int newLength, string newText)
        {
            var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer();
            var tree       = new EditorTree(textBuffer, services);

            tree.Build();

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new TextRange(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new TextRange(start, oldLength));
            }

            return(tree);
        }