diff options
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense')
8 files changed, 170 insertions, 9 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs index c8beebd28..191f99b6c 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs @@ -31,7 +31,7 @@ namespace Tango.Scripting.Editors.Intellisense int index = editor.GetCurrentWordStartIndex(); int max = editor.GetCurrentLine().EndOffset; - editor.Document.Replace(index, word.Length,Text); + editor.Document.Replace(index, word.Length, GetCode()); } public abstract BitmapSource Image { get; } @@ -41,6 +41,11 @@ namespace Tango.Scripting.Editors.Intellisense return new BitmapImage(new Uri($"pack://application:,,,/Tango.Scripting.Editors;component/Images/{name}", UriKind.Absolute)); } + protected virtual String GetCode() + { + return Text; + } + public override string ToString() { return Text; diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs new file mode 100644 index 000000000..5c510c39f --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class EventCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("event.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new FieldCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Class { get; set; } + public String Type { get; set; } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/HideIntellisenseAttribute.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/HideIntellisenseAttribute.cs new file mode 100644 index 000000000..548bd909e --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/HideIntellisenseAttribute.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class HideIntellisenseAttribute : Attribute + { + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs index 28f9ccb9a..8010dc689 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -1,11 +1,14 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; using System.Xml; using Tango.Core; @@ -14,16 +17,18 @@ namespace Tango.Scripting.Editors.Intellisense public class KnownType { private bool _initialized; - private bool _documentationLoaded; + public String Alias { get; set; } + public bool DocumentationLoaded { get; set; } public Type Type { get; private set; } - public String Name { get; private set; } + public String Name { get; set; } public String TypeDefinition { get; private set; } public String FriendlyName { get; private set; } public String Summary { get; set; } public List<KnownTypeConstructor> Constructors { get; set; } public List<KnownTypeMethod> Methods { get; set; } public List<KnownTypeProperty> Properties { get; set; } + public List<KnownTypeEvent> Events { get; set; } public List<KnownTypeMember> Members { get @@ -32,12 +37,20 @@ namespace Tango.Scripting.Editors.Intellisense members.AddRange(Properties); members.AddRange(Methods); + members.AddRange(Events); return members.OrderBy(x => x.Name).ToList(); } } public List<KnownTypeField> Fields { get; set; } + public static List<Assembly> ExtensionMethodsAssemblies { get; set; } + + static KnownType() + { + ExtensionMethodsAssemblies = new List<Assembly>(); + } + public KnownType(Type type) { Summary = "Loading documentation..."; @@ -45,6 +58,7 @@ namespace Tango.Scripting.Editors.Intellisense Methods = new List<KnownTypeMethod>(); Properties = new List<KnownTypeProperty>(); Fields = new List<KnownTypeField>(); + Events = new List<KnownTypeEvent>(); Type = type; Name = type.Name; @@ -118,9 +132,31 @@ namespace Tango.Scripting.Editors.Intellisense { var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); + if (Type.IsInterface) + { + foreach (var inter in Type.GetInterfaces()) + { + methods.AddRange(inter.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList()); + } + methods = methods.Distinct().ToList(); + + if (!methods.Exists(x => x.Name == "ToString")) + { + methods.Add(typeof(Object).GetMethod("ToString")); + } + } + //TODO: Separate extension methods! methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); + if (Type.Namespace.StartsWith("Tango")) + { + foreach (var asm in ExtensionMethodsAssemblies.Where(x => x != Type.Assembly)) + { + methods.AddRange(Type.GetExtensionMethods(asm).ToList()); + } + } + if (typeof(IEnumerable).IsAssignableFrom(Type)) { var linqMethods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList(); @@ -131,10 +167,13 @@ namespace Tango.Scripting.Editors.Intellisense { var method = methods[i]; + if (method.GetCustomAttribute<HideIntellisenseAttribute>() != null) continue; + KnownTypeMethod m = new KnownTypeMethod(this); m.Name = method.Name; m.ReturnType = method.ReturnType; m.ReturnTypeFriendlyName = method.ReturnType.GetFriendlyName(); + m.IsStatic = method.IsStatic && !method.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false); if (method.IsGenericMethod) { @@ -148,6 +187,11 @@ namespace Tango.Scripting.Editors.Intellisense bool isLinq = method.DeclaringType == typeof(Enumerable); + if (isLinq) + { + m.IsStatic = false; + } + for (int j = 0; j < parameters.Count; j++) { var parameter = parameters[j]; @@ -171,12 +215,14 @@ namespace Tango.Scripting.Editors.Intellisense //Load Properties { - var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); + var properties = Type.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static).ToList(); for (int i = 0; i < properties.Count; i++) { var property = properties[i]; + if (property.GetCustomAttribute<HideIntellisenseAttribute>() != null) continue; + KnownTypeProperty p = new KnownTypeProperty(this); p.Name = property.Name; p.ReturnType = property.PropertyType; @@ -186,6 +232,23 @@ namespace Tango.Scripting.Editors.Intellisense } } + //Load Events + { + var events = Type.GetRuntimeEvents().ToList(); + + for (int i = 0; i < events.Count; i++) + { + var ev = events[i]; + + if (ev.GetCustomAttribute<HideIntellisenseAttribute>() != null) continue; + + KnownTypeEvent p = new KnownTypeEvent(this); + p.Name = ev.Name; + + Events.Add(p); + } + } + //Load Enum Values { if (Type.IsEnum) @@ -211,9 +274,9 @@ namespace Tango.Scripting.Editors.Intellisense public void LoadDocumentation() { - if (!_documentationLoaded) + if (!DocumentationLoaded) { - _documentationLoaded = true; + DocumentationLoaded = true; Utils.LoadKnownTypeDocs(this); } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs new file mode 100644 index 000000000..7403d2cbd --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownTypeEvent : KnownTypeMember + { + public KnownTypeEvent() + { + Summary = "Loading documentation..."; + } + + public KnownTypeEvent(KnownType knownType) : this() + { + Type = knownType; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs index f84e26fe5..4cedad377 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs @@ -8,6 +8,8 @@ namespace Tango.Scripting.Editors.Intellisense { public class KnownTypeMethod : KnownTypeMember { + public bool IsStatic { get; set; } + public List<KnownTypeMethodParameter> Parameters { get; set; } public List<String> TypeArguments { get; set; } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/SnippetCompletionItem.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/SnippetCompletionItem.cs new file mode 100644 index 000000000..97807ed19 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/SnippetCompletionItem.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class SnippetCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("snippet.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new FieldCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Code { get; set; } + + protected override string GetCode() + { + return Code; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs index f8cc7072d..2ead15d0d 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs @@ -150,7 +150,12 @@ namespace Tango.Scripting.Editors.Intellisense var property = knownType.Properties[i]; var pDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(knownType.Type.Name + "." + property.Name)); - property.Summary = pDoc != null ? pDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + + if (pDoc != null) + { + var summaryNode = pDoc.SelectSingleNode("summary"); + property.Summary = summaryNode != null ? summaryNode.InnerXml : "No documentation"; + } } } @@ -162,7 +167,12 @@ namespace Tango.Scripting.Editors.Intellisense { var field = knownType.Fields[i]; var pDoc = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + $"F:{knownType.Type.FullName}.{field.Name}" + "')]"); - field.Summary = pDoc != null ? pDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + + if (pDoc != null) + { + var summaryNode = pDoc.SelectSingleNode("summary"); + field.Summary = summaryNode != null ? summaryNode.InnerXml : "No documentation"; + } } } } |
