public IronPythonCompletionData(string text, string stub, bool isInstance, CompletionType type, IronPythonCompletionProvider provider) { this.Text = text; this.Stub = stub; this.IsInstance = isInstance; this.provider = provider; if (IronPythonCompletionData.TypeToIcon == null) { TypeToIcon = new Dictionary<CompletionType, BitmapImage>(); var assembly = Assembly.GetExecutingAssembly(); var bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.method.png"); bi.EndInit(); TypeToIcon.Add(CompletionType.METHOD, bi); var b2 = new BitmapImage(); b2.BeginInit(); b2.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.namespace.png"); b2.EndInit(); TypeToIcon.Add(CompletionType.NAMESPACE, b2); var b3 = new BitmapImage(); b3.BeginInit(); b3.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.field.png"); b3.EndInit(); TypeToIcon.Add(CompletionType.FIELD, b3); var b4 = new BitmapImage(); b4.BeginInit(); b4.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.class.png"); b4.EndInit(); TypeToIcon.Add(CompletionType.CLASS, b4); var b5 = new BitmapImage(); b5.BeginInit(); b5.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.property.png"); b5.EndInit(); TypeToIcon.Add(CompletionType.PROPERTY, b5); var b6 = new BitmapImage(); b6.BeginInit(); b6.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.property.png"); b6.EndInit(); TypeToIcon.Add(CompletionType.ENUM, b6); } this._image = TypeToIcon[type]; }
public void CanFindSystemCollectionsAssignmentAndType() { var str = "from System.Collections import ArrayList\na = ArrayList()\n"; var completionProvider = new IronPythonCompletionProvider(); completionProvider.UpdateImportedTypes(str); completionProvider.UpdateVariableTypes(str); Assert.IsTrue(completionProvider.VariableTypes.ContainsKey("a")); Assert.AreEqual(typeof(System.Collections.ArrayList), completionProvider.VariableTypes["a"]); }
public void CanFindDifferentTypesOfImportsAndLoad() { var str = "from itertools import *\nimport math\nfrom sys import callstats\n"; var completionProvider = new IronPythonCompletionProvider(); completionProvider.UpdateImportedTypes(str); Assert.AreEqual(3, completionProvider.ImportedTypes.Count); Assert.IsTrue(completionProvider.Scope.ContainsVariable("repeat")); Assert.IsTrue(completionProvider.Scope.ContainsVariable("izip")); Assert.IsTrue(completionProvider.Scope.ContainsVariable("math")); Assert.IsTrue(completionProvider.Scope.ContainsVariable("callstats")); }
public void CanIdentifyVariableTypeAndGetCompletionData() { var str = "a = 5.0\na."; var completionProvider = new IronPythonCompletionProvider(); var completionData = completionProvider.GetCompletionData(str); Assert.AreNotEqual(0, completionData.Length); }
public void CanGetCompletionDataForArrayListVariable() { var str = "from System.Collections import ArrayList\na = ArrayList()\na."; var completionProvider = new IronPythonCompletionProvider(); var matches = completionProvider.GetCompletionData(str); Assert.AreNotEqual(0, matches.Length); //Assert.AreEqual(typeof(IronPython.Runtime.PythonDictionary), matches["a"].Item3); }
public void DuplicateCallsToImportShouldBeFine() { var str = "\nimport System\nimport System"; var completionProvider = new IronPythonCompletionProvider(); completionProvider.UpdateImportedTypes(str); Assert.AreEqual(1, completionProvider.ImportedTypes.Count); Assert.IsTrue(completionProvider.ImportedTypes.ContainsKey("System")); }
public void CanMatchAllVariableTypes() { var str = "a = { 'Alice': 7, 'Toby': 'Nuts' }\nb = {}\nc = 5.0\nd = 'pete'\ne = []"; var completionProvider = new IronPythonCompletionProvider(); var matches = completionProvider.FindAllVariables(str); Assert.AreEqual(5, matches.Count); Assert.AreEqual(typeof(IronPython.Runtime.PythonDictionary), matches["a"].Item3); Assert.AreEqual(typeof(IronPython.Runtime.PythonDictionary), matches["b"].Item3); Assert.AreEqual(typeof(double), matches["c"].Item3); Assert.AreEqual(typeof(string), matches["d"].Item3); Assert.AreEqual(typeof(IronPython.Runtime.List), matches["e"].Item3); }
public void CanMatchImportSystemAndLoadLibraryAndWithComment() { var str = "# Write your script here.\r\nimport System."; var completionProvider = new IronPythonCompletionProvider(); completionProvider.UpdateImportedTypes(str); Assert.AreEqual(1, completionProvider.ImportedTypes.Count); Assert.IsTrue(completionProvider.ImportedTypes.ContainsKey("System")); }
public void CanMatchAllVariablesSingleLine() { var str = "a = { 'Alice': 7, 'Toby': 'Nuts' }"; var completionProvider = new IronPythonCompletionProvider(); var matches = completionProvider.FindAllVariables(str); Assert.AreEqual(1, matches.Count); Assert.AreEqual(typeof( IronPython.Runtime.PythonDictionary), matches["a"].Item3); }
public void CanImportSystemLibraryAndGetCompletionData() { var str = "\nimport System\nSystem."; var completionProvider = new IronPythonCompletionProvider(); var completionData = completionProvider.GetCompletionData(str); Assert.AreEqual(224, completionData.Length); Assert.AreEqual(1, completionProvider.ImportedTypes.Count); Assert.IsTrue(completionProvider.ImportedTypes.ContainsKey("System")); }
public void CanImportSystemCollectionsLibraryAndGetCompletionData() { var str = "\nimport System.Collections\nSystem.Collections."; var completionProvider = new IronPythonCompletionProvider(); var completionData = completionProvider.GetCompletionData(str); Assert.AreEqual(29, completionData.Length); }
public void CanImportLibrary() { var str = "\nimport System\n"; var completionProvider = new IronPythonCompletionProvider(); completionProvider.UpdateImportedTypes(str); Assert.AreEqual(1, completionProvider.ImportedTypes.Count); Assert.IsTrue(completionProvider.ImportedTypes.ContainsKey("System")); }
public IronPythonCompletionData(string text, string stub, bool isInstance, CompletionType type, IronPythonCompletionProvider provider) { this.Text = text; this.Stub = stub; this.IsInstance = isInstance; this.provider = provider; if (IronPythonCompletionData.TypeToIcon == null) { TypeToIcon = new Dictionary <CompletionType, BitmapImage>(); var assembly = Assembly.GetExecutingAssembly(); var bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.method.png"); bi.EndInit(); TypeToIcon.Add(CompletionType.METHOD, bi); var b2 = new BitmapImage(); b2.BeginInit(); b2.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.namespace.png"); b2.EndInit(); TypeToIcon.Add(CompletionType.NAMESPACE, b2); var b3 = new BitmapImage(); b3.BeginInit(); b3.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.field.png"); b3.EndInit(); TypeToIcon.Add(CompletionType.FIELD, b3); var b4 = new BitmapImage(); b4.BeginInit(); b4.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.class.png"); b4.EndInit(); TypeToIcon.Add(CompletionType.CLASS, b4); var b5 = new BitmapImage(); b5.BeginInit(); b5.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.property.png"); b5.EndInit(); TypeToIcon.Add(CompletionType.PROPERTY, b5); var b6 = new BitmapImage(); b6.BeginInit(); b6.StreamSource = assembly.GetManifestResourceStream(@"DynamoPython.Resources.property.png"); b6.EndInit(); TypeToIcon.Add(CompletionType.ENUM, b6); } this._image = TypeToIcon[type]; }