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 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(); }
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); } } } }
public void InsertRoxygen02() { var tb = new TextBufferMock("##\r\nx <- function() { }", 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 #' #' @return #' @export #' #' @examples x <- function() { }"); }
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')")); }
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())")); }
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 void InsertRoxygen01() { var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); var eb = tb.ToEditorBuffer(); var ast = RParser.Parse(tb.CurrentSnapshot.GetText()); var result = RoxygenBlock.TryInsertBlock(eb, ast, 0); result.Should().BeFalse(); tb = new TextBufferMock("x <- 1\r\ny <- 2", RContentTypeDefinition.ContentType); eb = tb.ToEditorBuffer(); ast = RParser.Parse(tb.CurrentSnapshot.GetText()); RoxygenBlock.TryInsertBlock(eb, ast, 0).Should().BeFalse(); RoxygenBlock.TryInsertBlock(eb, ast, 8).Should().BeFalse(); tb = new TextBufferMock("##\r\nx <- function(a) { }", RContentTypeDefinition.ContentType); eb = tb.ToEditorBuffer(); ast = RParser.Parse(tb.CurrentSnapshot.GetText()); RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeTrue(); var actual = tb.CurrentSnapshot.GetText(); actual.Should().Be( @"#' Title #' #' @param a #' #' @return #' @export #' #' @examples x <- function(a) { }"); var funcStart = tb.CurrentSnapshot.GetText().IndexOfOrdinal("x <-"); tb.Insert(funcStart, "\r\n"); RoxygenBlock.TryInsertBlock(eb, ast, funcStart - 2).Should().BeFalse(); }
private string FormatFromClipboard(string content) { var textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); var editorBuffer = textBuffer.ToEditorBuffer(); var textView = new TextViewMock(textBuffer); var clipboard = new ClipboardDataProvider(); using (var command = new FormatOnPasteCommand(textView, textBuffer, _services)) { command.ClipboardDataProvider = clipboard; clipboard.Format = DataFormats.UnicodeText; clipboard.Data = content; var ast = RParser.Parse(textBuffer.CurrentSnapshot.GetText()); using (var document = new EditorDocumentMock(new EditorTreeMock(editorBuffer, ast))) { var o = new object(); command.Invoke(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste, null, ref o); } } return(textBuffer.CurrentSnapshot.GetText()); }
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}))")); }
public void ConstructionTest() { var textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); var eb = textBuffer.ToEditorBuffer(); var tree = new EditorTree(eb, _services); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, _services)) { ob.EditorDocument.Should().NotBeNull(); ob.EditorTree.Should().NotBeNull(); editorDocument.Closing.GetInvocationList().Should().ContainSingle(); var treeUpdateField = tree.GetType().GetField("UpdateCompleted", BindingFlags.Instance | BindingFlags.NonPublic); var d = (MulticastDelegate)treeUpdateField.GetValue(tree); d.GetInvocationList().Should().ContainSingle(); tree.Dispose(); editorDocument.Closing.Should().BeNull(); treeUpdateField.GetValue(tree).Should().BeNull(); } } }
public void Sections() { string content = @"# NAME1 ----- x <- 1 # NAME2 ----- "; TextBufferMock textBuffer = null; int calls = 0; OutlineRegionsChangedEventArgs args = null; 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 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) { _services.GetService <IIdleTimeSource>().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); } } } }