Ejemplo n.º 1
0
        public async Task SignatureHelpSourceTest01() {
            string content = @"x <- as.matrix(x)";

            AstRoot ast = RParser.Parse(content);
            int caretPosition = 15;
            ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            SignatureHelpSource signatureHelpSource = new SignatureHelpSource(textBuffer, EditorShell);
            SignatureHelpSessionMock signatureHelpSession = new SignatureHelpSessionMock(textBuffer, caretPosition);
            List<ISignature> 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(8);
            signatures[0].CurrentParameter.Name.Should().Be("x");
            signatures[0].Content.Should().Be("as.matrix(x, ..., data, nrow, ncol, byrow, dimnames, rownames.force)");
            signatures[0].Documentation.Should().NotBeEmpty();
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task SignatureHelpSourceTest02() {
            string content = 
@"
x <- function(a, b = TRUE, c = 12/7) { }
x( )
";

            AstRoot ast = RParser.Parse(content);
            int caretPosition = content.IndexOf("( )")+1;
            ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            SignatureHelpSource signatureHelpSource = new SignatureHelpSource(textBuffer, EditorShell);
            SignatureHelpSessionMock signatureHelpSession = new SignatureHelpSessionMock(textBuffer, caretPosition);
            List<ISignature> 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();
        }
Ejemplo n.º 4
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);
            }