public void EnterCommits() { using (PythonEditor view = new PythonEditor()) { view.TypeAndWaitForAnalysis("min"); view.Type("."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__"); view.Type("class\r"); } Assert.AreEqual("min.__class__", view.Text); } }
public void FilterCompletions() { using (PythonEditor view = new PythonEditor()) { view.TypeAndWaitForAnalysis("min"); view.Type("."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.Contains(sh.Session.Completions(), "__call__"); view.Type("class"); AssertUtil.DoesntContain(sh.Session.Completions(), "__call__"); } } }
public void DotCompletes() { using (PythonEditor view = new PythonEditor()) { view.TypeAndWaitForAnalysis("min"); view.Type("."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.Contains(sh.Session.Completions(), "__call__"); view.Type("class."); Assert.AreEqual("min.__class__.", view.Text); } } }
public ClassifierHelper(string code, PythonLanguageVersion version) { _view = new PythonEditor("", version); var providers = _view.VS.ComponentModel.GetExtensions <IClassifierProvider>().ToArray(); _provider1 = providers.OfType <PythonClassifierProvider>().Single(); _provider2 = providers.OfType <PythonAnalysisClassifierProvider>().Single(); _classificationsReady1 = new ManualResetEventSlim(); _classificationsReady2 = new ManualResetEventSlim(); AstClassifier.ClassificationChanged += (s, e) => _classificationsReady1.SetIfNotDisposed(); AnalysisClassifier.ClassificationChanged += (s, e) => _classificationsReady2.SetIfNotDisposed(); _view.Text = code; }
public void DisableAutoCompletions() { using (PythonEditor view = new PythonEditor()) { view.AdvancedOptions.AutoListMembers = false; view.AdvancedOptions.AutoListIdentifiers = false; foreach (global::System.String t in new[] { "a", "a.", "import " }) { Console.WriteLine("Typed " + t); view.Type(t); view.View.AssertNoIntellisenseSession(); view.Clear(); } } }
public void EnterDismisses() { using (PythonEditor view = new PythonEditor()) { view.AdvancedOptions.EnterCommitsIntellisense = false; view.AdvancedOptions.AutoListMembers = true; view.TypeAndWaitForAnalysis("min"); view.Type("."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__"); view.Type("class\r"); } Assert.AreEqual("min.class\r\n", view.Text); } }
public void NonIdentifierDismisses() { using (PythonEditor view = new PythonEditor()) { view.TypeAndWaitForAnalysis("min"); view.Type("."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.Contains(sh.Session.Completions(), "__call__"); view.Type("#"); Assert.IsTrue(sh.Session.IsDismissed); } view.View.AssertNoIntellisenseSession(); Assert.AreEqual("min.#", view.Text); } }
public void EnterCommitsCompleteNoNewLine() { using (PythonEditor view = new PythonEditor()) { view.AdvancedOptions.AddNewLineAtEndOfFullyTypedWord = true; view.AdvancedOptions.AutoListMembers = true; view.AdvancedOptions.AutoListIdentifiers = false; view.AdvancedOptions.HideAdvancedMembers = false; view.Type("min.__"); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__"); view.Type("class__\r"); } Assert.AreEqual("min.__class__\r\n", view.Text); } }
public void CompletionsAtEndOfLastChildScope() { using (PythonEditor view = new PythonEditor(@"class A: def f(param1, param2): y = 234 class B: pass ")) { view.MoveCaret(5, 9); view.TypeAndWaitForAnalysis("p"); view.MemberList(); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.ContainsAtLeast(sh.Session.Completions(), "param1", "param2"); } } }
public void TabCommits() { using (PythonEditor view = new PythonEditor()) { view.AdvancedOptions.EnterCommitsIntellisense = false; view.AdvancedOptions.AutoListMembers = true; view.AdvancedOptions.AutoListIdentifiers = false; view.AdvancedOptions.HideAdvancedMembers = false; view.Type("min."); using (var sh = view.View.WaitForSession <ICompletionSession>()) { AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__"); view.Type("class\t"); } Assert.AreEqual("min.__class__", view.Text); } }
public void NewlineWithinComment() { using (PythonEditor view = new PythonEditor(@"# comment")) { view.MoveCaret(1, 1); view.Enter(); Assert.AreEqual(2, view.CurrentSnapshot.LineCount); Assert.AreEqual("", view.CurrentSnapshot.GetLineFromLineNumber(0).GetText()); Assert.AreEqual("# comment", view.CurrentSnapshot.GetLineFromLineNumber(1).GetText()); } using (PythonEditor view = new PythonEditor(@"# comment")) { view.MoveCaret(1, 3); view.Enter(); Assert.AreEqual(2, view.CurrentSnapshot.LineCount); Assert.AreEqual("# ", view.CurrentSnapshot.GetLineFromLineNumber(0).GetText()); Assert.AreEqual("# comment", view.CurrentSnapshot.GetLineFromLineNumber(1).GetText()); } using (PythonEditor view = new PythonEditor(@"# comment")) { view.MoveCaret(1, 10); view.Enter(); Assert.AreEqual(2, view.CurrentSnapshot.LineCount); Assert.AreEqual("# comment", view.CurrentSnapshot.GetLineFromLineNumber(0).GetText()); Assert.AreEqual("", view.CurrentSnapshot.GetLineFromLineNumber(1).GetText()); } using (PythonEditor view = new PythonEditor(@" # comment")) { view.MoveCaret(1, 7); view.Enter(); Assert.AreEqual(2, view.CurrentSnapshot.LineCount); Assert.AreEqual(" # ", view.CurrentSnapshot.GetLineFromLineNumber(0).GetText()); Assert.AreEqual(" # comment", view.CurrentSnapshot.GetLineFromLineNumber(1).GetText()); } }
public void AutoListIdentifierCompletions() { using (PythonEditor view = new PythonEditor()) { view.AdvancedOptions.AutoListIdentifiers = true; view.Type("a = "); foreach (var c in "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ") { // x<space> should bring up a completion session Console.WriteLine("Typing {0}", c); view.Type(c.ToString()); using (var sh = view.View.WaitForSession <ICompletionSession>()) { sh.Session.Dismiss(); } view.Backspace(); } view.View.AssertNoIntellisenseSession(); // x<space> should not bring up a completion session // Don't check too many items, since asserting that no session // starts is slow. foreach (var c in "1234567890([{") { Console.WriteLine("Typing {0}", c); view.Type(c.ToString()); view.View.AssertNoIntellisenseSession(); view.Backspace(); } } }
public void BuiltinFunctionSigHelp() { using (PythonEditor view = new PythonEditor()) { view.TypeAndWaitForAnalysis("min"); view.Type("("); for (int retries = 10; retries > 0; --retries) { using (var sh = view.View.WaitForSession <ISignatureHelpSession>()) { var doc = sh.Session.Signatures[0].Documentation; if (doc.Contains("still being calculated")) { view.VS.Sleep(100); continue; } AssertUtil.AreEqual(new Regex(@".*min\([^)]+\).*"), doc); break; } } } }
private void AutoListTest(string code, PythonLanguageVersion version, params int[] triggerAtIndex) { using (PythonEditor view = new PythonEditor(version: version)) { view.AdvancedOptions.AutoListIdentifiers = true; view.AdvancedOptions.AutoListMembers = true; int lastStart = 0; string text; foreach (global::System.Int32 _i in triggerAtIndex) { bool expectCompletions = _i >= 0; int expected = _i > 0 ? _i : -_i; text = code.Substring(lastStart, expected - lastStart); if (!string.IsNullOrEmpty(text)) { Console.WriteLine("Typing '{0}' [{1}, {2})", text, lastStart, expected); view.Type(text); using (var sh = view.View.WaitForSession <ICompletionSession>(false)) { // Having a session here is okay as long as nothing is selected var hasCommittableCompletion = sh?.Session?.SelectedCompletionSet?.SelectionStatus?.IsSelected ?? false; if (hasCommittableCompletion) { sh.Session.Dismiss(); Assert.Fail($"Completion for {text} should not have any item selected"); } else if (sh != null) { sh.Session.Dismiss(); } } } lastStart = expected; if (expectCompletions) { text = code.Substring(expected, 1); Console.WriteLine("Typing '{0}' [{1}, {2}) and expect completions", text, expected, expected + 1); view.Type(text); using (var sh = view.View.WaitForSession <ICompletionSession>()) { sh.Session.Dismiss(); } lastStart = expected + 1; } } text = code.Substring(lastStart); if (!string.IsNullOrEmpty(text)) { Console.WriteLine("Typing '{0}' [{1}, {2})", text, lastStart, code.Length); view.Type(text); view.View.AssertNoIntellisenseSession(); } } }