diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-03-11 10:15:33 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-03-11 10:15:33 +0200 |
| commit | 42a4c114efafe342f562eb8ab8b28e994fccd74c (patch) | |
| tree | d1eb67f51ca66be3eee55ba6274db2efdfd493fa /Software | |
| parent | b9306bd57e04308d69ce46ed711fd12dfe0843e8 (diff) | |
| parent | 8c72f411d06dfd663347bef9adaad195fd060edc (diff) | |
| download | Tango-42a4c114efafe342f562eb8ab8b28e994fccd74c.tar.gz Tango-42a4c114efafe342f562eb8ab8b28e994fccd74c.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software')
29 files changed, 1174 insertions, 658 deletions
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs index e33ede203..7766d323a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs @@ -290,7 +290,7 @@ namespace Tango.Scripting.Editors.CodeCompletion //sourceIsInitialized = true; } - private void SetPosition() + public void SetPosition() { if (document != null && this.StartOffset != this.TextArea.Caret.Offset) { @@ -301,6 +301,16 @@ namespace Tango.Scripting.Editors.CodeCompletion SetPosition(this.TextArea.Caret.Position); } } + + public void UpdatePositionFix() + { + SetPosition(this.TextArea.Caret.Position); + } + + //public void UpdatePosition() + //{ + // SetPosition(this.TextArea.Caret.Position); + //} /// <inheritdoc/> protected override void OnClosed(EventArgs e) @@ -337,7 +347,7 @@ namespace Tango.Scripting.Editors.CodeCompletion /// Updates the position of the CompletionWindow based on the parent TextView position and the screen working area. /// It ensures that the CompletionWindow is completely visible on the screen. /// </summary> - protected void UpdatePosition() + public void UpdatePosition() { TextView textView = this.TextArea.TextView; // PointToScreen returns device dependent units (physical pixels) diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs index b0e9eeccb..9f16876b3 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs @@ -3,6 +3,7 @@ using System; using System.Windows.Media; +using System.Windows.Media.Imaging; using Tango.Scripting.Editors.Document; using Tango.Scripting.Editors.Editing; @@ -13,32 +14,26 @@ namespace Tango.Scripting.Editors.CodeCompletion /// </summary> public interface ICompletionData { - /// <summary> - /// Gets the image. - /// </summary> - ImageSource Image { get; } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - string Text { get; } - - /// <summary> - /// The displayed content. This can be the same as 'Text', or a WPF UIElement if - /// you want to display rich content. - /// </summary> - object Content { get; } + /// <summary> + /// Gets the image. + /// </summary> + BitmapSource Image { get; } + + /// <summary> + /// Gets the text. This property is used to filter the list of visible elements. + /// </summary> + string Text { get; } /// <summary> /// Gets the description. /// </summary> - object Description { get; } + object Description { get; set; } /// <summary> /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items /// which the user is accessing most frequently. /// </summary> - double Priority { get; } + double Priority { get; set; } /// <summary> /// Perform the completion. @@ -49,6 +44,6 @@ namespace Tango.Scripting.Editors.CodeCompletion /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how /// the insertion was triggered.</param> - void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs); + void Complete(ScriptEditor editor); } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ExtensionMethods.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ExtensionMethods.cs new file mode 100644 index 000000000..1605ff281 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ExtensionMethods.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors +{ + internal static class ExtensionMethodsNoName + { + public static String Remove(this String str, String pattern) + { + return Regex.Replace(str, pattern, ""); + } + + public static String GetFriendlyName(this Type type) + { + String name = type.Name; + + if (type.IsGenericType) + { + List<String> args = new List<string>(); + + foreach (var lGenericArgument in type.GetGenericTypeDefinition().GetGenericArguments()) + { + args.Add(lGenericArgument.Name); + } + + String gArgs = String.Join(",", args); + + name = $"{new String(type.Name.TakeWhile(x => x != '`').ToArray())}<{gArgs}>"; + } + + return name; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs new file mode 100644 index 000000000..a1734ba30 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs @@ -0,0 +1,32 @@ +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 ClassCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("class.png"); + + public override BitmapSource Image => image; + public override string Text => Name; + + public String Name { get; set; } + public String Namespace { get; set; } + public override CompletionItemPopupControl PopupControl => new ClassCompletionItemPopup(); + + public override void Complete(ScriptEditor editor) + { + base.Complete(editor); + + if (Text.Contains("<T>")) + { + editor.CaretOffset -= 2; + editor.Select(editor.CaretOffset, 1); + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs new file mode 100644 index 000000000..d575ba9db --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class ClassCompletionItemPopup : CompletionItemPopupControl + { + static ClassCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ClassCompletionItemPopup), new FrameworkPropertyMetadata(typeof(ClassCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs new file mode 100644 index 000000000..83ada090f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.Scripting.Editors.Document; +using Tango.Scripting.Editors.Editing; + +namespace Tango.Scripting.Editors.Intellisense +{ + public abstract class CompletionItem : DependencyObject, ICompletionItem + { + public abstract string Text { get; } + public object Description { get; set; } + public double Priority { get; set; } + public abstract CompletionItemPopupControl PopupControl { get; } + + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + public static readonly DependencyProperty IsSelectedProperty = + DependencyProperty.Register("IsSelected", typeof(bool), typeof(CompletionItem), new PropertyMetadata(false)); + + public virtual void Complete(ScriptEditor editor) + { + int index = editor.GetCurrentWordStartIndex(); + int max = editor.GetCurrentLine().EndOffset; + + editor.Document.Replace(index, Math.Min(max - index, Text.Length), Text); + } + + public abstract BitmapSource Image { get; } + + protected static BitmapSource GetImage(String name) + { + return new BitmapImage(new Uri($"pack://application:,,,/Tango.Scripting.Editors;component/Images/{name}", UriKind.Absolute)); + } + + public override string ToString() + { + return Text; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs new file mode 100644 index 000000000..14e5b6681 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace Tango.Scripting.Editors.Intellisense +{ + public abstract class CompletionItemPopupControl : Control + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs new file mode 100644 index 000000000..c8f34347e --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs @@ -0,0 +1,21 @@ +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 EnumCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("enum.png"); + + public override BitmapSource Image => image; + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new EnumCompletionItemPopup(); + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs new file mode 100644 index 000000000..0ef29c338 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class EnumCompletionItemPopup : CompletionItemPopupControl + { + static EnumCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(EnumCompletionItemPopup), new FrameworkPropertyMetadata(typeof(EnumCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs new file mode 100644 index 000000000..83e304e8b --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Scripting.Editors.CodeCompletion; + +namespace Tango.Scripting.Editors.Intellisense +{ + public interface ICompletionItem : ICompletionData + { + CompletionItemPopupControl PopupControl { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs new file mode 100644 index 000000000..bc48ce401 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public interface ICompletionProvider + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs new file mode 100644 index 000000000..56f6db7af --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs @@ -0,0 +1,21 @@ +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 InterfaceCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("interface.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new InterfaceCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs new file mode 100644 index 000000000..126a81c4c --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class InterfaceCompletionItemPopup : CompletionItemPopupControl + { + static InterfaceCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(InterfaceCompletionItemPopup), new FrameworkPropertyMetadata(typeof(InterfaceCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs index 3cb61b991..06282e15d 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -86,39 +87,31 @@ namespace Tango.Scripting.Editors.Intellisense public KnownType(Type type) { + _summary = "Loading documentation..."; _constructors = new List<KnownTypeConstructor>(); _methods = new List<KnownTypeMethod>(); _properties = new List<KnownTypeProperty>(); Type = type; Name = type.Name; + Init(); } + public override string ToString() + { + return Type.ToString(); + } + private void Init() { InitTypeDefinition(); InitFriendlyName(); + InitTypeDocumentation(); } private void InitFriendlyName() { - if (Type.IsGenericType) - { - List<String> args = new List<string>(); - - foreach (var lGenericArgument in Type.GetGenericTypeDefinition().GetGenericArguments()) - { - args.Add(lGenericArgument.Name); - } - - String gArgs = String.Join(",", args); - - FriendlyName = $"{new String(Type.Name.TakeWhile(x => x != '`').ToArray())}<{gArgs}>"; - } - else - { - FriendlyName = Type.Name; - } + FriendlyName = Type.GetFriendlyName(); } private void InitTypeDefinition() @@ -133,6 +126,8 @@ namespace Tango.Scripting.Editors.Intellisense { if (!_initialized) { + _initialized = true; + XmlDocument xmlDoc = null; if (_assemblies_docs_cache.ContainsKey(Type.Assembly)) @@ -165,155 +160,157 @@ namespace Tango.Scripting.Editors.Intellisense if (xmlDoc != null) { - //Load Type Summary + Task.Factory.StartNew(() => { - string path = "T:" + Type.FullName; - XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); - if (xmlDocuOfType != null) + //Load Type Summary { - XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); - Summary = summaryNode.InnerText; - } - } + string path = "T:" + Type.FullName; + XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); - //Load Constructors... - { - string path = "M:" + Type.FullName + ".#ctor"; - - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); - var constructors = Type.GetConstructors().Where(x => x.IsPublic).ToList(); - - for (int i = 0; i < constructors.Count; i++) - { - var constructor = constructors[i]; - XmlNode cDoc = null; - - if (i < docNodes.Count) + if (xmlDocuOfType != null) { - cDoc = docNodes[i]; + XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); + Summary = summaryNode.InnerText; } + } - KnownTypeConstructor c = new KnownTypeConstructor(this); - c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerText : $"Initializes a new instance of {FriendlyName}."; + //Load Constructors... + { + string path = "M:" + Type.FullName + ".#ctor"; - var parameters = constructor.GetParameters().ToList(); - var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); + var constructors = Type.GetConstructors().Where(x => x.IsPublic).ToList(); - for (int j = 0; j < parameters.Count; j++) + for (int i = 0; i < constructors.Count; i++) { - var parameter = parameters[j]; - XmlNode pNode = null; + var constructor = constructors[i]; + XmlNode cDoc = null; - if (j < parametersNodes.Count) + if (i < docNodes.Count) { - pNode = parametersNodes[j]; + cDoc = docNodes[i]; } - KnownTypeMethodParameter p = new KnownTypeMethodParameter(); - p.Type = parameter.ParameterType; - p.Name = parameter.Name; - p.Description = pNode != null ? pNode.InnerText : null; + KnownTypeConstructor c = new KnownTypeConstructor(this); + c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerXml : $"Initializes a new instance of {FriendlyName}."; - if (j == parameters.Count - 1) + var parameters = constructor.GetParameters().ToList(); + var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); + + for (int j = 0; j < parameters.Count; j++) { - p.IsLast = true; - } + var parameter = parameters[j]; + XmlNode pNode = null; - c.Parameters.Add(p); - } + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } - _constructors.Add(c); - } - } + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType.GetFriendlyName(); + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; - //Load Methods... - { - string path = "M:" + Type.FullName; + if (j == parameters.Count - 1) + { + p.IsLast = true; + } - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); - var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); + c.Parameters.Add(p); + } - //TODO: Separate extension methods! - methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); + _constructors.Add(c); + } + } - for (int i = 0; i < methods.Count; i++) + //Load Methods... { - var method = methods[i]; - XmlNode mDoc = null; + string path = "M:" + Type.FullName; - mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); + var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); - KnownTypeMethod m = new KnownTypeMethod(this); - m.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerText : "No documentation"; - m.Name = method.Name; - m.ReturnType = method.ReturnType; - m.ReturnTypeFriendlyName = method.ReturnType.Name; + //TODO: Separate extension methods! + methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); - if (method.ReturnType.IsGenericType) + if (typeof(IEnumerable).IsAssignableFrom(Type)) { - List<String> args = new List<string>(); + var linqMethods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList(); + methods.AddRange(linqMethods); + } - foreach (var lGenericArgument in m.ReturnType.GetGenericTypeDefinition().GetGenericArguments()) - { - args.Add(lGenericArgument.Name); - } + for (int i = 0; i < methods.Count; i++) + { + var method = methods[i]; + XmlNode mDoc = null; - String gArgs = String.Join(",", args); + mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); - m.ReturnTypeFriendlyName = $"{new String(Type.Name.TakeWhile(x => x != '`').ToArray())}<{gArgs}>"; - } + KnownTypeMethod m = new KnownTypeMethod(this); + m.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + m.Name = method.Name; + m.ReturnType = method.ReturnType; + m.ReturnTypeFriendlyName = method.ReturnType.GetFriendlyName(); - var parameters = method.GetParameters().ToList(); - var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); + var parameters = method.GetParameters().ToList(); + var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); - for (int j = 0; j < parameters.Count; j++) - { - var parameter = parameters[j]; - XmlNode pNode = null; + bool isLinq = method.DeclaringType == typeof(Enumerable); - if (j < parametersNodes.Count) + for (int j = 0; j < parameters.Count; j++) { - pNode = parametersNodes[j]; - } + var parameter = parameters[j]; - KnownTypeMethodParameter p = new KnownTypeMethodParameter(); - p.Type = parameter.ParameterType; - p.Name = parameter.Name; - p.Description = pNode != null ? pNode.InnerText : null; + XmlNode pNode = null; - if (j == parameters.Count - 1) - { - p.IsLast = true; + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } + + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType.GetFriendlyName(); + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; + + if (j == parameters.Count - 1) + { + p.IsLast = true; + } + + if (j == 0 && isLinq) continue; + m.Parameters.Add(p); } - m.Parameters.Add(p); + _methods.Add(m); } - - _methods.Add(m); } - } - //Load Properties - { - string path = "P:" + Type.FullName; + //Load Properties + { + string path = "P:" + Type.FullName; - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); - var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); + var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); - for (int i = 0; i < properties.Count; i++) - { - var property = properties[i]; - var pDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(property.DeclaringType.Name + "." + property.Name)); + for (int i = 0; i < properties.Count; i++) + { + var property = properties[i]; + var pDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(property.DeclaringType.Name + "." + property.Name)); - KnownTypeProperty p = new KnownTypeProperty(this); - p.Summary = pDoc != null ? pDoc.SelectSingleNode("summary").InnerText : "No documentation"; - p.Name = property.Name; - p.ReturnType = property.PropertyType; + KnownTypeProperty p = new KnownTypeProperty(this); + p.Summary = pDoc != null ? pDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + p.Name = property.Name; + p.ReturnType = property.PropertyType; + p.ReturnTypeFriendlyName = property.PropertyType.GetFriendlyName(); - _properties.Add(p); + _properties.Add(p); + } } - } + + }); } _initialized = true; diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs index d3d8cb428..1405a8c34 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs @@ -10,6 +10,8 @@ namespace Tango.Scripting.Editors.Intellisense { public Type ReturnType { get; set; } + public String ReturnTypeFriendlyName { get; set; } + public KnownType Type { get; set; } public String Summary { get; set; } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs index 27b052978..0ae4b708e 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs @@ -8,8 +8,6 @@ namespace Tango.Scripting.Editors.Intellisense { public class KnownTypeMethod : KnownTypeMember { - public String ReturnTypeFriendlyName { get; set; } - public List<KnownTypeMethodParameter> Parameters { get; set; } public KnownTypeMethod() diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs index c4f2a62c5..59f6db4fd 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs @@ -8,7 +8,7 @@ namespace Tango.Scripting.Editors.Intellisense { public class KnownTypeMethodParameter { - public Type Type { get; set; } + public String Type { get; set; } public String Name { get; set; } public String Description { get; set; } public bool IsLast { get; set; } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItem.cs new file mode 100644 index 000000000..0a0883ede --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItem.cs @@ -0,0 +1,36 @@ +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 MethodCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("method.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new MethodCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Class { get; set; } + public String Name { get; set; } + public String ReturnType { get; set; } + + public int Overloads { get; set; } + + public bool HasOverloads + { + get { return Overloads > 0; } + } + + public List<KnownTypeMethodParameter> Parameters { get; set; } + + public MethodCompletionItem() + { + Parameters = new List<KnownTypeMethodParameter>(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs new file mode 100644 index 000000000..1b9717307 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class MethodCompletionItemPopup : CompletionItemPopupControl + { + static MethodCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MethodCompletionItemPopup), new FrameworkPropertyMetadata(typeof(MethodCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs new file mode 100644 index 000000000..d5c8db38a --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs @@ -0,0 +1,27 @@ +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 NamespaceCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("namespace.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new NamespaceCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Assembly { get; set; } + + public override void Complete(ScriptEditor editor) + { + var line = editor.GetCurrentLine(); + editor.Document.Replace(line, "using " + Name); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs new file mode 100644 index 000000000..7adc82fd8 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class NamespaceCompletionItemPopup : CompletionItemPopupControl + { + static NamespaceCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(NamespaceCompletionItemPopup), new FrameworkPropertyMetadata(typeof(NamespaceCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.cs new file mode 100644 index 000000000..c301e8ede --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.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 PropertyCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("property.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new PropertyCompletionItemPopup(); + 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/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs new file mode 100644 index 000000000..7790d6c43 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class PropertyCompletionItemPopup : CompletionItemPopupControl + { + static PropertyCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyCompletionItemPopup), new FrameworkPropertyMetadata(typeof(PropertyCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs new file mode 100644 index 000000000..b89a7cee2 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs @@ -0,0 +1,21 @@ +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 StructCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("struct.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new StructCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs new file mode 100644 index 000000000..09512f405 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class StructCompletionItemPopup : CompletionItemPopupControl + { + static StructCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(StructCompletionItemPopup), new FrameworkPropertyMetadata(typeof(StructCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs index 3370ca0ee..49d745d6c 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -69,320 +70,7 @@ namespace Tango.Scripting.Editors private class MethodSession { public KnownType Type { get; set; } - public int ParameterIndex { get; set; } - public List<String> TypeArguments { get; set; } - } - - #endregion - - #region Completion - - /// <summary> - /// Represents an auto complete item. - /// </summary> - /// <seealso cref="ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData" /> - internal class TypeCompletionData : DependencyObject, ICompletionData - { - private String _description; - - /// <summary> - /// Gets or sets the icon source. - /// </summary> - public BitmapSource Source { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="TypeCompletionData"/> class. - /// </summary> - /// <param name="name">The text.</param> - /// <param name="description">The description.</param> - public TypeCompletionData(String type, string name, String ns, String description) - { - - Type = type; - this.Text = name; - Namespace = ns; - _description = description; - } - - /// <summary> - /// Gets the image. - /// </summary> - public System.Windows.Media.ImageSource Image - { - get { return Source; } - } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - public string Text { get; private set; } - - // Use this property if you want to show a fancy UIElement in the drop down list. - public object Content - { - get { return this.Text; } - } - - /// <summary> - /// Gets the description. - /// </summary> - public object Description - { - get { return _description; } - } - - public String Type { get; set; } - - public String Namespace { get; set; } - - /// <summary> - /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items - /// which the user is accessing most frequently. - /// </summary> - public double Priority { get { return 0; } } - - /// <summary> - /// Perform the completion. - /// </summary> - /// <param name="textArea">The text area on which completion is performed.</param> - /// <param name="completionSegment">The text segment that was used by the completion window if - /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset).</param> - /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. - /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how - /// the insertion was triggered.</param> - public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) - { - textArea.Document.Replace(completionSegment, this.Text); - } - - public bool IsSelected - { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } - } - public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register("IsSelected", typeof(bool), typeof(TypeCompletionData), new PropertyMetadata(false, IsSelectedChanged)); - - private static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - Debug.WriteLine("Selected"); - } - - - - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Text; - } - } - - internal class MethodCompletionData : DependencyObject, ICompletionData - { - private String _description; - - /// <summary> - /// Gets or sets the icon source. - /// </summary> - public BitmapSource Source { get; set; } - - public String ReturnType { get; set; } - - public String Type { get; set; } - - public String Class { get; set; } - - public int Overloads { get; set; } - - public List<KnownTypeMethodParameter> Parameters { get; set; } - - public bool HasOverloads - { - get { return Overloads > 0; } - } - - public MethodCompletionData(String cls, string name, String returnType, String description, List<KnownTypeMethodParameter> parameters, int overloads) - { - Type = "method"; - Parameters = parameters; - Class = cls; - this.Text = name; - Overloads = overloads; - ReturnType = returnType; - _description = description; - } - - /// <summary> - /// Gets the image. - /// </summary> - public System.Windows.Media.ImageSource Image - { - get { return Source; } - } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - public string Text { get; private set; } - - // Use this property if you want to show a fancy UIElement in the drop down list. - public object Content - { - get { return this.Text; } - } - - /// <summary> - /// Gets the description. - /// </summary> - public object Description - { - get { return _description; } - } - - /// <summary> - /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items - /// which the user is accessing most frequently. - /// </summary> - public double Priority { get { return 0; } } - - /// <summary> - /// Perform the completion. - /// </summary> - /// <param name="textArea">The text area on which completion is performed.</param> - /// <param name="completionSegment">The text segment that was used by the completion window if - /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset).</param> - /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. - /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how - /// the insertion was triggered.</param> - public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) - { - textArea.Document.Replace(completionSegment, this.Text); - } - - public bool IsSelected - { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } - } - public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register("IsSelected", typeof(bool), typeof(MethodCompletionData), new PropertyMetadata(false, IsSelectedChanged)); - - private static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - Debug.WriteLine("Selected"); - } - - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Text; - } - } - - internal class PropertyCompletionData : DependencyObject, ICompletionData - { - private String _description; - - /// <summary> - /// Gets or sets the icon source. - /// </summary> - public BitmapSource Source { get; set; } - - public String ReturnType { get; set; } - - public String Type { get; set; } - - public String Class { get; set; } - - public PropertyCompletionData(String cls, string name, String returnType, String description) - { - Type = "property"; - Class = cls; - this.Text = name; - ReturnType = returnType; - _description = description; - } - - /// <summary> - /// Gets the image. - /// </summary> - public System.Windows.Media.ImageSource Image - { - get { return Source; } - } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - public string Text { get; private set; } - - // Use this property if you want to show a fancy UIElement in the drop down list. - public object Content - { - get { return this.Text; } - } - - /// <summary> - /// Gets the description. - /// </summary> - public object Description - { - get { return _description; } - } - - /// <summary> - /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items - /// which the user is accessing most frequently. - /// </summary> - public double Priority { get { return 0; } } - - /// <summary> - /// Perform the completion. - /// </summary> - /// <param name="textArea">The text area on which completion is performed.</param> - /// <param name="completionSegment">The text segment that was used by the completion window if - /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset).</param> - /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. - /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how - /// the insertion was triggered.</param> - public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) - { - textArea.Document.Replace(completionSegment, this.Text); - } - - public bool IsSelected - { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } - } - public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register("IsSelected", typeof(bool), typeof(PropertyCompletionData), new PropertyMetadata(false, IsSelectedChanged)); - - private static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - Debug.WriteLine("Selected"); - } - - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Text; - } + public String MethodName { get; set; } } #endregion @@ -700,76 +388,53 @@ namespace Tango.Scripting.Editors return null; } - //private MethodSession GetMethodSession() - //{ - // var lineText = GetCurrentLineText(); - // var expression = lineText.Split(' ').ToList().LastOrDefault(); - - // if (expression != null) - // { - - // } - - - // var expression = _parser.GetExpression<InvocationExpressionSyntax>(GetCurrentLineText()); - - // if (expression != null) - // { - // MethodSession session = new MethodSession(); + private MethodSession GetMethodSession() + { + var expression = GetPreviousWords().LastOrDefault(); - // var line = GetCurrentLine(); - // int parameterIndex = 0; - // for (int i = CaretOffset; i > line.Offset; i--) - // { - // String c = Document.GetText(i, 1); + if (expression != null) + { + var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "")).ToList(); + var variableName = tree.FirstOrDefault(); - // if (c == "(") - // { - // //var typeDeclaration = expression.Type as GenericNameSyntax; + if (variableName != null && tree.Count > 1) + { + tree.RemoveAt(0); + var variables = _parser.GetScriptVariables(Document.Text); + var variable = variables.FirstOrDefault(x => x.Name == variableName); - // //KnownType type = null; + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); - // //if (typeDeclaration != null) - // //{ - // // var typeName = typeDeclaration.Identifier.ToString(); - // // var argumentsCount = typeDeclaration.TypeArgumentList.Arguments.Count; - // // session.TypeArguments = typeDeclaration.TypeArgumentList.Arguments.Select(x => x.ToString()).ToList(); + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); - // // if (argumentsCount == 0) - // // { - // // type = _knownTypes.FirstOrDefault(x => x.Type.Name == expression.Type.ToString()); - // // } - // // else - // // { - // // type = _knownTypes.FirstOrDefault(x => x.Type.Name == typeName + "`" + argumentsCount); - // // } - // //} - // //else - // //{ - // // type = _knownTypes.FirstOrDefault(x => x.Name == expression.Type.ToString()); - // //} + if (member == null) + { + return null; + } - // //if (type != null) - // //{ - // // session.Type = type; - // // session.ParameterIndex = parameterIndex; - // // return session; - // //} - // //else - // //{ - // // return null; - // //} - // } - // else if (c == ",") - // { - // parameterIndex++; - // } + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } - // } - // } + return new MethodSession() + { + Type = knownType, + MethodName = tree.Last(), + }; + } + } + } + } - // return null; - //} + return null; + } public List<String> GetPreviousWords() { @@ -782,7 +447,7 @@ namespace Tango.Scripting.Editors #region Highlighting - private async void InvalidateHighlighting() + private void InvalidateHighlighting() { _parser.GetDeclaredTypes(Text); @@ -791,26 +456,29 @@ namespace Tango.Scripting.Editors var assemblies = ReferenceAssemblies.ToList(); var usings = _current_usings.ToList(); - foreach (var asm in assemblies.Select(x => x.Assembly)) + Thread t = new Thread(() => { - Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => + foreach (var asm in assemblies.Select(x => x.Assembly)) { - if (usings.Exists(x => type.Namespace == x)) + Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => { - lock (_knownTypes) + if (usings.Exists(x => type.Namespace == x)) { - _knownTypes.Add(new KnownType(type)); + lock (_knownTypes) + { + if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + { + _knownTypes.Add(new KnownType(type)); + } + } } - } - }); - } - - if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) - { - String text = String.Empty; + }); + } - await Task.Factory.StartNew(() => + if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) { + String text = String.Empty; + Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); using (StreamReader reader = new StreamReader(xshd_stream)) @@ -864,15 +532,22 @@ namespace Tango.Scripting.Editors { text = text.Replace("<Word>@InterfaceTypes@</Word>", String.Join(Environment.NewLine, interfaceTypes.Distinct())); } - }); - using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text))) - { + MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); + XmlTextReader xshd_reader = new XmlTextReader(ms); - SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); - xshd_reader.Close(); + + Dispatcher.BeginInvoke(new Action(() => + { + SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); + xshd_reader.Close(); + ms.Dispose(); + })); + } - } + }); + t.IsBackground = true; + t.Start(); } private void InvalidateScriptTypesHighlightings() @@ -1009,74 +684,75 @@ namespace Tango.Scripting.Editors var lineText = GetCurrentLineText(); var previousWordsLast = GetPreviousWords().LastOrDefault(); String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; + String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); + + + if (e.Text == " " && GetPreviousWord() == "new") + { + var s = _parser.GetExpression<FieldDeclarationSyntax>(GetCurrentLineText()); + + if (s != null) + { + String type = s.Declaration.Type.ToString(); + IList<ICompletionData> data = new List<ICompletionData>(); + + data.Add(new ClassCompletionItem() + { + Name = type, + Description = "Auto generate assignment...", + }); - if (e.Text == ";" || e.Text == " ") + ShowCompletionWindow(data, type); + } + } + else if (e.Text == ";" || e.Text == " ") { HideCompletionWindow(); } else if (e.Text == ".") { - var expression = GetPreviousWords().LastOrDefault(); + var knownType = GetCurrentKnownType(); - if (expression != null) + if (knownType != null) { - var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "")).ToList(); - var variableName = tree.FirstOrDefault(); + completionWindow.HideCompletion(); + IList<ICompletionData> data = new List<ICompletionData>(); - if (variableName != null) + var typeMembers = knownType.Members.ToList(); + + foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) { - tree.RemoveAt(0); - var variables = _parser.GetScriptVariables(Document.Text); - var variable = variables.FirstOrDefault(x => x.Name == variableName); + var member = methodGroup.First(); - if (variable != null) + if (member.GetType() == typeof(KnownTypeMethod)) { - var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == variable.Type); + var method = member as KnownTypeMethod; - if (knownType != null) + data.Add(new MethodCompletionItem() { - while (tree.Count > 1) - { - var memberName = tree.First(); - tree.RemoveAt(0); - var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + Class = knownType.FriendlyName, + Name = method.Name, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); - if (member == null) - { - return; - } - - knownType = _knownTypes.FirstOrDefault(x => x.Type == member.ReturnType); - } - - if (knownType != null) - { - completionWindow.HideCompletion(); - IList<ICompletionData> data = new List<ICompletionData>(); - - var typeMembers = knownType.Members.ToList(); - - foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) - { - var member = methodGroup.First(); - - if (member.GetType() == typeof(KnownTypeMethod)) - { - var method = member as KnownTypeMethod; - data.Add(new MethodCompletionData(knownType.FriendlyName, method.Name, method.ReturnTypeFriendlyName, method.Summary, method.Parameters, methodGroup.Count() - 1)); - } - else - { - data.Add(new PropertyCompletionData(knownType.FriendlyName, member.Name, member.ReturnType.Name, member.Summary)); - } - } - - ShowCompletionWindow(data, GetCurrentWord()); - } - } + } + else + { + data.Add(new PropertyCompletionItem() + { + Class = knownType.FriendlyName, + Name = member.Name, + Type = member.ReturnTypeFriendlyName, + Description = member.Summary, + }); } } + + ShowCompletionWindow(data, GetCurrentWord()); } } else if (e.Text == "(" || e.Text == ",") @@ -1094,29 +770,53 @@ namespace Tango.Scripting.Editors } } - //var methodSession = GetMethodSession(); + var methodSession = GetMethodSession(); - //if (methodSession != null) - //{ + if (methodSession != null) + { + var content = CreateMethodSessionPopupContent(methodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + } + } - //} + var a = GetMethodSession(); } else if (lineText.StartsWith("using")) { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } + IList<ICompletionData> data = new List<ICompletionData>(); foreach (var asm in ReferenceAssemblies) { foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) { - data.Add(new TypeCompletionData("namespace", ns, "", asm.Assembly.GetName().Name)); + data.Add(new NamespaceCompletionItem() + { + Name = ns, + Assembly = asm.Assembly.GetName().Name, + }); } } + data = data.DistinctBy(x => x.Text).ToList(); + ShowCompletionWindow(data, GetCurrentWord()); } - else if (!currentWord.Contains(".")) + else if (!currentWordIncludingParenthesis.Contains(".")) { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } + var previous_word = GetPreviousWord(); var word = GetCurrentWord(); @@ -1141,12 +841,90 @@ namespace Tango.Scripting.Editors foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) { - data.Add(new TypeCompletionData(type.TypeKind.ToString().ToLower(), type.Name, type.ContainingNamespace?.Name, "Declared inside the current script...")); + if (type.TypeKind == TypeKind.Struct) + { + data.Add(new StructCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Enum) + { + data.Add(new EnumCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Interface) + { + data.Add(new InterfaceCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Class) + { + data.Add(new ClassCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else + { + throw new NotImplementedException("Implement generic item here!"); + } } foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) { - data.Add(new TypeCompletionData(type.TypeDefinition, type.FriendlyName, type.Type.Namespace, type.Summary)); + if (type.Type.IsEnum) + { + data.Add(new EnumCompletionItem() + { + Namespace = type.Type.Namespace, + Description = type.Summary, + Name = type.FriendlyName, + }); + } + else if (type.Type.IsInterface) + { + data.Add(new InterfaceCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else if (type.Type.IsValueType) + { + data.Add(new StructCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else if (type.Type.IsClass) + { + data.Add(new ClassCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else + { + throw new NotImplementedException("Implement generic item here."); + } } ShowCompletionWindow(data, word); @@ -1157,10 +935,7 @@ namespace Tango.Scripting.Editors private void CompletionWindow_InsertionRequest(ICompletionData item) { - int index = GetCurrentWordStartIndex(); - int max = GetCurrentLine().EndOffset; - - Document.Replace(index, Math.Min(max - index, item.Text.Length), item.Text); + item.Complete(this); } private void ShowCompletionWindow(IList<ICompletionData> suggestions, String filter) @@ -1240,6 +1015,50 @@ namespace Tango.Scripting.Editors return list; } + private KnownType GetCurrentKnownType() + { + var expression = GetPreviousWords().LastOrDefault(); + + if (expression != null) + { + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + var variableName = tree.FirstOrDefault(); + + if (variableName != null) + { + tree.RemoveAt(0); + var variables = _parser.GetScriptVariables(Document.Text); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); + + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } + + return knownType; + } + } + } + } + + return null; + } + #endregion #region Popup @@ -1290,7 +1109,7 @@ namespace Tango.Scripting.Editors { ParameterDescription pDescription = new ParameterDescription(method); pDescription.Name = p.Name; - pDescription.Type = p.Type.Name; + pDescription.Type = p.Type; pDescription.Description = p.Description; method.Parameters.Add(pDescription); } @@ -1320,6 +1139,57 @@ namespace Tango.Scripting.Editors return popup; } + private MethodPopup CreateMethodSessionPopupContent(MethodSession session) + { + MethodPopup popup = new MethodPopup(); + + foreach (var m in session.Type.Methods.Where(x => x.Name == session.MethodName)) + { + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Type.Name; + method.Description = m.Summary; + + //if (session.Type.Type.IsGenericType && session.TypeArguments != null) + //{ + // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; + //} + + var parameters = m.Parameters; + + foreach (var p in parameters) + { + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Name = p.Name; + pDescription.Type = p.Type; + pDescription.Description = p.Description; + method.Parameters.Add(pDescription); + } + + popup.Methods.Add(method); + } + + //if (false) + //{ + // popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1); + + // if (popup.CurrentMethod == null) + // { + // popup.CurrentMethod = popup.Methods.FirstOrDefault(); + // } + //} + //else + //{ + popup.CurrentMethod = popup.Methods.FirstOrDefault(); + //} + + if (popup.CurrentMethod != null) + { + popup.CurrentMethodIndex = popup.Methods.IndexOf(popup.CurrentMethod) + 1; + } + + return popup; + } + #endregion } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj index d7c455704..5422ba805 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj @@ -191,6 +191,16 @@ <Compile Include="CodeCompletion\OverloadViewer.cs" /> <Compile Include="Converters\BooleanToVisibilityConverter.cs" /> <Compile Include="Converters\BooleanToVisibilityInversedConverter.cs" /> + <Compile Include="ExtensionMethods.cs" /> + <Compile Include="Intellisense\ClassCompletionItemPopup.cs" /> + <Compile Include="Intellisense\CompletionItem.cs" /> + <Compile Include="Intellisense\CompletionItemPopupControl.cs" /> + <Compile Include="Intellisense\EnumCompletionItem.cs" /> + <Compile Include="Intellisense\EnumCompletionItemPopup.cs" /> + <Compile Include="Intellisense\ICompletionItem.cs" /> + <Compile Include="Intellisense\ICompletionProvider.cs" /> + <Compile Include="Intellisense\InterfaceCompletionItem.cs" /> + <Compile Include="Intellisense\InterfaceCompletionItemPopup.cs" /> <Compile Include="Intellisense\KnownType.cs" /> <Compile Include="Document\ChangeTrackingCheckpoint.cs" /> <Compile Include="Document\DocumentChangeOperation.cs"> @@ -328,6 +338,15 @@ <Compile Include="Intellisense\KnownTypeMethodParameter.cs" /> <Compile Include="Intellisense\KnownTypeMethod.cs" /> <Compile Include="Intellisense\KnownTypeProperty.cs" /> + <Compile Include="Intellisense\ClassCompletionItem.cs" /> + <Compile Include="Intellisense\MethodCompletionItem.cs" /> + <Compile Include="Intellisense\MethodCompletionItemPopup.cs" /> + <Compile Include="Intellisense\NamespaceCompletionItem.cs" /> + <Compile Include="Intellisense\NamespaceCompletionItemPopup.cs" /> + <Compile Include="Intellisense\PropertyCompletionItem.cs" /> + <Compile Include="Intellisense\PropertyCompletionItemPopup.cs" /> + <Compile Include="Intellisense\StructCompletionItem.cs" /> + <Compile Include="Intellisense\StructCompletionItemPopup.cs" /> <Compile Include="Popups\MethodDescription.cs" /> <Compile Include="Popups\MethodPopup.cs" /> <Compile Include="Popups\ParameterDescription.cs" /> diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml index 8b60d42a7..7a6588239 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml @@ -5,6 +5,7 @@ xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:editing="clr-namespace:Tango.Scripting.Editors.Editing" xmlns:folding="clr-namespace:Tango.Scripting.Editors.Folding" + xmlns:intellisense="clr-namespace:Tango.Scripting.Editors.Intellisense" xmlns:converters="clr-namespace:Tango.Scripting.Editors.Converters" xmlns:completion="clr-namespace:Tango.Scripting.Editors.CodeCompletion"> @@ -25,6 +26,7 @@ <Color x:Key="ScriptLineNumberForeground">#2B91AF</Color> <Color x:Key="ScriptReferenceTypesColor">#4EC9B0</Color> <Color x:Key="ScriptKeywordColor">#3F8FD6</Color> + <Color x:Key="ScriptInterfaceColor">#B5CE8A</Color> <!--Brushes--> <SolidColorBrush x:Key="ScriptBackgroundBrush" Color="{StaticResource ScriptBackground}"></SolidColorBrush> @@ -35,6 +37,7 @@ <SolidColorBrush x:Key="CompletionToolTipBackgroundBrush" Color="{StaticResource CompletionToolTipBackground}"></SolidColorBrush> <SolidColorBrush x:Key="ScriptReferenceTypesBrush" Color="{StaticResource ScriptReferenceTypesColor}"></SolidColorBrush> <SolidColorBrush x:Key="ScriptKeywordBrush" Color="{StaticResource ScriptKeywordColor}"></SolidColorBrush> + <SolidColorBrush x:Key="ScriptInterfaceBrush" Color="{StaticResource ScriptInterfaceColor}"></SolidColorBrush> <!--Images--> <BitmapImage x:Key="interface" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/interface.png" /> @@ -80,37 +83,17 @@ <Setter.Value> <DataTemplate> <Border Background="{StaticResource CompletionToolTipBackgroundBrush}" CornerRadius="3" BorderThickness="0.5" BorderBrush="#434343" Padding="10 5" TextElement.Foreground="{StaticResource ScriptForegroundBrush}" TextElement.FontSize="12"> - <ContentControl Content="{Binding}"> + <!--<ContentControl Content="{Binding}"> <ContentControl.Style> <Style TargetType="ContentControl"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> - <TextBlock TextWrapping="Wrap"> - <Run Text="{Binding Type,Mode=OneWay}" Foreground="#3F8FD6"></Run> - <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Text,Mode=OneWay}" Foreground="#4EC9B0"></Run> - <LineBreak/> - <Run Text="{Binding Description,Mode=OneWay}"></Run> - </TextBlock> + <ContentPresenter Content="{Binding PopupControl}" /> </DataTemplate> </Setter.Value> </Setter> <Style.Triggers> - <DataTrigger Binding="{Binding Type}" Value="namespace"> - <Setter Property="ContentTemplate"> - <Setter.Value> - <DataTemplate> - <TextBlock TextWrapping="Wrap"> - <Run Text="{Binding Type,Mode=OneWay}" Foreground="#3F8FD6"></Run> - <Run Text="{Binding Text,Mode=OneWay}"></Run> - <LineBreak/> - <Run Text="{Binding Description,Mode=OneWay}"></Run> - </TextBlock> - </DataTemplate> - </Setter.Value> - </Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="method"> <Setter Property="ContentTemplate"> <Setter.Value> @@ -181,7 +164,15 @@ </Style.Triggers> </Style> </ContentControl.Style> - </ContentControl> + + <ContentControl.ContentTemplate> + <DataTemplate> + <ContentPresenter Content="{Binding PopupControl}" /> + </DataTemplate> + </ContentControl.ContentTemplate> + </ContentControl>--> + + <ContentPresenter DataContext="{Binding}" Content="{Binding PopupControl}" /> </Border> </DataTemplate> </Setter.Value> @@ -205,36 +196,8 @@ <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> - <Image Width="16" Height="16" Margin="0,0,4,0"> - <Image.Style> - <Style TargetType="Image"> - <Style.Triggers> - <DataTrigger Binding="{Binding Type}" Value="interface"> - <Setter Property="Source" Value="{StaticResource interface}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="class"> - <Setter Property="Source" Value="{StaticResource class}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="enum"> - <Setter Property="Source" Value="{StaticResource enum}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="struct"> - <Setter Property="Source" Value="{StaticResource struct}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="namespace"> - <Setter Property="Source" Value="{StaticResource namespace}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="method"> - <Setter Property="Source" Value="{StaticResource method}"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding Type}" Value="property"> - <Setter Property="Source" Value="{StaticResource property}"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </Image.Style> - </Image> - <ContentControl Content="{Binding Content}" /> + <Image Width="16" Height="16" Margin="0,0,4,0" Source="{Binding Image}"></Image> + <ContentControl Content="{Binding}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> @@ -388,4 +351,184 @@ </Setter.Value> </Setter> </Style> + + <!--Completion Items--> + + <Style TargetType="{x:Type intellisense:ClassCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:ClassCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + <TextBlock TextWrapping="Wrap"> + <Run Text="class" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:EnumCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:EnumCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + <TextBlock TextWrapping="Wrap"> + <Run Text="enum" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Text,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:MethodCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:MethodCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Name}"></TextBlock> + <TextBlock>(</TextBlock> + <ItemsControl ItemsSource="{Binding Parameters}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <StackPanel Orientation="Horizontal"></StackPanel> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Name}"></TextBlock> + <TextBlock Margin="0 0 5 0" Text="," Visibility="{Binding IsLast,Converter={StaticResource BooleanToVisibilityInversedConverter}}"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <TextBlock>)</TextBlock> + + <StackPanel Margin="5 0 0 0" Orientation="Horizontal" Visibility="{Binding HasOverloads,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock>(+</TextBlock> + <TextBlock Margin="2 0" Text="{Binding Overloads}"></TextBlock> + <TextBlock>overloads)</TextBlock> + </StackPanel> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:InterfaceCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:InterfaceCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="interface" Foreground="#3F8FD6"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:NamespaceCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:NamespaceCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="namespace" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Name,Mode=OneWay}"></Run> + </TextBlock> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:PropertyCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:PropertyCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Text}"></TextBlock> + <TextBlock Margin="5 0 0 0"> + <Run>{</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">get</Run><Run>;</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">set</Run><Run>;</Run> + <Run>}</Run> + </TextBlock> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:StructCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:StructCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="struct" Foreground="#3F8FD6"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> </ResourceDictionary> diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs index 7bbc029d6..5564296e8 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs @@ -85,9 +85,9 @@ namespace Tango.Scripting.Parsing public List<String> GetUsings(String code) { - Regex r = new Regex("(using [^;]+;)"); + Regex r = new Regex("(using [^;^\n]+;)"); var matches = r.Matches(code); - return matches.OfType<Match>().Select(x => x.Value.Replace("using ", "").Replace(";", "")).ToList(); + return matches.OfType<Match>().Select(x => x.Value.Replace("using ", "").Replace(";", "").Replace("\n", "").Replace("\t", "").Replace("\r", "")).ToList(); } public List<INamedTypeSymbol> GetDeclaredTypes(String code) @@ -118,7 +118,7 @@ namespace Tango.Scripting.Parsing return root.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().FirstOrDefault(); } - public T GetExpression<T>(String line) where T : ExpressionSyntax + public T GetExpression<T>(String line) where T : CSharpSyntaxNode { SyntaxTree tree = CSharpSyntaxTree.ParseText(line); CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); |
