public void R_ProvisionalText02() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("c(\""); string expected = "c(\"\")"; string actual = script.EditorText; actual.Should().Be(expected); // Move caret outside of the provisional text area // and back so provisional text becomes permanent. script.MoveRight(); script.MoveLeft(); // Let parser hit on idle so AST updates script.DoIdle(300); // There should not be completion inside "" script.Type("\""); expected = "c(\"\"\")"; actual = script.EditorText; actual.Should().Be(expected); } }
public void R_SignatureSessionNavigation() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { FunctionRdDataProvider.HostStartTimeout = 10000; using (new RHostScript(EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>())) { PrepareFunctionIndex(); FunctionIndexUtility.GetFunctionInfoAsync("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 void R_ProvisionalText01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("{"); script.Type("("); script.Type("["); script.Type("\""); string expected = "{([\"\"])}"; string actual = script.EditorText; actual.Should().Be(expected); REditorSettings.AutoFormat = false; script.Type("\""); script.Type("]"); script.Type(")"); script.Type("}"); script.DoIdle(1000); expected = "{([\"\"])}"; actual = script.EditorText; actual.Should().Be(expected); } }
public void R_ErrorTagsTest01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { // Force tagger creation var tagSpans = script.GetErrorTagSpans(); script.Type("x <- {"); script.Delete(); script.DoIdle(500); tagSpans = script.GetErrorTagSpans(); string errorTags = script.WriteErrorTags(tagSpans); errorTags.Should().Be("[5 - 6] } expected\r\n"); var item = tagSpans[0].Tag as IEditorTaskListItem; item.Line.Should().Be(1); item.Column.Should().Be(6); item.FileName.Should().Be("filename"); item.HelpKeyword.Should().Be("vs.r.validationerror"); script.Type("}"); script.DoIdle(500); tagSpans = script.GetErrorTagSpans(); tagSpans.Should().BeEmpty(); } }
public void R_SignatureParametersMatch() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { FunctionRdDataProvider.HostStartTimeout = 10000; using (new RHostScript(EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>())) { PrepareFunctionIndex(); FunctionIndexUtility.GetFunctionInfoAsync("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; } } }
/// <summary> /// Opens file in an editor window /// </summary> /// <param name="fileName">File name</param> /// <param name="contentType">File content type</param> private string TypeFileInEditor(string fileName, string contentType) { using (var script = new TestScript(contentType)) { string text = _files.LoadDestinationFile(fileName); script.Type(text, idleTime: 10); return script.EditorText; } }
public void R_RequireIntellisense() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("require(uti"); script.DoIdle(100); script.Type("{TAB}"); string expected = "require(utils)"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_AutoFormatFunctionBraces() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("function(a,b){"); script.DoIdle(300); script.Type("{ENTER}a"); string expected = "function(a, b) {\r\n a\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_KeywordIntellisense() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("funct"); script.DoIdle(100); script.Type("{TAB}"); string expected = "function"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_SmartIndentTest() { using (var script = new TestScript(string.Empty, RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = false; script.MoveRight(); script.Type("{{ENTER}a"); script.DoIdle(300); string expected = "{\r\n a\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_LibrarySuggestedActions() { using (var script = new TestScript(" library(base)", RContentTypeDefinition.ContentType)) { IEnumerable<SuggestedActionSet> sets = null; ILightBulbSession session = null; var e = EditorShell.Current.ExportProvider; var svc = e.GetExportedValue<ISuggestedActionCategoryRegistryService>(); script.Invoke(() => { var broker = e.GetExportedValue<ILightBulbBroker>(); broker.CreateSession(svc.AllCodeFixes, EditorWindow.CoreEditor.View); session = script.GetLightBulbSession(); session.Should().NotBeNull(); session.Expand(); session.TryGetSuggestedActionSets(out sets); }); sets.Should().NotBeNull(); sets.Should().HaveCount(0); session.Dismiss(); script.DoIdle(200); script.MoveRight(2); script.DoIdle(200); sets = null; script.Invoke(() => { var broker = e.GetExportedValue<ILightBulbBroker>(); broker.CreateSession(svc.Any, EditorWindow.CoreEditor.View); session = script.GetLightBulbSession(); session.Should().NotBeNull(); session.Expand(); session.TryGetSuggestedActionSets(out sets); }); script.DoIdle(3000); sets = null; script.Invoke(() => { session.TryGetSuggestedActionSets(out sets); }); sets.Should().NotBeNull(); sets.Should().HaveCount(1); var set = sets.First(); set.Actions.Should().HaveCount(2); var actions = set.Actions.ToArray(); actions[0].Should().BeOfType(typeof(InstallPackageSuggestedAction)); actions[1].Should().BeOfType(typeof(LoadLibrarySuggestedAction)); } }
public void R_AutoFormatScopeBraces02() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = true; script.Type("if(x>1){ENTER}{"); script.DoIdle(300); script.Type("{ENTER}a"); string expected = "if (x > 1) \r\n{\r\n a\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_SelectWord03() { using (var script = new TestScript("abc\'def", RContentTypeDefinition.ContentType)) { script.Execute(Languages.Editor.Controller.Constants.VSConstants.VSStd2KCmdID.SELECTCURRENTWORD); var span = EditorWindow.CoreEditor.View.Selection.StreamSelectionSpan; var selectedWord = span.GetText(); selectedWord.Should().Be("abc"); script.MoveRight(2); script.Execute(Languages.Editor.Controller.Constants.VSConstants.VSStd2KCmdID.SELECTCURRENTWORD); span = EditorWindow.CoreEditor.View.Selection.StreamSelectionSpan; selectedWord = span.GetText(); selectedWord.Should().Be("def"); } }
public void R_AutoFormatScopeBraces03() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = false; script.Type("while(true) {"); script.DoIdle(300); script.Type("{ENTER}if(x>1) {"); script.DoIdle(300); script.Type("{ENTER}foo"); string expected = "while (true) {\r\n if (x > 1) {\r\n foo\r\n }\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_ProvisionalCurlyBrace01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = false; script.Type("while(1)"); script.DoIdle(300); script.Type("{"); script.DoIdle(300); script.Type("{ENTER}}"); string expected = "while (1) {\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_OutlineToggleAll() { string text = _files.LoadDestinationFile("lsfit.r"); using (var script = new TestScript(text, RContentTypeDefinition.ContentType)) { script.DoIdle(500); IOutliningManagerService svc = EditorShell.Current.ExportProvider.GetExportedValue<IOutliningManagerService>(); IOutliningManager mgr = svc.GetOutliningManager(EditorWindow.CoreEditor.View); var snapshot = EditorWindow.TextBuffer.CurrentSnapshot; var viewLines = EditorWindow.CoreEditor.View.TextViewLines; viewLines.Count.Should().Be(40); script.DoIdle(500); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL); script.DoIdle(1000); IEnumerable<ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))); collapsed.Count().Should().Be(20); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL); script.DoIdle(500); viewLines = EditorWindow.CoreEditor.View.TextViewLines; viewLines.Count.Should().Be(40); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL); script.DoIdle(200); mgr.Enabled.Should().Be(false); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING); script.DoIdle(200); mgr.Enabled.Should().Be(true); script.MoveDown(9); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT); script.DoIdle(500); collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))); collapsed.Count().Should().Be(1); EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT); script.DoIdle(200); collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))); collapsed.Count().Should().Be(0); } }
public void R_CompletionFilter01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("x <- lm"); script.DoIdle(100); script.Type("mmm"); script.DoIdle(100); script.Backspace(); script.Backspace(); script.Backspace(); script.Backspace(); script.DoIdle(100); script.Type("abels.{TAB}"); string expected = "x <- labels.default"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_FormatSelection01() { string content = @" while (TRUE) { if(x>1) { } }"; string expected = @" while (TRUE) { if (x > 1) { } }"; using (var script = new TestScript(content, RContentTypeDefinition.ContentType)) { script.Select(20, 21); script.Execute(VSConstants.VSStd2KCmdID.FORMATSELECTION, 50); string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_CompletionFunctionBraces02() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { var provider = EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>(); using (var hostScript = new RHostScript(provider)) { string message = null; hostScript.Session.Output += (s, e) => { message = e.Message; }; script.DoIdle(100); script.Type("bas"); script.DoIdle(1000); script.Type("{TAB}"); script.DoIdle(100); string actual = script.EditorText; actual.Should().Be("base"); message.Should().NotContain("Error"); } } }
public void R_NoCompletionOnTab() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { var provider = EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>(); using (var hostScript = new RHostScript(provider)) { script.DoIdle(100); script.Type("f1<-function(x,y"); script.DoIdle(300); script.Type("{TAB}"); script.DoIdle(100); string actual = script.EditorText; actual.Should().Be("f1<-function(x,y)"); EditorWindow.CoreEditor.View.Caret.Position.BufferPosition.Position.Should().Be(actual.Length); } } }
public void R_AutoFormatFuncionDefinition01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = true; string text = "library ( abind){ENTER}x <-function (x,y, wt= NULL, intercept =TRUE, tolerance=1e-07, {ENTER} yname = NULL){ENTER}{{ENTER}abind(a, )"; script.Type(text); script.DoIdle(300); string actual = script.EditorText; string expected = @"library(abind) x <- function(x, y, wt = NULL, intercept = TRUE, tolerance = 1e-07, yname = NULL) { abind(a, ) }"; actual.Should().Be(expected); } }
public void R_AutoFormatOnSemicolon() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("x<-1;"); string expected = "x <- 1;"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_AutoFormatIfNoScope() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("if(x>1)"); script.DoIdle(300); script.Type("{ENTER}a"); string expected = "if (x > 1)\r\n a"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_AutoFormatFunctionArgument() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = false; script.Type("zzzz(a=1,{ENTER}"); script.DoIdle(300); script.Type("b=2"); string expected = "zzzz(a = 1,\r\n b=2)"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_AutoFormatScopeBraces10() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = false; script.Type("if(TRUE){"); script.DoIdle(300); script.Type("{ENTER}a"); script.MoveDown(); script.MoveRight(); script.Type("{ENTER}"); string expected = "if (TRUE) {\r\n a\r\n}\r\n"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_CompletionOnTab() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { var provider = EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>(); using (var hostScript = new RHostScript(provider)) { REditorSettings.ShowCompletionOnTab = true; script.DoIdle(100); script.Type("f1<-x"); EditorShell.Current.DispatchOnUIThread(() => script.GetCompletionSession().Dismiss()); script.DoIdle(300); script.Type("{TAB}"); script.DoIdle(500); script.Type("{TAB}"); script.DoIdle(200); string actual = script.EditorText; actual.Should().Be("f1<-x11"); REditorSettings.ShowCompletionOnTab = false; } } }
public void R_AutoFormatScopeBraces08() { using (var script = new TestScript("while (true) {\r\n}", RContentTypeDefinition.ContentType)) { REditorSettings.FormatOptions.BracesOnNewLine = true; script.MoveDown(); script.Enter(); string expected = "while (true) {\r\n\r\n}"; string actual = script.EditorText; actual.Should().Be(expected); } }
public void R_CompletionFilter02() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { script.Type("x <- lm"); script.DoIdle(100); script.Type("+"); string expected = "x <- lm+"; string actual = script.EditorText; actual.Should().Be(expected); } }
public async Task R_DeclaredVariablesCompletion01() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { var provider = EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>(); using (var hostScript = new RHostScript(provider)) { await ExecuteRCode(hostScript.Session, "zzz111 <- 1\r\n"); await ExecuteRCode(hostScript.Session, "zzz111$y222 <- 2\r\n"); PrimeIntellisenseProviders(); script.DoIdle(500); script.Type("zzz1"); script.DoIdle(500); script.Type("{TAB}"); script.DoIdle(500); script.Type("$"); script.DoIdle(500); script.Type("y2"); script.DoIdle(500); script.Type("{TAB}"); string expected = "zzz111$y222"; string actual = script.EditorText; actual.Should().Be(expected); } } }
public async Task R_DeclaredVariablesCompletion02() { using (var script = new TestScript(RContentTypeDefinition.ContentType)) { var provider = EditorShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>(); using (var hostScript = new RHostScript(provider)) { await ExecuteRCode(hostScript.Session, "setClass('Person', representation(name = 'character', age = 'numeric'))\r\n"); await ExecuteRCode(hostScript.Session, "hadley <- new('Person', name = 'Hadley', age = 31)\r\n"); PrimeIntellisenseProviders(); script.DoIdle(1000); script.Type("hadle"); script.DoIdle(500); script.Type("{TAB}"); script.DoIdle(500); script.Type("@"); script.DoIdle(500); script.Type("na"); script.DoIdle(500); script.Type("{TAB}"); string expected = "hadley@name"; string actual = script.EditorText; actual.Should().Be(expected); } } }