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); } } }
public async Task R_SignatureSessionNavigation() { using (var script = await _editorHost.StartScript(_exportProvider, RContentTypeDefinition.ContentType)) { IntelliSenseRSession.HostStartTimeout = 10000; using (new RHostScript(_exportProvider)) { var functionIndex = PrepareFunctionIndex(); PackageIndexUtility.GetFunctionInfoAsync(functionIndex, "lm").Wait(3000); script.Type("x <- lm(subset = a, sing"); script.DoIdle(1000); script.Type("{TAB}"); script.DoIdle(1000); ISignatureHelpSession session = script.GetSignatureSession(); session.Should().NotBeNull(); script.DoIdle(200); IParameter parameter = session.SelectedSignature.CurrentParameter; parameter.Should().NotBeNull(); parameter.Name.Should().Be("singular.ok"); script.MoveLeft(17); script.DoIdle(200); parameter = session.SelectedSignature.CurrentParameter; parameter.Name.Should().Be("subset"); script.MoveRight(3); script.DoIdle(200); parameter = session.SelectedSignature.CurrentParameter; parameter.Name.Should().Be("singular.ok"); } } }
public async Task R_SignatureParametersMatch() { using (var script = await _editorHost.StartScript(_exportProvider, RContentTypeDefinition.ContentType)) { IntelliSenseRSession.HostStartTimeout = 10000; using (new RHostScript(_exportProvider)) { var functionIndex = PrepareFunctionIndex(); PackageIndexUtility.GetFunctionInfoAsync(functionIndex, "lm").Wait(3000); script.Type("x <- lm("); script.DoIdle(2000); ISignatureHelpSession session = script.GetSignatureSession(); session.Should().NotBeNull(); IParameter parameter = session.SelectedSignature.CurrentParameter; parameter.Should().NotBeNull(); parameter.Name.Should().Be("formula"); script.Type("sub"); script.DoIdle(500); script.Type("{TAB}"); script.DoIdle(1000); parameter = session.SelectedSignature.CurrentParameter; parameter.Name.Should().Be("subset"); string actual = script.EditorText; actual.Should().Be("x <- lm(subset = )"); session = script.GetSignatureSession(); parameter = session.SelectedSignature.CurrentParameter; } } }
public async Task FunctionInfoTest2() { var functionInfo = await PackageIndexUtility.GetFunctionInfoAsync(_functionIndex, "eval"); functionInfo.Should().NotBeNull(); functionInfo.Name.Should().Be("eval"); functionInfo.Description.Should().NotBeEmpty(); functionInfo.Signatures.Should().ContainSingle().Which.Arguments.Should().HaveCount(3); List <int> locusPoints = new List <int>(); string signature = functionInfo.Signatures[0].GetSignatureString("eval", locusPoints); signature.Should().Be("eval(expr, envir = parent.frame(), enclos = if(is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv())"); locusPoints.Should().Equal(5, 11, 35, 114); }
public async Task FunctionInfoTest1(string name) { var functionInfo = await PackageIndexUtility.GetFunctionInfoAsync(_functionIndex, "abs"); functionInfo.Should().NotBeNull(); functionInfo.Name.Should().Be("abs"); functionInfo.Description.Should().NotBeEmpty(); functionInfo.Signatures.Should().ContainSingle() .Which.Arguments.Should().ContainSingle(); List <int> locusPoints = new List <int>(); functionInfo.Signatures[0].GetSignatureString(name, locusPoints).Should().Be(name + "(x)"); locusPoints.Should().Equal(4, 5); }
public async Task R_EqualsCompletion01() { using (var script = await _editorHost.StartScript(_exportProvider, RContentTypeDefinition.ContentType)) { var functionIndex = PrepareFunctionIndex(); PackageIndexUtility.GetFunctionInfoAsync(functionIndex, "addmargins").Wait(3000); script.DoIdle(100); script.Type("addmargins(FU"); script.DoIdle(300); script.Type("="); script.DoIdle(300); string expected = "addmargins(FUN = )"; string actual = script.EditorText; actual.Should().Be(expected); } }
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); } } }
public async Task RSignature() { using (var script = await _editorHost.StartScript(_exportProvider, "```{r}\r\n\r\n```", MdContentTypeDefinition.ContentType)) { IntelliSenseRSession.HostStartTimeout = 10000; using (new RHostScript(_sessionProvider)) { var packageIndex = _exportProvider.GetExportedValue <IPackageIndex>(); await packageIndex.BuildIndexAsync(); var functionIndex = _exportProvider.GetExportedValue <IFunctionIndex>(); PackageIndexUtility.GetFunctionInfoAsync(functionIndex, "lm").Wait(3000); script.DoIdle(500); script.MoveDown(); script.Type("x <- lm("); script.DoIdle(2000); ISignatureHelpSession session = script.GetSignatureSession(); session.Should().NotBeNull(); IParameter parameter = session.SelectedSignature.CurrentParameter; parameter.Should().NotBeNull(); parameter.Name.Should().Be("formula"); script.Type("sub"); script.DoIdle(500); script.Type("{TAB}"); script.DoIdle(1000); parameter = session.SelectedSignature.CurrentParameter; parameter.Name.Should().Be("subset"); string actual = script.EditorText; actual.Should().Be("```{r}\r\nx <- lm(subset = )\r\n```"); session = script.GetSignatureSession(); parameter = session.SelectedSignature.CurrentParameter; } } }