Example #1
0
        public void InsertRoxygen01()
        {
            var     tb     = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            AstRoot ast    = RParser.Parse(tb.CurrentSnapshot.GetText());
            var     result = RoxygenBlock.TryInsertBlock(tb, ast, 0);

            result.Should().BeFalse();

            tb  = new TextBufferMock("x <- 1\r\ny <- 2", RContentTypeDefinition.ContentType);
            ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            RoxygenBlock.TryInsertBlock(tb, ast, 0).Should().BeFalse();
            RoxygenBlock.TryInsertBlock(tb, ast, 8).Should().BeFalse();

            tb  = new TextBufferMock("##\r\nx <- function(a) { }", RContentTypeDefinition.ContentType);
            ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            RoxygenBlock.TryInsertBlock(tb, ast, 4).Should().BeTrue();
            string actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                @"#' Title
#'
#' @param a
#'
#' @return
#' @export
#'
#' @examples
x <- function(a) { }");

            int funcStart = tb.CurrentSnapshot.GetText().IndexOf("x <-");

            tb.Insert(funcStart, "\r\n");
            RoxygenBlock.TryInsertBlock(tb, ast, funcStart - 2).Should().BeFalse();
        }
Example #2
0
        public void S4Error(string content)
        {
            var tb = new TextBufferMock("##\r\n" + content, RContentTypeDefinition.ContentType);
            var eb = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeFalse();
        }
Example #3
0
        public void InsertRoxygen02()
        {
            var tb  = new TextBufferMock("##\r\nx <- function() { }", RContentTypeDefinition.ContentType);
            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(tb, ast, 4).Should().BeTrue();
            string actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                @"#' Title
#'
#' @return
#' @export
#'
#' @examples
x <- function() { }");
        }
Example #4
0
        private bool TryInsertRoxygenBlock()
        {
            var point = TextView.GetCaretPosition(_textBuffer);

            if (point.HasValue)
            {
                var snapshot = _textBuffer.CurrentSnapshot;
                var line     = snapshot.GetLineFromPosition(point.Value);
                if (line.LineNumber < snapshot.LineCount - 1 && point.Value == line.End && line.GetText().EqualsOrdinal("##"))
                {
                    var nextLine = snapshot.GetLineFromLineNumber(line.LineNumber + 1);
                    var document = _textBuffer.GetEditorDocument <IREditorDocument>();
                    document.EditorTree.EnsureTreeReady();
                    return(RoxygenBlock.TryInsertBlock(_textBuffer.ToEditorBuffer(), document.EditorTree.AstRoot, nextLine.Start));
                }
            }
            return(false);
        }
Example #5
0
        public void S4MethodGeneric(string name)
        {
            var tb = new TextBufferMock(Invariant($"##\r\n{name}('Name')"), RContentTypeDefinition.ContentType);
            var eb = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeTrue();
            var actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                Invariant($@"#' Title
#'
#' @return
#' @export
#'
#' @examples
{name}('Name')"));
        }
Example #6
0
        public void S4Empty()
        {
            var tb = new TextBufferMock(Invariant($"##\r\nsetClass('Name', slots())"), RContentTypeDefinition.ContentType);
            var eb = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeTrue();
            var actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                Invariant($@"#' Title
#'
#' @return
#' @export
#'
#' @examples
setClass('Name', slots())"));
        }
Example #7
0
        public void S4Class(string name)
        {
            const string type = "\"float\"";
            var          tb   = new TextBufferMock(Invariant($"##\r\nsetClass('Name', {name}(a = 'character', b = \"float\"))"), RContentTypeDefinition.ContentType);
            var          eb   = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeTrue();
            var actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                Invariant($@"#' Title
#'
#' @slot a character
#' @slot b float
#'
#' @return
#' @export
#'
#' @examples
setClass('Name', {name}(a = 'character', b = {type}))"));
        }
Example #8
0
        public void InsertRoxygen03()
        {
            var tb = new TextBufferMock("##\r\nx <-\r\n function(a=1, b, c=FALSE) { }", RContentTypeDefinition.ContentType);
            var eb = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeTrue();
            string actual = tb.CurrentSnapshot.GetText();

            actual.Should().Be(
                @"#' Title
#'
#' @param a
#' @param b
#' @param c
#'
#' @return
#' @export
#'
#' @examples
x <-
 function(a=1, b, c=FALSE) { }");
        }