本文整理汇总了C#中PythonToolsMockTests.PythonEditor类的典型用法代码示例。如果您正苦于以下问题:C# PythonEditor类的具体用法?C# PythonEditor怎么用?C# PythonEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonEditor类属于PythonToolsMockTests命名空间,在下文中一共展示了PythonEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnresolvedImportSquiggle
public void UnresolvedImportSquiggle() {
List<string> squiggles;
using (var view = new PythonEditor("import fob, oar\r\nfrom baz import *\r\nfrom .spam import eggs")) {
var errorProvider = view.VS.ServiceProvider.GetComponentModel().GetService<IErrorProviderFactory>();
var tagger = errorProvider.GetErrorTagger(view.View.TextView.TextBuffer);
// Ensure all tasks have been updated
var taskProvider = (ErrorTaskProvider)view.VS.ServiceProvider.GetService(typeof(ErrorTaskProvider));
var time = taskProvider.FlushAsync().GetAwaiter().GetResult();
Console.WriteLine("TaskProvider.FlushAsync took {0}ms", time.TotalMilliseconds);
squiggles = tagger.GetTaggedSpans(new SnapshotSpan(view.CurrentSnapshot, 0, view.CurrentSnapshot.Length))
.Select(FormatErrorTag)
.ToList();
}
Console.WriteLine(" Squiggles found:");
foreach (var actual in squiggles) {
Console.WriteLine(actual);
}
Console.WriteLine(" Found {0} squiggle(s)", squiggles.Count);
int i = 0;
foreach (var expected in new[] {
// Ensure that the warning includes the module name
@".*warning:.*fob.*\(7-10\)",
@".*warning:.*oar.*\(12-15\)",
@".*warning:.*baz.*\(22-25\)",
@".*warning:.*\.spam.*\(41-46\)"
}) {
Assert.IsTrue(i < squiggles.Count, "Not enough squiggles");
AssertUtil.AreEqual(new Regex(expected, RegexOptions.IgnoreCase | RegexOptions.Singleline), squiggles[i]);
i += 1;
}
}
示例2: CtrlSpaceCompletions
public void CtrlSpaceCompletions() {
using (var view = new PythonEditor()) {
view.Text = @"def f(param1, param2):
g()";
AssertUtil.ContainsAtLeast(view.GetCompletionsAfter("g("), "param1", "param2");
view.Text = @"def f(param1, param2):
g(param1, )";
AssertUtil.ContainsAtLeast(view.GetCompletionsAfter("g(param1, "), "param1", "param2");
// verify Ctrl-Space inside of a function gives proper completions
foreach (var codeSnippet in new[] { @"def f():
pass", @"def f():
x = (2 + 3)
pass
", @"def f():
yield (2 + 3)
pass" }) {
Debug.WriteLine(String.Format("Testing {0}", codeSnippet));
view.Text = codeSnippet;
AssertUtil.ContainsAtLeast(view.GetCompletions(codeSnippet.IndexOf("\r\n pass")), "min", "assert");
}
}
}
示例3: GetApplicableSpanTest
public void GetApplicableSpanTest() {
var text = "if fob.oar(eggs, spam<=ham) :";
using (var view = new PythonEditor(text)) {
var snapshot = view.CurrentSnapshot;
// We check the applicable span at every index in the string.
var expected = new[] {
"if", "if", "if",
"fob", "fob", "fob", "fob",
"oar", "oar", "oar", "oar",
"eggs", "eggs", "eggs", "eggs", "eggs",
"", // between ',' and ' '
"spam", "spam", "spam", "spam", "spam",
"", // between '<' and '='
"ham", "ham", "ham", "ham",
"", // between ')' and ' '
"", // between ' ' and ':'
"", // between ':' and EOL
};
for (int i = 0; i < text.Length; ++i) {
var span = snapshot.GetApplicableSpan(i);
if (span == null) {
Assert.AreEqual(expected[i], "", text.Substring(0, i) + "|" + text.Substring(i));
} else {
Assert.AreEqual(expected[i], span.GetText(snapshot), text.Substring(0, i) + "|" + text.Substring(i));
}
}
}
}
示例4: AutoListIdentifierCompletions
public void AutoListIdentifierCompletions()
{
using (var 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();
}
}
}
示例5: BuiltinFunctionCompletions
public void BuiltinFunctionCompletions() {
using (var view = new PythonEditor()) {
view.Type("min.");
using (var sh = view.View.WaitForSession<ICompletionSession>()) {
AssertUtil.Contains(sh.Session.Completions(), "__call__");
}
}
}
示例6: SigHelpInClass
public void SigHelpInClass() {
using (var view = new PythonEditor()) {
view.Type("class C(): pass");
view.MoveCaret(1, 9);
view.ParamInfo();
view.View.AssertNoIntellisenseSession();
}
}
示例7: FilterCompletions
public void FilterCompletions() {
using (var view = new PythonEditor()) {
view.Type("min.");
using (var sh = view.View.WaitForSession<ICompletionSession>()) {
AssertUtil.Contains(sh.Session.Completions(), "__call__");
view.Type("class");
AssertUtil.DoesntContain(sh.Session.Completions(), "__call__");
}
}
}
示例8: BuiltinFunctionSigHelp
public void BuiltinFunctionSigHelp() {
using (var view = new PythonEditor()) {
view.Type("min(");
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\(x\: object\).+?"), doc);
break;
}
}
}
}
示例9: DisableAutoCompletions
public void DisableAutoCompletions() {
using (var view = new PythonEditor()) {
view.AdvancedOptions.AutoListMembers = false;
view.AdvancedOptions.AutoListIdentifiers = false;
foreach (var t in new[] { "a", "a.", "import " }) {
Console.WriteLine("Typed " + t);
view.Type(t);
view.View.AssertNoIntellisenseSession();
view.View.Clear();
}
}
}
示例10: DecoratorNonCompletions
public void DecoratorNonCompletions() {
using (var view = new PythonEditor()) {
view.Type("a = b @");
view.View.AssertNoIntellisenseSession();
}
}
示例11: AutoListTest
private void AutoListTest(string code, PythonLanguageVersion version, params int[] triggerAtIndex) {
using (var view = new PythonEditor(version: version)) {
view.AdvancedOptions.AutoListIdentifiers = true;
view.AdvancedOptions.AutoListMembers = true;
int lastStart = 0;
string text;
foreach (var _i in triggerAtIndex) {
bool expectCompletions = _i >= 0;
int expected = _i > 0 ? _i : -_i;
text = code.Substring(lastStart, expected - lastStart);
Console.WriteLine("Typing '{0}' [{1}, {2})", text, lastStart, expected);
view.Type(text);
view.View.AssertNoIntellisenseSession();
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();
}
}
}
示例12: TabCommits
public void TabCommits() {
using (var 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);
}
}
示例13: DecoratorCompletions
public void DecoratorCompletions() {
using (var view = new PythonEditor()) {
view.Type("@");
using (var sh = view.View.WaitForSession<ICompletionSession>()) {
AssertUtil.ContainsAtLeast(sh.Session.Completions(), "property", "staticmethod");
}
}
}
示例14: HideAdvancedMembersHelper
private IEnumerable<string> HideAdvancedMembersHelper(PythonEditor view, string text, params string[] completions) {
view.Text = text;
var snapshot = view.CurrentSnapshot;
var set = new FuzzyCompletionSet(
"Test Completions",
"Test Completions",
snapshot.CreateTrackingSpan(0, snapshot.Length, SpanTrackingMode.EdgeInclusive),
completions.Select(c => new DynamicallyVisibleCompletion(c)),
new CompletionOptions { HideAdvancedMembers = true, IntersectMembers = false },
CompletionComparer.UnderscoresLast
);
set.Filter();
return set.Completions.Select(c => c.DisplayText).ToList();
}
示例15: EnterCommitsCompleteNoNewLine
public void EnterCommitsCompleteNoNewLine() {
using (var 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);
}
}