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);
                }
            }
        }
        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);
                }
            }
        }
        public async Task SignatureHelpSourceTest01()
        {
            const string content = @"x <- as.matrix(x)";

            var ast                  = RParser.Parse(content);
            var caretPosition        = 15;
            var textBuffer           = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var signatureHelpSource  = new RSignatureHelpSource(textBuffer, Services);
            var signatureHelpSession = new SignatureHelpSessionMock(Services, textBuffer, caretPosition);
            var signatures           = new List <ISignature>();

            signatureHelpSession.TrackingPoint = new TrackingPointMock(textBuffer, caretPosition, PointTrackingMode.Positive, TrackingFidelityMode.Forward);
            await signatureHelpSource.AugmentSignatureHelpSessionAsync(signatureHelpSession, signatures, ast);

            signatures.Should().ContainSingle();
            signatures[0].Parameters.Should().HaveCount(2);
            signatures[0].CurrentParameter.Name.Should().Be("x");
            signatures[0].Content.Should().Be("as.matrix(x, ...)");
            signatures[0].Documentation.Should().NotBeEmpty();
        }
        public async Task SignatureHelpSourceTest02()
        {
            const string content =
                @"
x <- function(a, b = TRUE, c = 12/7) { }
x( )
";

            var ast                  = RParser.Parse(content);
            var caretPosition        = content.IndexOfOrdinal("( )") + 1;
            var textBuffer           = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var signatureHelpSource  = new RSignatureHelpSource(textBuffer, Services);
            var signatureHelpSession = new SignatureHelpSessionMock(Services, textBuffer, caretPosition);
            var signatures           = new List <ISignature>();

            signatureHelpSession.TrackingPoint = new TrackingPointMock(textBuffer, caretPosition, PointTrackingMode.Positive, TrackingFidelityMode.Forward);
            await signatureHelpSource.AugmentSignatureHelpSessionAsync(signatureHelpSession, signatures, ast);

            signatures.Should().ContainSingle();
            signatures[0].Parameters.Should().HaveCount(3);
            signatures[0].CurrentParameter.Name.Should().Be("a");
            signatures[0].Content.Should().Be("x(a, b = TRUE, c = 12/7)");
            signatures[0].Documentation.Should().BeEmpty();
        }