From cbdd79778764ce38017790e1e1f9316e52ec8104 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 10 Mar 2019 09:05:11 +0200 Subject: Working on new scripting editor. --- .../CodeCompletion/CompletionListBoxItem.cs | 14 +- .../CodeCompletion/CompletionWindow.cs | 2 + .../CodeCompletion/CompletionWindowBase.cs | 5 +- .../Converters/BooleanToVisibilityConverter.cs | 24 + .../BooleanToVisibilityInversedConverter.cs | 24 + .../Tango.Scripting.Editors/Editing/Caret.cs | 2 +- .../Highlighting/Resources/CSharp-Mode.xshd | 1 + .../Tango.Scripting.Editors/Images/class.png | Bin 0 -> 212 bytes .../Tango.Scripting.Editors/Images/enum.png | Bin 0 -> 190 bytes .../Tango.Scripting.Editors/Images/interface.png | Bin 0 -> 222 bytes .../Tango.Scripting.Editors/Images/method.png | Bin 0 -> 276 bytes .../Tango.Scripting.Editors/Images/namespace.png | Bin 0 -> 250 bytes .../Tango.Scripting.Editors/Images/property.png | Bin 0 -> 316 bytes .../Tango.Scripting.Editors/Images/pubclass.gif | Bin 290 -> 0 bytes .../Tango.Scripting.Editors/Images/pubevent.gif | Bin 365 -> 0 bytes .../Tango.Scripting.Editors/Images/pubmethod.gif | Bin 599 -> 0 bytes .../Tango.Scripting.Editors/Images/pubproperty.gif | Bin 435 -> 0 bytes .../Tango.Scripting.Editors/Images/struct.png | Bin 0 -> 136 bytes .../Intellisense/KnownType.cs | 323 ++++++++++ .../Intellisense/KnownTypeConstructor.cs | 27 + .../Intellisense/KnownTypeMember.cs | 29 + .../Intellisense/KnownTypeMethod.cs | 25 + .../Intellisense/KnownTypeMethodParameter.cs | 16 + .../Intellisense/KnownTypeProperty.cs | 21 + .../Popups/MethodDescription.cs | 20 + .../Tango.Scripting.Editors/Popups/MethodPopup.cs | 82 +++ .../Popups/ParameterDescription.cs | 26 + .../Tango.Scripting.Editors/Rendering/TextView.cs | 22 +- .../Tango.Scripting.Editors/ScriptEditor.cs | 717 ++++++++++++++++++--- .../Tango.Scripting.Editors.csproj | 40 +- .../Tango.Scripting.Editors/Themes/Generic.xaml | 248 ++++++- 31 files changed, 1542 insertions(+), 126 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityConverter.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityInversedConverter.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/enum.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/method.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubclass.gif delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubevent.gif delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubmethod.gif delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubproperty.gif create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/struct.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodPopup.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/ParameterDescription.cs (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs index bb6acf69e..55d752bfd 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs @@ -42,11 +42,15 @@ namespace Tango.Scripting.Editors.CodeCompletion protected override void OnSelected(RoutedEventArgs e) { - base.OnSelected(e); - toolTip.Content = DataContext; - toolTip.ContentTemplate = ToolTipContentTemplate; - toolTip.StaysOpen = true; - toolTip.IsOpen = true; + try + { + base.OnSelected(e); + toolTip.Content = DataContext; + toolTip.ContentTemplate = ToolTipContentTemplate; + toolTip.StaysOpen = true; + toolTip.IsOpen = true; + } + catch { } } protected override void OnUnselected(RoutedEventArgs e) diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs index 0e8cd781d..33759e351 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs @@ -84,6 +84,8 @@ namespace Tango.Scripting.Editors.CodeCompletion { InsertionRequest?.Invoke(item); } + + completionList.SelectedItem = null; } void AttachEvents() 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 b5bab3f97..e33ede203 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 @@ -79,6 +79,7 @@ namespace Tango.Scripting.Editors.CodeCompletion public virtual void HideCompletion() { + Debug.WriteLine("Hide Completion..."); DetachEvents(); Hide(); } @@ -148,7 +149,7 @@ namespace Tango.Scripting.Editors.CodeCompletion public override void Detach() { base.Detach(); - window.HideCompletion(); + //window.HideCompletion(); } const Key KeyDeadCharProcessed = (Key)0xac; // Key.DeadCharProcessed; // new in .NET 4 @@ -367,6 +368,8 @@ namespace Tango.Scripting.Editors.CodeCompletion bounds = bounds.TransformFromDevice(textView); this.Left = bounds.X; this.Top = bounds.Y; + + Debug.WriteLine($"Position: {Left}x{Top}"); } /// diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityConverter.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityConverter.cs new file mode 100644 index 000000000..7412e4a67 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityConverter.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Tango.Scripting.Editors.Converters +{ + public class BooleanToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return (bool)value ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityInversedConverter.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityInversedConverter.cs new file mode 100644 index 000000000..c91aa45fd --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Converters/BooleanToVisibilityInversedConverter.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Tango.Scripting.Editors.Converters +{ + public class BooleanToVisibilityInversedConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return (bool)value ? Visibility.Collapsed : Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Editing/Caret.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Editing/Caret.cs index 23542cd21..fb21448e5 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Editing/Caret.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Editing/Caret.cs @@ -267,7 +267,7 @@ namespace Tango.Scripting.Editors.Editing if (!visualColumnValid) { TextDocument document = textArea.Document; if (document != null) { - Debug.WriteLine("Explicit validation of caret column"); + //Debug.WriteLine("Explicit validation of caret column"); var documentLine = document.GetLineByNumber(position.Line); RevalidateVisualColumn(textView.GetOrConstructVisualLine(documentLine)); } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd index a8ca62be2..1ba2cbc6f 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd @@ -220,6 +220,7 @@ uint ushort ulong + null diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png new file mode 100644 index 000000000..91b35a829 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/enum.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/enum.png new file mode 100644 index 000000000..b79aa844f Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/enum.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png new file mode 100644 index 000000000..3b07597dd Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/method.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/method.png new file mode 100644 index 000000000..249689941 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/method.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png new file mode 100644 index 000000000..7f2b6b5ef Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png new file mode 100644 index 000000000..001a8c66a Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubclass.gif b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubclass.gif deleted file mode 100644 index 28abc36a7..000000000 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubclass.gif and /dev/null differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubevent.gif b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubevent.gif deleted file mode 100644 index 7c2466f0e..000000000 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubevent.gif and /dev/null differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubmethod.gif b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubmethod.gif deleted file mode 100644 index 040280d15..000000000 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubmethod.gif and /dev/null differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubproperty.gif b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubproperty.gif deleted file mode 100644 index 49d5042b9..000000000 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubproperty.gif and /dev/null differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/struct.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/struct.png new file mode 100644 index 000000000..02fbdbde7 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/struct.png differ 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 new file mode 100644 index 000000000..3cb61b991 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -0,0 +1,323 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownType + { + private static String dotNetXmlFolder = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.X"; + private static Dictionary _assemblies_docs_cache; + + private bool _initialized; + + public Type Type { get; private set; } + public String Name { get; private set; } + public String TypeDefinition { get; private set; } + public String FriendlyName { get; private set; } + + private String _summary; + public String Summary + { + get + { + InitTypeDocumentation(); + return _summary; + } + private set { _summary = value; } + } + + + private List _constructors; + public List Constructors + { + get + { + InitTypeDocumentation(); + return _constructors; + } + private set { _constructors = value; } + } + + private List _methods; + public List Methods + { + get + { + InitTypeDocumentation(); + return _methods; + } + private set { _methods = value; } + } + + private List _properties; + public List Properties + { + get + { + InitTypeDocumentation(); + return _properties; + } + private set { _properties = value; } + } + + public List Members + { + get + { + List members = new List(); + + members.AddRange(Properties); + members.AddRange(Methods); + + return members.OrderBy(x => x.Name).ToList(); + } + } + + static KnownType() + { + _assemblies_docs_cache = new Dictionary(); + } + + public KnownType(Type type) + { + _constructors = new List(); + _methods = new List(); + _properties = new List(); + Type = type; + Name = type.Name; + Init(); + } + + private void Init() + { + InitTypeDefinition(); + InitFriendlyName(); + } + + private void InitFriendlyName() + { + if (Type.IsGenericType) + { + List args = new List(); + + 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; + } + } + + private void InitTypeDefinition() + { + if (Type.IsClass) TypeDefinition = "class"; + else if (Type.IsEnum) TypeDefinition = "enum"; + else if (Type.IsInterface) TypeDefinition = "interface"; + else if (Type.IsValueType) TypeDefinition = "struct"; + } + + private void InitTypeDocumentation() + { + if (!_initialized) + { + XmlDocument xmlDoc = null; + + if (_assemblies_docs_cache.ContainsKey(Type.Assembly)) + { + xmlDoc = _assemblies_docs_cache[Type.Assembly]; + } + + if (xmlDoc == null) + { + String dllPath = Type.Assembly.Location; + + string docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML"; + + if (File.Exists(docuPath)) + { + xmlDoc = new XmlDocument(); + xmlDoc.Load(docuPath); + } + else if (File.Exists(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath)))) + { + xmlDoc = new XmlDocument(); + xmlDoc.Load(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath))); + } + + if (xmlDoc != null) + { + _assemblies_docs_cache.Add(Type.Assembly, xmlDoc); + } + } + + if (xmlDoc != null) + { + //Load Type Summary + { + string path = "T:" + Type.FullName; + XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); + + if (xmlDocuOfType != null) + { + XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); + Summary = summaryNode.InnerText; + } + } + + //Load Constructors... + { + string path = "M:" + Type.FullName + ".#ctor"; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().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) + { + cDoc = docNodes[i]; + } + + KnownTypeConstructor c = new KnownTypeConstructor(this); + c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerText : $"Initializes a new instance of {FriendlyName}."; + + var parameters = constructor.GetParameters().ToList(); + var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType().ToList() : new List(); + + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; + XmlNode pNode = null; + + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } + + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType; + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; + + if (j == parameters.Count - 1) + { + p.IsLast = true; + } + + c.Parameters.Add(p); + } + + _constructors.Add(c); + } + } + + //Load Methods... + { + string path = "M:" + Type.FullName; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); + + //TODO: Separate extension methods! + methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); + + for (int i = 0; i < methods.Count; i++) + { + var method = methods[i]; + XmlNode mDoc = null; + + mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); + + 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; + + if (method.ReturnType.IsGenericType) + { + List args = new List(); + + foreach (var lGenericArgument in m.ReturnType.GetGenericTypeDefinition().GetGenericArguments()) + { + args.Add(lGenericArgument.Name); + } + + String gArgs = String.Join(",", args); + + m.ReturnTypeFriendlyName = $"{new String(Type.Name.TakeWhile(x => x != '`').ToArray())}<{gArgs}>"; + } + + var parameters = method.GetParameters().ToList(); + var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); + + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; + XmlNode pNode = null; + + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } + + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType; + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; + + if (j == parameters.Count - 1) + { + p.IsLast = true; + } + + m.Parameters.Add(p); + } + + _methods.Add(m); + } + } + + //Load Properties + { + string path = "P:" + Type.FullName; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().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)); + + KnownTypeProperty p = new KnownTypeProperty(this); + p.Summary = pDoc != null ? pDoc.SelectSingleNode("summary").InnerText : "No documentation"; + p.Name = property.Name; + p.ReturnType = property.PropertyType; + + _properties.Add(p); + } + } + } + + _initialized = true; + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs new file mode 100644 index 000000000..273d61084 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownTypeConstructor + { + public KnownType Type { get; set; } + + public String Summary { get; set; } + + public List Parameters { get; set; } + + public KnownTypeConstructor() + { + Parameters = new List(); + } + + public KnownTypeConstructor(KnownType knownType) : this() + { + Type = knownType; + } + } +} 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 new file mode 100644 index 000000000..d3d8cb428 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public abstract class KnownTypeMember + { + public Type ReturnType { get; set; } + + public KnownType Type { get; set; } + + public String Summary { get; set; } + + public String Name { get; set; } + + public KnownTypeMember() + { + + } + + public KnownTypeMember(KnownType knownType) : this() + { + Type = knownType; + } + } +} 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 new file mode 100644 index 000000000..27b052978 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownTypeMethod : KnownTypeMember + { + public String ReturnTypeFriendlyName { get; set; } + + public List Parameters { get; set; } + + public KnownTypeMethod() + { + Parameters = new List(); + } + + public KnownTypeMethod(KnownType knownType) : this() + { + Type = knownType; + } + } +} 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 new file mode 100644 index 000000000..c4f2a62c5 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethodParameter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownTypeMethodParameter + { + public Type 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/KnownTypeProperty.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs new file mode 100644 index 000000000..a77dd7dc2 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.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 KnownTypeProperty : KnownTypeMember + { + public KnownTypeProperty() + { + + } + + public KnownTypeProperty(KnownType knownType) : this() + { + Type = knownType; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs new file mode 100644 index 000000000..864072952 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Popups +{ + public class MethodDescription + { + public String Description { get; set; } + public String ReturnType { get; set; } + public List Parameters { get; set; } + + public MethodDescription() + { + Parameters = new List(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodPopup.cs new file mode 100644 index 000000000..7c431f9b4 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodPopup.cs @@ -0,0 +1,82 @@ +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.Popups +{ + public class MethodPopup : Control + { + public List Methods { get; set; } + + public int CurrentMethodIndex + { + get { return (int)GetValue(CurrentMethodIndexProperty); } + set { SetValue(CurrentMethodIndexProperty, value); } + } + public static readonly DependencyProperty CurrentMethodIndexProperty = + DependencyProperty.Register("CurrentMethodIndex", typeof(int), typeof(MethodPopup), new PropertyMetadata(1)); + + public MethodDescription CurrentMethod + { + get { return (MethodDescription)GetValue(CurrentMethodProperty); } + set { SetValue(CurrentMethodProperty, value); } + } + public static readonly DependencyProperty CurrentMethodProperty = + DependencyProperty.Register("CurrentMethod", typeof(MethodDescription), typeof(MethodPopup), new PropertyMetadata(null)); + + public void IncrementMethod() + { + if (Methods.Count > 0) + { + if (CurrentMethodIndex < Methods.Count) + { + CurrentMethodIndex++; + CurrentMethod = Methods[CurrentMethodIndex - 1]; + } + else + { + CurrentMethodIndex = 1; + CurrentMethod = Methods[0]; + } + } + } + + public void DecrementMethod() + { + if (Methods.Count > 0) + { + if (CurrentMethodIndex > 1) + { + CurrentMethodIndex--; + CurrentMethod = Methods[CurrentMethodIndex - 1]; + } + else + { + CurrentMethodIndex = Methods.Count; + CurrentMethod = Methods[Methods.Count - 1]; + } + } + } + + public MethodPopup() + { + Methods = new List(); + } + + static MethodPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MethodPopup), new FrameworkPropertyMetadata(typeof(MethodPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/ParameterDescription.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/ParameterDescription.cs new file mode 100644 index 000000000..6650f76ec --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/ParameterDescription.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Popups +{ + public class ParameterDescription + { + public ParameterDescription(MethodDescription method) + { + Method = method; + } + + public MethodDescription Method { get; set; } + public String Type { get; set; } + public String Name { get; set; } + public String Description { get; set; } + + public bool IsLast + { + get { return Method.Parameters.Last() == this; } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Rendering/TextView.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Rendering/TextView.cs index 6bbf13618..3dabb6b7a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Rendering/TextView.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Rendering/TextView.cs @@ -800,9 +800,14 @@ namespace Tango.Scripting.Editors.Rendering [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] public ReadOnlyCollection VisualLines { get { - if (visibleVisualLines == null) - throw new VisualLinesInvalidException(); - return visibleVisualLines; + if (visibleVisualLines == null) + { + return new ReadOnlyCollection(new List()); + } + else + { + return visibleVisualLines; + } } } @@ -848,11 +853,12 @@ namespace Tango.Scripting.Editors.Rendering // Sometimes we still have invalid lines after UpdateLayout - work around the problem // by calling MeasureOverride directly. if (!VisualLinesValid) { - Debug.WriteLine("UpdateLayout() failed in EnsureVisualLines"); - MeasureOverride(lastAvailableSize); - } - if (!VisualLinesValid) - throw new VisualLinesInvalidException("Internal error: visual lines invalid after EnsureVisualLines call"); + //Debug.WriteLine("UpdateLayout() failed in EnsureVisualLines"); + //MeasureOverride(lastAvailableSize); + // UpdateLayout(); + } + //if (!VisualLinesValid) + //throw new VisualLinesInvalidException("Internal error: visual lines invalid after EnsureVisualLines call"); } #endregion 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 316b95ed7..3370ca0ee 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 @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -11,6 +12,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; @@ -27,6 +29,9 @@ using Tango.Scripting.Editors.Editing; using Tango.Scripting.Editors.Folding; using Tango.Scripting.Editors.Highlighting; using Tango.Scripting.Editors.Highlighting.Xshd; +using Tango.Scripting.Editors.Intellisense; +using Tango.Scripting.Editors.Popups; +using Tango.Scripting.Editors.Rendering; using Tango.Scripting.Parsing; namespace Tango.Scripting.Editors @@ -35,18 +40,16 @@ namespace Tango.Scripting.Editors { private char[] word_separators = { ' ', '\t', '\n', '.', '(', ',', '-', '*', '/', '+', '$', '=' }; private string[] _blocking_type_words = { "class", "void" }; - private String dotNetXmlFolder = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.X"; private DispatcherTimer _update_timer; + private Popup _popup; private FoldingManager foldingManager; private BraceFoldingStrategy foldingStrategy; private CompletionWindow completionWindow; private ScriptParser _parser; private List _current_usings; - private List _knownTypes; + private List _knownTypes; private List _declaredTypes; - private Dictionary _known_types_docs_cache; - private Dictionary _assemblies_docs_cache; #region Mini Classes @@ -56,6 +59,20 @@ namespace Tango.Scripting.Editors public int Index { get; set; } } + private class ConstructionSession + { + public KnownType Type { get; set; } + public int ParameterIndex { get; set; } + public List TypeArguments { get; set; } + } + + private class MethodSession + { + public KnownType Type { get; set; } + public int ParameterIndex { get; set; } + public List TypeArguments { get; set; } + } + #endregion #region Completion @@ -64,7 +81,7 @@ namespace Tango.Scripting.Editors /// Represents an auto complete item. /// /// - internal class CompletionData : DependencyObject, ICompletionData + internal class TypeCompletionData : DependencyObject, ICompletionData { private String _description; @@ -74,12 +91,13 @@ namespace Tango.Scripting.Editors public BitmapSource Source { get; set; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The text. /// The description. - public CompletionData(String type, string name, String ns, String description) + public TypeCompletionData(String type, string name, String ns, String description) { + Type = type; this.Text = name; Namespace = ns; @@ -143,7 +161,7 @@ namespace Tango.Scripting.Editors set { SetValue(IsSelectedProperty, value); } } public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register("IsSelected", typeof(bool), typeof(CompletionData), new PropertyMetadata(false, IsSelectedChanged)); + DependencyProperty.Register("IsSelected", typeof(bool), typeof(TypeCompletionData), new PropertyMetadata(false, IsSelectedChanged)); private static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -164,6 +182,209 @@ namespace Tango.Scripting.Editors } } + internal class MethodCompletionData : DependencyObject, ICompletionData + { + private String _description; + + /// + /// Gets or sets the icon source. + /// + 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 Parameters { get; set; } + + public bool HasOverloads + { + get { return Overloads > 0; } + } + + public MethodCompletionData(String cls, string name, String returnType, String description, List parameters, int overloads) + { + Type = "method"; + Parameters = parameters; + Class = cls; + this.Text = name; + Overloads = overloads; + ReturnType = returnType; + _description = description; + } + + /// + /// Gets the image. + /// + public System.Windows.Media.ImageSource Image + { + get { return Source; } + } + + /// + /// Gets the text. This property is used to filter the list of visible elements. + /// + 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; } + } + + /// + /// Gets the description. + /// + public object Description + { + get { return _description; } + } + + /// + /// 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. + /// + public double Priority { get { return 0; } } + + /// + /// Perform the completion. + /// + /// The text area on which completion is performed. + /// The text segment that was used by the completion window if + /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset). + /// The EventArgs used for the insertion request. + /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how + /// the insertion was triggered. + 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"); + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return Text; + } + } + + internal class PropertyCompletionData : DependencyObject, ICompletionData + { + private String _description; + + /// + /// Gets or sets the icon source. + /// + 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; + } + + /// + /// Gets the image. + /// + public System.Windows.Media.ImageSource Image + { + get { return Source; } + } + + /// + /// Gets the text. This property is used to filter the list of visible elements. + /// + 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; } + } + + /// + /// Gets the description. + /// + public object Description + { + get { return _description; } + } + + /// + /// 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. + /// + public double Priority { get { return 0; } } + + /// + /// Perform the completion. + /// + /// The text area on which completion is performed. + /// The text segment that was used by the completion window if + /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset). + /// The EventArgs used for the insertion request. + /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how + /// the insertion was triggered. + 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"); + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return Text; + } + } + #endregion #region Properties @@ -201,6 +422,15 @@ namespace Tango.Scripting.Editors public static readonly DependencyProperty ReferenceAssembliesProperty = DependencyProperty.Register("ReferenceAssemblies", typeof(ObservableCollection), typeof(ScriptEditor), new PropertyMetadata(null)); + public Object CurrentPopupContent + { + get { return (Object)GetValue(CurrentPopupContentProperty); } + set { SetValue(CurrentPopupContentProperty, value); } + } + public static readonly DependencyProperty CurrentPopupContentProperty = + DependencyProperty.Register("CurrentPopupContent", typeof(Object), typeof(ScriptEditor), new PropertyMetadata(null)); + + #endregion #region Constructors @@ -218,8 +448,6 @@ namespace Tango.Scripting.Editors /// public ScriptEditor() { - _known_types_docs_cache = new Dictionary(); - _assemblies_docs_cache = new Dictionary(); _declaredTypes = new List(); _current_usings = new List(); @@ -230,7 +458,7 @@ namespace Tango.Scripting.Editors ReferenceAssemblies.Add(new ReferenceAssembly(typeof(String))); //mscorelib ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Enumerable))); //System.Core - _knownTypes = new List(); + _knownTypes = new List(); _parser = new ScriptParser(); TextArea.IndentationStrategy = new Indentation.CSharp.CSharpIndentationStrategy(Options); @@ -410,6 +638,146 @@ namespace Tango.Scripting.Editors return GetWordByEndIndex(index); } + private ConstructionSession GetConstructionSession() + { + var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); + + if (expression != null) + { + ConstructionSession session = new ConstructionSession(); + + var line = GetCurrentLine(); + int parameterIndex = 0; + for (int i = CaretOffset; i > line.Offset; i--) + { + String c = Document.GetText(i, 1); + + if (c == "(") + { + var typeDeclaration = expression.Type as GenericNameSyntax; + + KnownType type = null; + + 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 (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 (type != null) + { + session.Type = type; + session.ParameterIndex = parameterIndex; + return session; + } + else + { + return null; + } + } + else if (c == ",") + { + parameterIndex++; + } + + } + } + + return null; + } + + //private MethodSession GetMethodSession() + //{ + // var lineText = GetCurrentLineText(); + // var expression = lineText.Split(' ').ToList().LastOrDefault(); + + // if (expression != null) + // { + + // } + + + // var expression = _parser.GetExpression(GetCurrentLineText()); + + // if (expression != null) + // { + // MethodSession session = new MethodSession(); + + // var line = GetCurrentLine(); + // int parameterIndex = 0; + // for (int i = CaretOffset; i > line.Offset; i--) + // { + // String c = Document.GetText(i, 1); + + // if (c == "(") + // { + // //var typeDeclaration = expression.Type as GenericNameSyntax; + + // //KnownType type = null; + + // //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 (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 (type != null) + // //{ + // // session.Type = type; + // // session.ParameterIndex = parameterIndex; + // // return session; + // //} + // //else + // //{ + // // return null; + // //} + // } + // else if (c == ",") + // { + // parameterIndex++; + // } + + // } + // } + + // return null; + //} + + public List GetPreviousWords() + { + var currentLine = GetCurrentLine(); + var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); + return currentText.Split(' ').ToList(); + } + #endregion #region Highlighting @@ -431,7 +799,7 @@ namespace Tango.Scripting.Editors { lock (_knownTypes) { - _knownTypes.Add(type); + _knownTypes.Add(new KnownType(type)); } } }); @@ -453,22 +821,25 @@ namespace Tango.Scripting.Editors List referenceTypes = new List(); List interfaceTypes = new List(); - foreach (var type in _knownTypes) + lock (_knownTypes) { - String name = type.Name; - - if (type.ContainsGenericParameters) + foreach (var type in _knownTypes.ToList().Where(x => x != null)) { - name = new String(name.TakeWhile(x => x != '`').ToArray()); - } + String name = type.Name; - if (type.IsClass || (type.IsValueType && !type.IsPrimitive)) - { - referenceTypes.Add(String.Format("{0}", name)); - } - else if (type.IsInterface || type.IsEnum) - { - interfaceTypes.Add(String.Format("{0}", name)); + if (type.Type.ContainsGenericParameters) + { + name = new String(name.TakeWhile(x => x != '`').ToArray()); + } + + if (type.Type.IsInterface || type.Type.IsEnum) + { + interfaceTypes.Add(String.Format("{0}", name)); + } + else if (type.Type.IsClass) + { + referenceTypes.Add(String.Format("{0}", name)); + } } } @@ -545,12 +916,40 @@ namespace Tango.Scripting.Editors /// The that contains the event data. protected override void OnPreviewKeyDown(KeyEventArgs e) { + if (CurrentPopupContent is MethodPopup && (e.Key == Key.Down || e.Key == Key.Up)) + { + e.Handled = true; + + if (e.Key == Key.Down) + { + (CurrentPopupContent as MethodPopup).IncrementMethod(); + } + else if (e.Key == Key.Up) + { + (CurrentPopupContent as MethodPopup).DecrementMethod(); + } + + return; + } + base.OnPreviewKeyDown(e); + HidePopup(); HandleKeyCombinations(e); } #endregion + #region Apply Template + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _popup = GetTemplateChild("PART_popup") as Popup; + } + + #endregion + #region Key Combination Handling /// @@ -605,11 +1004,118 @@ namespace Tango.Scripting.Editors { List items = new List(); - if (e.Text == ".") + HidePopup(); + + var lineText = GetCurrentLineText(); + var previousWordsLast = GetPreviousWords().LastOrDefault(); + String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; + + + if (e.Text == ";" || e.Text == " ") { - var word = GetCurrentWord(); + HideCompletionWindow(); } - else + else if (e.Text == ".") + { + var expression = GetPreviousWords().LastOrDefault(); + + if (expression != null) + { + var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "")).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 == variable.Type); + + 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; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type == member.ReturnType); + } + + if (knownType != null) + { + completionWindow.HideCompletion(); + IList data = new List(); + + 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 if (e.Text == "(" || e.Text == ",") + { + completionWindow.HideCompletion(); + + var session = GetConstructionSession(); + + if (session != null) + { + var content = CreateConstructionSessionPopupContent(session); + if (content.Methods.Count > 0) + { + ShowPopup(content); + } + } + + //var methodSession = GetMethodSession(); + + //if (methodSession != null) + //{ + + //} + } + else if (lineText.StartsWith("using")) + { + IList data = new List(); + + 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)); + } + } + + ShowCompletionWindow(data, GetCurrentWord()); + } + else if (!currentWord.Contains(".")) { var previous_word = GetPreviousWord(); var word = GetCurrentWord(); @@ -631,33 +1137,19 @@ namespace Tango.Scripting.Editors { if (char.IsUpper(word.First())) { - IList data = completionWindow.CompletionList.CompletionData; - data.Clear(); + IList data = new List(); foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) { - data.Add(new CompletionData(type.TypeKind.ToString().ToLower(), type.Name, type.ContainingNamespace?.Name, "Declared inside the current script...")); + data.Add(new TypeCompletionData(type.TypeKind.ToString().ToLower(), type.Name, type.ContainingNamespace?.Name, "Declared inside the current script...")); } foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) { - String doc = GetKnownTypeDocumentation(type); - data.Add(new CompletionData(GetTypeOfType(type), type.Name, type.Namespace, doc)); + data.Add(new TypeCompletionData(type.TypeDefinition, type.FriendlyName, type.Type.Namespace, type.Summary)); } - if (data.Count > 0) - { - completionWindow.ShowCompletion(); - - if (completionWindow.CompletionList.ListBox != null) - { - completionWindow.CompletionList.SelectItemFiltering(word); - } - } - else - { - completionWindow.HideCompletion(); - } + ShowCompletionWindow(data, word); } } } @@ -671,61 +1163,34 @@ namespace Tango.Scripting.Editors Document.Replace(index, Math.Min(max - index, item.Text.Length), item.Text); } - private String GetKnownTypeDocumentation(Type type) + private void ShowCompletionWindow(IList suggestions, String filter) { - if (_known_types_docs_cache.ContainsKey(type)) - { - return _known_types_docs_cache[type]; - } + IList data = completionWindow.CompletionList.CompletionData; + data.Clear(); - XmlDocument _docuDoc = null; - - if (_assemblies_docs_cache.ContainsKey(type.Assembly)) + foreach (var item in suggestions) { - _docuDoc = _assemblies_docs_cache[type.Assembly]; + data.Add(item); } - if (_docuDoc == null) + if (data.Count > 0) { - String dllPath = type.Assembly.Location; - - string docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML"; + completionWindow.ShowCompletion(); - if (File.Exists(docuPath)) + if (completionWindow.CompletionList.ListBox != null) { - _docuDoc = new XmlDocument(); - _docuDoc.Load(docuPath); + completionWindow.CompletionList.SelectItemFiltering(filter); } - else if (File.Exists(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath)))) - { - _docuDoc = new XmlDocument(); - _docuDoc.Load(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath))); - } - - _assemblies_docs_cache.Add(type.Assembly, _docuDoc); } - - if (_docuDoc != null) + else { - string path = "T:" + type.FullName; - XmlNode xmlDocuOfType = _docuDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); - - _known_types_docs_cache.Add(type, xmlDocuOfType.InnerText); - - return xmlDocuOfType.InnerText; + completionWindow.HideCompletion(); } - - return String.Empty; } - private String GetTypeOfType(Type type) + private void HideCompletionWindow() { - if (type.IsClass) return "class"; - if (type.IsEnum) return "enum"; - if (type.IsInterface) return "interface"; - if (type.IsValueType) return "struct"; - - return ""; + completionWindow.HideCompletion(); } private List GetScriptClassNames() @@ -776,5 +1241,85 @@ namespace Tango.Scripting.Editors } #endregion + + #region Popup + + private void ShowPopup(Object content) + { + var position = TextArea.Caret.Position; + var textView = TextArea.TextView; + + var visualLocation = textView.GetVisualPosition(position, VisualYPosition.LineBottom); + var visualLocationTop = textView.GetVisualPosition(position, VisualYPosition.LineTop); + + Point location = textView.PointToScreen(visualLocation - textView.ScrollOffset); + Point locationTop = textView.PointToScreen(visualLocationTop - textView.ScrollOffset); + + _popup.Placement = PlacementMode.Absolute; + _popup.PlacementRectangle = new Rect(location, new Size(200, 100)); + + CurrentPopupContent = content; + + _popup.IsOpen = true; + } + + private void HidePopup() + { + _popup.IsOpen = false; + CurrentPopupContent = null; + } + + private MethodPopup CreateConstructionSessionPopupContent(ConstructionSession session) + { + MethodPopup popup = new MethodPopup(); + + foreach (var c in session.Type.Constructors) + { + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Type.Name; + method.Description = c.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 = c.Parameters; + + foreach (var p in parameters) + { + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Name = p.Name; + pDescription.Type = p.Type.Name; + pDescription.Description = p.Description; + method.Parameters.Add(pDescription); + } + + popup.Methods.Add(method); + } + + if (session.ParameterIndex > 0) + { + 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 18ed1ff70..d7c455704 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 @@ -189,6 +189,9 @@ + + + UndoStack.cs @@ -320,6 +323,14 @@ + + + + + + + + IBackgroundRenderer.cs @@ -560,19 +571,34 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file 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 d113ca2a2..8b60d42a7 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 @@ -1,9 +1,11 @@ @@ -21,6 +23,8 @@ #E6E6E6 #A0A0A0 #2B91AF + #4EC9B0 + #3F8FD6 @@ -29,6 +33,21 @@ + + + + + + + + + + + + + + + + + @@ -90,7 +205,35 @@ - + + + + + @@ -160,17 +303,86 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> - + + + + + + + + + + + + + + + + - + + + + + + + --> + + @@ -205,36 +196,8 @@ - - - - - - + + @@ -388,4 +351,184 @@ + + + + + + + + + + + + + + + + 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 GetUsings(String code) { - Regex r = new Regex("(using [^;]+;)"); + Regex r = new Regex("(using [^;^\n]+;)"); var matches = r.Matches(code); - return matches.OfType().Select(x => x.Value.Replace("using ", "").Replace(";", "")).ToList(); + return matches.OfType().Select(x => x.Value.Replace("using ", "").Replace(";", "").Replace("\n", "").Replace("\t", "").Replace("\r", "")).ToList(); } public List GetDeclaredTypes(String code) @@ -118,7 +118,7 @@ namespace Tango.Scripting.Parsing return root.DescendantNodes().OfType().FirstOrDefault(); } - public T GetExpression(String line) where T : ExpressionSyntax + public T GetExpression(String line) where T : CSharpSyntaxNode { SyntaxTree tree = CSharpSyntaxTree.ParseText(line); CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); -- cgit v1.3.1 From c96ecaf239db6d1270958841e2efd9fba3360c6e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 11 Mar 2019 13:59:39 +0200 Subject: Working on script engine. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Highlighting/Resources/CSharp-Mode.xshd | 2 + .../Tango.Scripting.Editors/Images/field.png | Bin 0 -> 395 bytes .../Tango.Scripting.Editors/Images/property.png | Bin 316 -> 363 bytes .../Intellisense/FieldCompletionItem.cs | 20 ++ .../Intellisense/FieldCompletionItemPopup.cs | 25 +++ .../Tango.Scripting.Editors/ScriptEditor.cs | 217 +++++++++++++-------- .../Tango.Scripting.Editors.csproj | 7 +- .../Tango.Scripting.Editors/Themes/Generic.xaml | 23 +++ .../Tango.Scripting/Parsing/ScriptParser.cs | 102 +++++----- .../Tango.Scripting/Parsing/ScriptVariable.cs | 9 +- .../Tango.Scripting/Tango.Scripting.csproj | 3 + 13 files changed, 277 insertions(+), 131 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItemPopup.cs (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 87a17e875..13f721931 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index b805976f0..659c9bdf0 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd index 1ba2cbc6f..40f362e08 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd @@ -184,6 +184,8 @@ dynamic await void + interface + this diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png new file mode 100644 index 000000000..37de414e9 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png index 001a8c66a..4abd1a4a4 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItem.cs new file mode 100644 index 000000000..3b1996174 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItem.cs @@ -0,0 +1,20 @@ +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 FieldCompletionItem : CompletionItem + { + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new FieldCompletionItemPopup(); + public override BitmapSource Image => GetImage("field.png"); + + 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/FieldCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItemPopup.cs new file mode 100644 index 000000000..e1ea3ce55 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItemPopup.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 FieldCompletionItemPopup : CompletionItemPopupControl + { + static FieldCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(FieldCompletionItemPopup), new FrameworkPropertyMetadata(typeof(FieldCompletionItemPopup))); + } + } +} 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 49d745d6c..64fb0f194 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 @@ -400,7 +400,7 @@ namespace Tango.Scripting.Editors if (variableName != null && tree.Count > 1) { tree.RemoveAt(0); - var variables = _parser.GetScriptVariables(Document.Text); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); var variable = variables.FirstOrDefault(x => x.Name == variableName); if (variable != null) @@ -449,8 +449,6 @@ namespace Tango.Scripting.Editors private void InvalidateHighlighting() { - _parser.GetDeclaredTypes(Text); - _knownTypes.Clear(); var assemblies = ReferenceAssemblies.ToList(); @@ -689,7 +687,7 @@ namespace Tango.Scripting.Editors if (e.Text == " " && GetPreviousWord() == "new") { - var s = _parser.GetExpression(GetCurrentLineText()); + var s = _parser.GetExpressionFirst(GetCurrentLineText()); if (s != null) { @@ -835,100 +833,153 @@ namespace Tango.Scripting.Editors if (!String.IsNullOrWhiteSpace(word)) { - if (char.IsUpper(word.First())) - { - IList data = new List(); + IList data = new List(); - foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) + foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) + { + if (type.TypeKind == TypeKind.Struct) { - 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 StructCompletionItem() { - data.Add(new EnumCompletionItem() - { - Name = type.Name, - Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, - }); - } - else if (type.TypeKind == TypeKind.Interface) + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + Priority = 1, + }); + } + else if (type.TypeKind == TypeKind.Enum) + { + data.Add(new EnumCompletionItem() { - data.Add(new InterfaceCompletionItem() - { - Name = type.Name, - Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, - }); - } - else if (type.TypeKind == TypeKind.Class) + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + Priority = 1, + }); + } + else if (type.TypeKind == TypeKind.Interface) + { + data.Add(new InterfaceCompletionItem() { - data.Add(new ClassCompletionItem() - { - Name = type.Name, - Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, - }); - } - else + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + Priority = 1, + }); + } + else if (type.TypeKind == TypeKind.Class) + { + data.Add(new ClassCompletionItem() { - throw new NotImplementedException("Implement generic item here!"); - } + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + Priority = 1, + }); } + else + { + throw new NotImplementedException("Implement generic item here!"); + } + } - foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) + foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) + { + if (type.Type.IsEnum) { - if (type.Type.IsEnum) + data.Add(new EnumCompletionItem() { - 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) + Namespace = type.Type.Namespace, + Description = type.Summary, + Name = type.FriendlyName, + Priority = 0, + }); + } + else if (type.Type.IsInterface) + { + data.Add(new InterfaceCompletionItem() { - data.Add(new StructCompletionItem() - { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - }); - } - else if (type.Type.IsClass) + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsValueType) + { + data.Add(new StructCompletionItem() { - data.Add(new ClassCompletionItem() - { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - }); - } - else + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsClass) + { + data.Add(new ClassCompletionItem() { - throw new NotImplementedException("Implement generic item here."); - } + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); } + else + { + throw new NotImplementedException("Implement generic item here."); + } + } - ShowCompletionWindow(data, word); + foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset)) + { + if (symbol.Kind == SymbolKind.Property) + { + data.Add(new PropertyCompletionItem() + { + Class = symbol.Class, + Description = "Property defined in this script.", + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Field) + { + data.Add(new FieldCompletionItem() + { + Class = symbol.Class, + Description = "Field defined in this script.", + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Parameter) + { + data.Add(new FieldCompletionItem() + { + Class = symbol.Class, + Description = "Method parameter defined in this script.", + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Method) + { + data.Add(new MethodCompletionItem() + { + Class = symbol.Class, + Description = "Method defined in this script.", + Name = symbol.Name, + ReturnType = symbol.Type, + Priority = 2, + }); + } } + + ShowCompletionWindow(data, word); } } } @@ -1027,7 +1078,7 @@ namespace Tango.Scripting.Editors if (variableName != null) { tree.RemoveAt(0); - var variables = _parser.GetScriptVariables(Document.Text); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); var variable = variables.FirstOrDefault(x => x.Name == variableName); if (variable != null) 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 5422ba805..e5960a664 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 @@ -197,6 +197,8 @@ + + @@ -615,9 +617,12 @@ + + + - + \ No newline at end of file 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 7a6588239..1ab9dd2db 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 @@ -531,4 +531,27 @@ + + 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 5564296e8..43a5a6b54 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 @@ -26,61 +26,51 @@ namespace Tango.Scripting.Parsing CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); var compilation = CSharpCompilation.Create("CSharpScript").AddSyntaxTrees(tree); SemanticModel model = compilation.GetSemanticModel(tree); - return model; } - public List GetScriptVariables(String code) + public List GetContextSymbols(String code, int caretOffset) { - List vars = new List(); + var model = GetSemanticModel(code); + var symbols = model.LookupSymbols(caretOffset).ToList().Where(x => x.Kind == SymbolKind.Property || x.Kind == SymbolKind.Field || x.Kind == SymbolKind.Parameter || x.Kind == SymbolKind.Local || x.Kind == SymbolKind.Method).ToList(); - SyntaxTree tree = CSharpSyntaxTree.ParseText(code); - var root = (CompilationUnitSyntax)tree.GetRoot(); + List vars = new List(); - List variables = new List(); - FillVariables(variables, root.Members[0]); - variables = variables.Distinct().ToList(); - - foreach (var item in variables) + foreach (var symbol in symbols.DistinctBy(x => x.Name)) { - ScriptVariable v = new ScriptVariable(); - v.Type = item.Type.ToString(); - - var variable = item.Variables.FirstOrDefault(); - - if (variable != null) + if (symbol.Kind == SymbolKind.Method) { - //if (variable.Initializer.Value.GetType() == typeof(ObjectCreationExpressionSyntax)) - //{ - // v.Type = (variable.Initializer.Value as ObjectCreationExpressionSyntax).Type.ToString(); - //} - //else if (variable.Initializer.Value.GetType() == typeof(InvocationExpressionSyntax)) - //{ - // v.Type = (((variable.Initializer.Value as InvocationExpressionSyntax).Expression as MemberAccessExpressionSyntax).Name as GenericNameSyntax).TypeArgumentList.Arguments[0].ToString(); - //} - - v.Name = variable.Identifier.ToString(); - } - - vars.Add(v); - } - - return vars; - } - - private void FillVariables(List variables, SyntaxNode node) - { - foreach (var item in node.DescendantNodes(x => true)) - { - if (item.GetType() == typeof(VariableDeclarationSyntax)) - { - variables.Add(item as VariableDeclarationSyntax); + var prop = symbol.GetType().GetProperty("ReturnType"); + + if (prop != null) + { + vars.Add(new ScriptSymbol() + { + Name = symbol.Name, + Type = prop.GetValue(symbol).ToString(), + Class = symbol.ContainingType?.Name, + Kind = symbol.Kind, + }); + } } else { - FillVariables(variables, item); + var prop = symbol.GetType().GetProperty("Type"); + + if (prop != null) + { + vars.Add(new ScriptSymbol() + { + Name = symbol.Name, + Type = prop.GetValue(symbol).ToString(), + Class = symbol.ContainingType?.Name, + Kind = symbol.Kind, + }); + } } } + + return vars; } public List GetUsings(String code) @@ -99,7 +89,7 @@ namespace Tango.Scripting.Parsing var compilation = CSharpCompilation.Create("CSharpScript").AddSyntaxTrees(tree); SemanticModel model = compilation.GetSemanticModel(tree); - foreach (var d in root.DescendantNodes().OfType()) + foreach (var d in root.DescendantNodes().Where(x => x is ClassDeclarationSyntax || x is EnumDeclarationSyntax || x is InterfaceDeclarationSyntax).OfType()) { var type = model.GetDeclaredSymbol(d); if (!String.IsNullOrWhiteSpace(type.Name)) @@ -118,11 +108,35 @@ namespace Tango.Scripting.Parsing return root.DescendantNodes().OfType().FirstOrDefault(); } - public T GetExpression(String line) where T : CSharpSyntaxNode + public T GetExpressionFirst(String line) where T : CSharpSyntaxNode { SyntaxTree tree = CSharpSyntaxTree.ParseText(line); CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); return root.DescendantNodes().OfType().FirstOrDefault(); } + + public List GetExpressions(String line) where T : CSharpSyntaxNode + { + SyntaxTree tree = CSharpSyntaxTree.ParseText(line); + CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); + return root.DescendantNodes().OfType().ToList(); + } + + public List GetDirectExpressions(SyntaxNode node) where T : CSharpSyntaxNode + { + return node.DescendantNodes().OfType().ToList(); + } + + private SyntaxNode GetCaretOffsetNode(String code, int offset) + { + SyntaxTree tree = CSharpSyntaxTree.ParseText(code); + CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); + return root.DescendantNodes().Where(x => offset >= x.FullSpan.Start && offset <= x.FullSpan.End).OrderBy(x => x.FullSpan.Length).FirstOrDefault(); + } + + private List GetNodeAncestors(SyntaxNode node) + { + return node.Ancestors().ToList(); + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs index c843e07c6..50b3fdd7e 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.CodeAnalysis; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,14 +7,16 @@ using System.Threading.Tasks; namespace Tango.Scripting.Parsing { - public class ScriptVariable + public class ScriptSymbol { public String Name { get; set; } public String Type { get; set; } + public SymbolKind Kind { get; set; } + public String Class { get; set; } public override string ToString() { - return String.Format("{0} : {1}", Type, Name); + return $"{Kind.ToString()} : {Type} : {Name}"; } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj index 71d1da005..f5d0175e7 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj @@ -114,6 +114,9 @@ ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + + ..\..\..\Build\Core\Debug\Tango.Core.dll + -- cgit v1.3.1 From b0bbc0bec1aaed2230b8a4aa1c08e379fed4629a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 11 Mar 2019 15:41:05 +0200 Subject: WOrking on script engine. --- .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../Tango.Scripting.Editors/Images/class.png | Bin 212 -> 417 bytes .../Tango.Scripting.Editors/Images/field.png | Bin 395 -> 216 bytes .../Tango.Scripting.Editors/Images/interface.png | Bin 222 -> 381 bytes .../Tango.Scripting.Editors/Images/namespace.png | Bin 250 -> 241 bytes .../Tango.Scripting.Editors/Images/property.png | Bin 363 -> 428 bytes .../Tango.Scripting.Editors/ScriptEditor.cs | 79 +++++++++++++++++---- .../Tango.Scripting.Editors.csproj | 14 ++-- .../Tango.Scripting/Parsing/ScriptParser.cs | 66 ++++++++++++++++- .../Tango.Scripting/Parsing/ScriptSymbol.cs | 24 +++++++ .../Tango.Scripting/Parsing/ScriptType.cs | 22 ++++++ .../Tango.Scripting/Parsing/ScriptVariable.cs | 22 ------ .../Tango.Scripting/Tango.Scripting.csproj | 3 +- 13 files changed, 184 insertions(+), 46 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 1fc56ba11..01dc974ad 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png index 91b35a829..3e40469f5 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png index 37de414e9..763eadffb 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/field.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png index 3b07597dd..fb00f0cc7 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png index 7f2b6b5ef..6520448ce 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png index 4abd1a4a4..d2f90f569 100644 Binary files a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png differ 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 64fb0f194..bcc05bde5 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 @@ -50,7 +50,7 @@ namespace Tango.Scripting.Editors private ScriptParser _parser; private List _current_usings; private List _knownTypes; - private List _declaredTypes; + private List _declaredTypes; #region Mini Classes @@ -136,7 +136,7 @@ namespace Tango.Scripting.Editors /// public ScriptEditor() { - _declaredTypes = new List(); + _declaredTypes = new List(); _current_usings = new List(); @@ -511,11 +511,11 @@ namespace Tango.Scripting.Editors foreach (var type in _declaredTypes) { - if (type.TypeKind == TypeKind.Interface || type.TypeKind == TypeKind.Enum) + if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) { interfaceTypes.Add(String.Format("{0}", type.Name)); } - else if (type.TypeKind == TypeKind.Class) + else if (type.Kind == TypeKind.Class) { referenceTypes.Add(String.Format("{0}", type.Name)); } @@ -752,6 +752,15 @@ namespace Tango.Scripting.Editors ShowCompletionWindow(data, GetCurrentWord()); } + else + { + var declaredType = GetCurrentDeclaredType(); + + if (declaredType != null) + { + + } + } } else if (e.Text == "(" || e.Text == ",") { @@ -837,43 +846,43 @@ namespace Tango.Scripting.Editors foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) { - if (type.TypeKind == TypeKind.Struct) + if (type.Kind == TypeKind.Struct) { data.Add(new StructCompletionItem() { Name = type.Name, Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, + Namespace = type.ContainingNamespace, Priority = 1, }); } - else if (type.TypeKind == TypeKind.Enum) + else if (type.Kind == TypeKind.Enum) { data.Add(new EnumCompletionItem() { Name = type.Name, Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, + Namespace = type.ContainingNamespace, Priority = 1, }); } - else if (type.TypeKind == TypeKind.Interface) + else if (type.Kind == TypeKind.Interface) { data.Add(new InterfaceCompletionItem() { Name = type.Name, Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, + Namespace = type.ContainingNamespace, Priority = 1, }); } - else if (type.TypeKind == TypeKind.Class) + else if (type.Kind == TypeKind.Class) { data.Add(new ClassCompletionItem() { Name = type.Name, Description = "Declared inside the current script...", - Namespace = type.ContainingNamespace?.Name, + Namespace = type.ContainingNamespace, Priority = 1, }); } @@ -944,7 +953,7 @@ namespace Tango.Scripting.Editors Priority = 2, }); } - else if (symbol.Kind == SymbolKind.Field) + else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local) { data.Add(new FieldCompletionItem() { @@ -1110,6 +1119,50 @@ namespace Tango.Scripting.Editors return null; } + private ScriptType GetCurrentDeclaredType() + { + 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.GetContextSymbols(Document.Text, CaretOffset); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Type, "<.+>", "")); + + if (declaredType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type); + } + + return declaredType; + } + } + } + } + + return null; + } + #endregion #region Popup 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 e5960a664..8b213a870 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 @@ -597,32 +597,32 @@ - + - + - + - + - + - + - + \ No newline at end of file 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 43a5a6b54..1ee2b780c 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 @@ -50,6 +50,8 @@ namespace Tango.Scripting.Parsing Type = prop.GetValue(symbol).ToString(), Class = symbol.ContainingType?.Name, Kind = symbol.Kind, + Accessibility = symbol.DeclaredAccessibility, + ContainingNamespace = symbol.ContainingNamespace?.Name, }); } } @@ -65,6 +67,8 @@ namespace Tango.Scripting.Parsing Type = prop.GetValue(symbol).ToString(), Class = symbol.ContainingType?.Name, Kind = symbol.Kind, + Accessibility = symbol.DeclaredAccessibility, + ContainingNamespace = symbol.ContainingNamespace?.Name, }); } } @@ -80,9 +84,9 @@ namespace Tango.Scripting.Parsing return matches.OfType().Select(x => x.Value.Replace("using ", "").Replace(";", "").Replace("\n", "").Replace("\t", "").Replace("\r", "")).ToList(); } - public List GetDeclaredTypes(String code) + public List GetDeclaredTypes(String code) { - List types = new List(); + List types = new List(); SyntaxTree tree = CSharpSyntaxTree.ParseText(code); CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); @@ -94,7 +98,63 @@ namespace Tango.Scripting.Parsing var type = model.GetDeclaredSymbol(d); if (!String.IsNullOrWhiteSpace(type.Name)) { - types.Add(type); + ScriptType scriptType = new ScriptType(); + scriptType.Name = type.Name; + scriptType.Kind = type.TypeKind; + scriptType.ContainingNamespace = type.ContainingNamespace?.Name; + + foreach (var symbol in d.DescendantNodes().OfType()) + { + var symbolModel = model.GetDeclaredSymbol(symbol); + + scriptType.Symbols.Add(new ScriptSymbol() + { + Class = scriptType.Name, + Accessibility = symbolModel.DeclaredAccessibility, + Kind = SymbolKind.Property, + Name = symbolModel.Name, + Type = symbolModel.Type.ToString(), + ContainingNamespace = symbolModel.ContainingNamespace?.Name, + }); + } + + foreach (var symbol in d.DescendantNodes().OfType()) + { + var symbolModel = model.GetDeclaredSymbol(symbol.Declaration.Variables.FirstOrDefault()) as IFieldSymbol; + + if (symbolModel != null) + { + scriptType.Symbols.Add(new ScriptSymbol() + { + Class = scriptType.Name, + Accessibility = symbolModel.DeclaredAccessibility, + Kind = SymbolKind.Field, + Name = symbolModel.Name, + Type = symbolModel.Type.ToString(), + ContainingNamespace = symbolModel.ContainingNamespace?.Name, + }); + } + } + + foreach (var symbol in d.DescendantNodes().OfType()) + { + var symbolModel = model.GetDeclaredSymbol(symbol); + + if (symbolModel != null) + { + scriptType.Symbols.Add(new ScriptSymbol() + { + Class = scriptType.Name, + Accessibility = symbolModel.DeclaredAccessibility, + Kind = SymbolKind.Method, + Name = symbolModel.Name, + Type = symbolModel.ReturnType.ToString(), + ContainingNamespace = symbolModel.ContainingNamespace?.Name, + }); + } + } + + types.Add(scriptType); } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs new file mode 100644 index 000000000..b93b7951a --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs @@ -0,0 +1,24 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Parsing +{ + public class ScriptSymbol + { + public String Name { get; set; } + public String Type { get; set; } + public SymbolKind Kind { get; set; } + public String Class { get; set; } + public Accessibility Accessibility { get; set; } + public String ContainingNamespace { get; set; } + + public override string ToString() + { + return $"{Kind.ToString()} : {Type} : {Name}"; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs new file mode 100644 index 000000000..fc360acb5 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs @@ -0,0 +1,22 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Parsing +{ + public class ScriptType + { + public String Name { get; set; } + public TypeKind Kind { get; set; } + public List Symbols { get; set; } + public string ContainingNamespace { get; set; } + + public ScriptType() + { + Symbols = new List(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs deleted file mode 100644 index 50b3fdd7e..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptVariable.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.CodeAnalysis; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Scripting.Parsing -{ - public class ScriptSymbol - { - public String Name { get; set; } - public String Type { get; set; } - public SymbolKind Kind { get; set; } - public String Class { get; set; } - - public override string ToString() - { - return $"{Kind.ToString()} : {Type} : {Name}"; - } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj index f5d0175e7..081009e7e 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Tango.Scripting.csproj @@ -124,6 +124,7 @@ + @@ -133,7 +134,7 @@ - + -- cgit v1.3.1 From ac251de510cfb75c2967f85efc17ac8f8ad20ea0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 11 Mar 2019 18:26:59 +0200 Subject: Working on script engine... --- .../Tango.Scripting.Editors/ScriptEditor.cs | 114 ++++++++++++++------- .../Tango.Scripting/Parsing/ScriptParser.cs | 95 +++++++++++++++-- .../Tango.Scripting/Parsing/ScriptSymbol.cs | 1 + .../Tango.Scripting/Parsing/ScriptType.cs | 1 + 4 files changed, 168 insertions(+), 43 deletions(-) (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') 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 bcc05bde5..d2f5dd169 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 @@ -558,6 +558,8 @@ namespace Tango.Scripting.Editors InvalidateHighlighting(); } + _declaredTypes = declaredTypes; + //for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++) //{ // if (TextArea.TextView.LineTransformers[i] is OffsetColorizer) @@ -680,10 +682,12 @@ namespace Tango.Scripting.Editors HidePopup(); var lineText = GetCurrentLineText(); - var previousWordsLast = GetPreviousWords().LastOrDefault(); + var previousWords = GetPreviousWords(); + var previousWordsLast = previousWords.LastOrDefault(); String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); + if (previousWords.Count > 0 && previousWords.First().StartsWith("//")) return; if (e.Text == " " && GetPreviousWord() == "new") { @@ -758,7 +762,51 @@ namespace Tango.Scripting.Editors if (declaredType != null) { + completionWindow.HideCompletion(); + IList data = new List(); + + var typeMembers = declaredType.Symbols.ToList(); + + foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) + { + var member = methodGroup.First(); + if (member.Kind == SymbolKind.Method) + { + data.Add(new MethodCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + ReturnType = member.Type, + Description = member.Summary, + //Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); + + } + else if (member.Kind == SymbolKind.Property) + { + data.Add(new PropertyCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } + else if (member.Kind == SymbolKind.Field) + { + data.Add(new FieldCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } + } + + ShowCompletionWindow(data, GetCurrentWord()); } } } @@ -766,29 +814,34 @@ namespace Tango.Scripting.Editors { completionWindow.HideCompletion(); - var session = GetConstructionSession(); - - if (session != null) + try { - var content = CreateConstructionSessionPopupContent(session); - if (content.Methods.Count > 0) + var session = GetConstructionSession(); + + if (session != null) { - ShowPopup(content); + var content = CreateConstructionSessionPopupContent(session); + if (content.Methods.Count > 0) + { + ShowPopup(content); + } } - } - var methodSession = GetMethodSession(); + var methodSession = GetMethodSession(); - if (methodSession != null) - { - var content = CreateMethodSessionPopupContent(methodSession); - if (content.Methods.Count > 0) + if (methodSession != null) { - ShowPopup(content); + var content = CreateMethodSessionPopupContent(methodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + } } } - - var a = GetMethodSession(); + catch (Exception ex) + { + Debug.WriteLine(ex); + } } else if (lineText.StartsWith("using")) { @@ -851,7 +904,7 @@ namespace Tango.Scripting.Editors data.Add(new StructCompletionItem() { Name = type.Name, - Description = "Declared inside the current script...", + Description = type.Summary, Namespace = type.ContainingNamespace, Priority = 1, }); @@ -861,7 +914,7 @@ namespace Tango.Scripting.Editors data.Add(new EnumCompletionItem() { Name = type.Name, - Description = "Declared inside the current script...", + Description = type.Summary, Namespace = type.ContainingNamespace, Priority = 1, }); @@ -871,7 +924,7 @@ namespace Tango.Scripting.Editors data.Add(new InterfaceCompletionItem() { Name = type.Name, - Description = "Declared inside the current script...", + Description = type.Summary, Namespace = type.ContainingNamespace, Priority = 1, }); @@ -881,7 +934,7 @@ namespace Tango.Scripting.Editors data.Add(new ClassCompletionItem() { Name = type.Name, - Description = "Declared inside the current script...", + Description = type.Summary, Namespace = type.ContainingNamespace, Priority = 1, }); @@ -940,36 +993,25 @@ namespace Tango.Scripting.Editors } } - foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset)) + foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset).Where(x => x.Name.StartsWith(GetCurrentWord()))) { if (symbol.Kind == SymbolKind.Property) { data.Add(new PropertyCompletionItem() { Class = symbol.Class, - Description = "Property defined in this script.", - Name = symbol.Name, - Type = symbol.Type, - Priority = 2, - }); - } - else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local) - { - data.Add(new FieldCompletionItem() - { - Class = symbol.Class, - Description = "Field defined in this script.", + Description = symbol.Summary, Name = symbol.Name, Type = symbol.Type, Priority = 2, }); } - else if (symbol.Kind == SymbolKind.Parameter) + else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter) { data.Add(new FieldCompletionItem() { Class = symbol.Class, - Description = "Method parameter defined in this script.", + Description = symbol.Summary, Name = symbol.Name, Type = symbol.Type, Priority = 2, @@ -980,7 +1022,7 @@ namespace Tango.Scripting.Editors data.Add(new MethodCompletionItem() { Class = symbol.Class, - Description = "Method defined in this script.", + Description = symbol.Summary, Name = symbol.Name, ReturnType = symbol.Type, Priority = 2, 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 1ee2b780c..b0c18ce83 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 @@ -13,6 +13,19 @@ namespace Tango.Scripting.Parsing { public class ScriptParser { + private const string fakeScript = "CurrentScript"; + private string fakeScriptName = "CurrentScript."; + + private String ReplaceFakeScript(String str) + { + if (str != null) + { + return str.Replace(fakeScriptName, "").Replace(fakeScript, ""); + } + + return str; + } + private CompilationUnitSyntax GetRoot(String code) { SyntaxTree tree = CSharpSyntaxTree.ParseText(code); @@ -31,6 +44,24 @@ namespace Tango.Scripting.Parsing public List GetContextSymbols(String code, int caretOffset) { + var currentNode = GetCaretOffsetNode(code, caretOffset); + + if (currentNode.Ancestors().OfType().Count() == 0) + { + var usings = GetUsingsFull(code); + + int removedLength = usings.Select(x => x.Length).Sum(); + + foreach (var use in usings) + { + code = code.Replace(use, ""); + } + + String scriptStart = $"public class {fakeScript}\n{{\n"; + code = $"{scriptStart}{code}\n}}"; + caretOffset = caretOffset - removedLength + scriptStart.Length; + } + var model = GetSemanticModel(code); var symbols = model.LookupSymbols(caretOffset).ToList().Where(x => x.Kind == SymbolKind.Property || x.Kind == SymbolKind.Field || x.Kind == SymbolKind.Parameter || x.Kind == SymbolKind.Local || x.Kind == SymbolKind.Method).ToList(); @@ -47,11 +78,12 @@ namespace Tango.Scripting.Parsing vars.Add(new ScriptSymbol() { Name = symbol.Name, - Type = prop.GetValue(symbol).ToString(), - Class = symbol.ContainingType?.Name, + Type = ReplaceFakeScript(prop.GetValue(symbol).ToString()), + Class = ReplaceFakeScript(symbol.ContainingType?.Name), Kind = symbol.Kind, Accessibility = symbol.DeclaredAccessibility, - ContainingNamespace = symbol.ContainingNamespace?.Name, + ContainingNamespace = ReplaceFakeScript(symbol.ContainingNamespace?.Name), + Summary = GetSymbolDocumentation(symbol), }); } } @@ -64,11 +96,12 @@ namespace Tango.Scripting.Parsing vars.Add(new ScriptSymbol() { Name = symbol.Name, - Type = prop.GetValue(symbol).ToString(), - Class = symbol.ContainingType?.Name, + Type = ReplaceFakeScript(prop.GetValue(symbol).ToString()), + Class = ReplaceFakeScript(symbol.ContainingType?.Name), Kind = symbol.Kind, Accessibility = symbol.DeclaredAccessibility, - ContainingNamespace = symbol.ContainingNamespace?.Name, + ContainingNamespace = ReplaceFakeScript(symbol.ContainingNamespace?.Name), + Summary = GetSymbolDocumentation(symbol), }); } } @@ -84,6 +117,13 @@ namespace Tango.Scripting.Parsing return matches.OfType().Select(x => x.Value.Replace("using ", "").Replace(";", "").Replace("\n", "").Replace("\t", "").Replace("\r", "")).ToList(); } + public List GetUsingsFull(String code) + { + Regex r = new Regex("(using [^;^\n]+;)"); + var matches = r.Matches(code); + return matches.OfType().Select(x => x.Value).ToList(); + } + public List GetDeclaredTypes(String code) { List types = new List(); @@ -102,6 +142,8 @@ namespace Tango.Scripting.Parsing scriptType.Name = type.Name; scriptType.Kind = type.TypeKind; scriptType.ContainingNamespace = type.ContainingNamespace?.Name; + scriptType.Summary = GetNodeDocumentation(d); + foreach (var symbol in d.DescendantNodes().OfType()) { @@ -115,12 +157,13 @@ namespace Tango.Scripting.Parsing Name = symbolModel.Name, Type = symbolModel.Type.ToString(), ContainingNamespace = symbolModel.ContainingNamespace?.Name, + Summary = GetNodeDocumentation(symbol), }); } foreach (var symbol in d.DescendantNodes().OfType()) { - var symbolModel = model.GetDeclaredSymbol(symbol.Declaration.Variables.FirstOrDefault()) as IFieldSymbol; + var symbolModel = model.GetDeclaredSymbol(symbol.Declaration.Variables.FirstOrDefault()) as IFieldSymbol; if (symbolModel != null) { @@ -132,6 +175,7 @@ namespace Tango.Scripting.Parsing Name = symbolModel.Name, Type = symbolModel.Type.ToString(), ContainingNamespace = symbolModel.ContainingNamespace?.Name, + Summary = GetNodeDocumentation(symbol), }); } } @@ -150,6 +194,7 @@ namespace Tango.Scripting.Parsing Name = symbolModel.Name, Type = symbolModel.ReturnType.ToString(), ContainingNamespace = symbolModel.ContainingNamespace?.Name, + Summary = GetNodeDocumentation(symbol), }); } } @@ -198,5 +243,41 @@ namespace Tango.Scripting.Parsing { return node.Ancestors().ToList(); } + + private String GetNodeDocumentation(SyntaxNode node) + { + try + { + var trivia = node.GetLeadingTrivia().FirstOrDefault(t => t.Kind() == SyntaxKind.SingleLineCommentTrivia); + + if (trivia != null && !String.IsNullOrWhiteSpace(trivia.ToString())) + { + return trivia.ToString().Replace("//", ""); + } + } + catch { } + + return "No documentation."; + } + + private String GetSymbolDocumentation(ISymbol symbol) + { + if (symbol != null) + { + var prop = symbol.GetType().GetProperty("SyntaxNode"); + + if (prop != null) + { + var node = prop.GetValue(symbol) as SyntaxNode; + + if (node != null) + { + return GetNodeDocumentation(node.Parent); + } + } + } + + return "No documentation."; + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs index b93b7951a..622ca4406 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs @@ -15,6 +15,7 @@ namespace Tango.Scripting.Parsing public String Class { get; set; } public Accessibility Accessibility { get; set; } public String ContainingNamespace { get; set; } + public String Summary { get; set; } public override string ToString() { diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs index fc360acb5..3ca34a85e 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptType.cs @@ -13,6 +13,7 @@ namespace Tango.Scripting.Parsing public TypeKind Kind { get; set; } public List Symbols { get; set; } public string ContainingNamespace { get; set; } + public String Summary { get; set; } public ScriptType() { -- cgit v1.3.1 From 057b7d9d9916144fed099ac8573a864c45cd0146 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 11 Mar 2019 19:46:43 +0200 Subject: Working on script engine. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../Popups/MethodDescription.cs | 2 + .../Tango.Scripting.Editors/ScriptEditor.cs | 177 ++++++++++++++++++++- .../Tango.Scripting.Editors/Themes/Generic.xaml | 13 ++ .../Tango.Scripting/Parsing/ScriptParser.cs | 64 +++++++- .../Tango.Scripting/Parsing/ScriptSymbol.cs | 6 + 7 files changed, 252 insertions(+), 10 deletions(-) (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 3366b830d..5474d352a 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index c20e1bda9..5c2d42e86 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs index 864072952..70e0d028d 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs @@ -11,6 +11,8 @@ namespace Tango.Scripting.Editors.Popups public String Description { get; set; } public String ReturnType { get; set; } public List Parameters { get; set; } + public String Class { get; set; } + public String Name { get; set; } public MethodDescription() { 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 d2f5dd169..e43322711 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 @@ -73,6 +73,12 @@ namespace Tango.Scripting.Editors public String MethodName { get; set; } } + private class DeclaredMethodSession + { + public ScriptType Type { get; set; } + public ScriptSymbol Method { get; set; } + } + #endregion #region Properties @@ -436,6 +442,74 @@ namespace Tango.Scripting.Editors return null; } + private DeclaredMethodSession GetDeclaredMethodSession() + { + var expression = GetPreviousWords().LastOrDefault(); + + 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 (variableName != null && tree.Count > 0) + { + tree.RemoveAt(0); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Class, "<.+>", "")); + + if (declaredType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type); + } + + var methodName = tree.Count > 0 ? tree.Last() : variableName; + + var method = declaredType.Symbols.FirstOrDefault(x => x.Kind == SymbolKind.Method && x.Name == methodName); + + if (method != null) + { + return new DeclaredMethodSession() + { + Type = declaredType, + Method = method, + }; + } + } + else if (tree.Count == 0) + { + var method = variable; + + if (method != null) + { + return new DeclaredMethodSession() + { + Type = declaredType, + Method = method, + }; + } + } + } + } + } + + return null; + } + public List GetPreviousWords() { var currentLine = GetCurrentLine(); @@ -687,7 +761,7 @@ namespace Tango.Scripting.Editors String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); - if (previousWords.Count > 0 && previousWords.First().StartsWith("//")) return; + if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; if (e.Text == " " && GetPreviousWord() == "new") { @@ -773,15 +847,29 @@ namespace Tango.Scripting.Editors if (member.Kind == SymbolKind.Method) { - data.Add(new MethodCompletionItem() + var methodCompletion = new MethodCompletionItem() { Class = declaredType.Name, Name = member.Name, ReturnType = member.Type, Description = member.Summary, - //Parameters = method.Parameters, Overloads = methodGroup.Count() - 1, - }); + }; + + + for (int i = 0; i < member.Parameters.Count; i++) + { + var pair = member.Parameters[i]; + + methodCompletion.Parameters.Add(new KnownTypeMethodParameter() + { + Type = pair.Key, + Name = pair.Value, + IsLast = (i == member.Parameters.Count - 1) + }); + } + + data.Add(methodCompletion); } else if (member.Kind == SymbolKind.Property) @@ -824,6 +912,7 @@ namespace Tango.Scripting.Editors if (content.Methods.Count > 0) { ShowPopup(content); + return; } } @@ -835,6 +924,19 @@ namespace Tango.Scripting.Editors if (content.Methods.Count > 0) { ShowPopup(content); + return; + } + } + + var declaredMethodSession = GetDeclaredMethodSession(); + + if (declaredMethodSession != null) + { + var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; } } } @@ -1019,14 +1121,28 @@ namespace Tango.Scripting.Editors } else if (symbol.Kind == SymbolKind.Method) { - data.Add(new MethodCompletionItem() + var methodCompletion = new MethodCompletionItem() { Class = symbol.Class, Description = symbol.Summary, Name = symbol.Name, ReturnType = symbol.Type, Priority = 2, - }); + }; + + for (int i = 0; i < symbol.Parameters.Count; i++) + { + var pair = symbol.Parameters[i]; + + methodCompletion.Parameters.Add(new KnownTypeMethodParameter() + { + Type = pair.Key, + Name = pair.Value, + IsLast = (i == symbol.Parameters.Count - 1) + }); + } + + data.Add(methodCompletion); } } @@ -1294,6 +1410,8 @@ namespace Tango.Scripting.Editors MethodDescription method = new MethodDescription(); method.ReturnType = session.Type.Name; method.Description = m.Summary; + method.Name = m.Name; + method.Class = session.Type.FriendlyName; //if (session.Type.Type.IsGenericType && session.TypeArguments != null) //{ @@ -1336,6 +1454,53 @@ namespace Tango.Scripting.Editors return popup; } + private MethodPopup CreateDeclaredMethodSessionPopupContent(DeclaredMethodSession session) + { + MethodPopup popup = new MethodPopup(); + + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Method.Type; + method.Description = session.Method.Summary; + method.Name = session.Method.Name; + method.Class = session.Method.Class; + + //if (session.Type.Type.IsGenericType && session.TypeArguments != null) + //{ + // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; + //} + + foreach (var p in session.Method.Parameters) + { + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Type = p.Key; + pDescription.Name = p.Value; + 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/Themes/Generic.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml index 1ab9dd2db..ce5cb39e1 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 @@ -311,6 +311,9 @@ + + . + ( @@ -337,6 +340,16 @@ + + + : 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 b0c18ce83..101bfdda3 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 @@ -2,7 +2,9 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using System.Linq; using System.Text; @@ -75,7 +77,7 @@ namespace Tango.Scripting.Parsing if (prop != null) { - vars.Add(new ScriptSymbol() + ScriptSymbol m = new ScriptSymbol() { Name = symbol.Name, Type = ReplaceFakeScript(prop.GetValue(symbol).ToString()), @@ -84,7 +86,11 @@ namespace Tango.Scripting.Parsing Accessibility = symbol.DeclaredAccessibility, ContainingNamespace = ReplaceFakeScript(symbol.ContainingNamespace?.Name), Summary = GetSymbolDocumentation(symbol), - }); + }; + + m.Parameters = GetMethodSymbolParameters(symbol); + + vars.Add(m); } } else @@ -186,7 +192,7 @@ namespace Tango.Scripting.Parsing if (symbolModel != null) { - scriptType.Symbols.Add(new ScriptSymbol() + ScriptSymbol m = new ScriptSymbol() { Class = scriptType.Name, Accessibility = symbolModel.DeclaredAccessibility, @@ -195,7 +201,14 @@ namespace Tango.Scripting.Parsing Type = symbolModel.ReturnType.ToString(), ContainingNamespace = symbolModel.ContainingNamespace?.Name, Summary = GetNodeDocumentation(symbol), - }); + }; + + foreach (var p in symbol.DescendantNodes().OfType()) + { + m.Parameters.Add(new KeyValuePair(p.Type.ToString(), p.Identifier.ToString())); + } + + scriptType.Symbols.Add(m); } } @@ -279,5 +292,48 @@ namespace Tango.Scripting.Parsing return "No documentation."; } + + private SyntaxNode GetSymbolSyntaxNode(ISymbol symbol) + { + if (symbol != null) + { + var prop = symbol.GetType().GetProperty("SyntaxNode"); + + if (prop != null) + { + var node = prop.GetValue(symbol) as SyntaxNode; + + return node; + } + } + + return null; + } + + private List> GetMethodSymbolParameters(ISymbol symbol) + { + List> parameters = new List>(); + + try + { + var prop = symbol.GetType().GetProperty("Parameters"); + + if (prop != null) + { + var array = prop.GetValue(symbol) as IEnumerable; + + foreach (var item in array) + { + var type = item.GetType().GetProperty("Type").GetValue(item).ToString(); + var value = item.GetType().GetProperty("Name").GetValue(item).ToString(); + + parameters.Add(new KeyValuePair(type, value)); + } + } + } + catch { } + + return parameters; + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs index 622ca4406..d6fdaeebf 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptSymbol.cs @@ -15,8 +15,14 @@ namespace Tango.Scripting.Parsing public String Class { get; set; } public Accessibility Accessibility { get; set; } public String ContainingNamespace { get; set; } + public List> Parameters { get; set; } public String Summary { get; set; } + public ScriptSymbol() + { + Parameters = new List>(); + } + public override string ToString() { return $"{Kind.ToString()} : {Type} : {Name}"; -- cgit v1.3.1 From 0a8e05dca474e11fbc27e2b446d82a941019b6c9 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 12 Mar 2019 01:13:16 +0200 Subject: Working on script engine. --- .../Intellisense/CompletionItem.cs | 3 +- .../Intellisense/KnownType.cs | 232 +++++++++++---------- .../Intellisense/KnownTypeMethod.cs | 18 ++ .../Intellisense/MethodCompletionItem.cs | 11 + .../Tango.Scripting.Editors/ScriptEditor.cs | 201 +++++++++--------- .../Tango.Scripting/Parsing/ScriptParser.cs | 37 +++- 6 files changed, 291 insertions(+), 211 deletions(-) (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') 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 index 83ada090f..c8beebd28 100644 --- 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 @@ -27,10 +27,11 @@ namespace Tango.Scripting.Editors.Intellisense public virtual void Complete(ScriptEditor editor) { + var word = editor.GetCurrentWord(); int index = editor.GetCurrentWordStartIndex(); int max = editor.GetCurrentLine().EndOffset; - editor.Document.Replace(index, Math.Min(max - index, Text.Length), Text); + editor.Document.Replace(index, word.Length,Text); } public abstract BitmapSource Image { get; } 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 06282e15d..7aec36a86 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 @@ -158,159 +158,161 @@ namespace Tango.Scripting.Editors.Intellisense } } - if (xmlDoc != null) - { - Task.Factory.StartNew(() => - { - - //Load Type Summary - { - string path = "T:" + Type.FullName; - XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); + xmlDoc = new XmlDocument(); - if (xmlDocuOfType != null) - { - XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); - Summary = summaryNode.InnerText; - } - } - - //Load Constructors... - { - string path = "M:" + Type.FullName + ".#ctor"; + //Load Type Summary + { + string path = "T:" + Type.FullName; + XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); - var constructors = Type.GetConstructors().Where(x => x.IsPublic).ToList(); + if (xmlDocuOfType != null) + { + XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); + Summary = summaryNode.InnerText; + } + } - for (int i = 0; i < constructors.Count; i++) - { - var constructor = constructors[i]; - XmlNode cDoc = null; + //Load Constructors... + { + string path = "M:" + Type.FullName + ".#ctor"; - if (i < docNodes.Count) - { - cDoc = docNodes[i]; - } + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + var constructors = Type.GetConstructors().Where(x => x.IsPublic).ToList(); - KnownTypeConstructor c = new KnownTypeConstructor(this); - c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerXml : $"Initializes a new instance of {FriendlyName}."; + for (int i = 0; i < constructors.Count; i++) + { + var constructor = constructors[i]; + XmlNode cDoc = null; - var parameters = constructor.GetParameters().ToList(); - var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType().ToList() : new List(); + if (i < docNodes.Count) + { + cDoc = docNodes[i]; + } - for (int j = 0; j < parameters.Count; j++) - { - var parameter = parameters[j]; - XmlNode pNode = null; + KnownTypeConstructor c = new KnownTypeConstructor(this); + c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerXml : $"Initializes a new instance of {FriendlyName}."; - if (j < parametersNodes.Count) - { - pNode = parametersNodes[j]; - } + var parameters = constructor.GetParameters().ToList(); + var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType().ToList() : new List(); - KnownTypeMethodParameter p = new KnownTypeMethodParameter(); - p.Type = parameter.ParameterType.GetFriendlyName(); - p.Name = parameter.Name; - p.Description = pNode != null ? pNode.InnerText : null; + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; + XmlNode pNode = null; - if (j == parameters.Count - 1) - { - p.IsLast = true; - } + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } - c.Parameters.Add(p); - } + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType.GetFriendlyName(); + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; - _constructors.Add(c); + if (j == parameters.Count - 1) + { + p.IsLast = true; } + + c.Parameters.Add(p); } - //Load Methods... - { - string path = "M:" + Type.FullName; + _constructors.Add(c); + } + } - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); - var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); + //Load Methods... + { + string path = "M:" + Type.FullName; - //TODO: Separate extension methods! - methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); - if (typeof(IEnumerable).IsAssignableFrom(Type)) - { - var linqMethods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList(); - methods.AddRange(linqMethods); - } + //TODO: Separate extension methods! + methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); - for (int i = 0; i < methods.Count; i++) - { - var method = methods[i]; - XmlNode mDoc = null; + if (typeof(IEnumerable).IsAssignableFrom(Type)) + { + var linqMethods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList(); + methods.AddRange(linqMethods); + } - mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); + for (int i = 0; i < methods.Count; i++) + { + var method = methods[i]; + XmlNode mDoc = null; - 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(); + mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); - var parameters = method.GetParameters().ToList(); - var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); + 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(); - bool isLinq = method.DeclaringType == typeof(Enumerable); + if (method.IsGenericMethod) + { + foreach (var lGenericArgument in method.GetGenericMethodDefinition().GetGenericArguments()) + { + m.TypeArguments.Add(lGenericArgument.Name); + } + } - for (int j = 0; j < parameters.Count; j++) - { - var parameter = parameters[j]; + var parameters = method.GetParameters().ToList(); + var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); - XmlNode pNode = null; + bool isLinq = method.DeclaringType == typeof(Enumerable); - if (j < parametersNodes.Count) - { - pNode = parametersNodes[j]; - } + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; - KnownTypeMethodParameter p = new KnownTypeMethodParameter(); - p.Type = parameter.ParameterType.GetFriendlyName(); - 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]; + } - if (j == 0 && isLinq) continue; - m.Parameters.Add(p); - } + KnownTypeMethodParameter p = new KnownTypeMethodParameter(); + p.Type = parameter.ParameterType.GetFriendlyName(); + p.Name = parameter.Name; + p.Description = pNode != null ? pNode.InnerText : null; - _methods.Add(m); + if (j == parameters.Count - 1) + { + p.IsLast = true; } + + if (j == 0 && isLinq) continue; + m.Parameters.Add(p); } - //Load Properties - { - string path = "P:" + Type.FullName; + _methods.Add(m); + } + } - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); - var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); + //Load Properties + { + string path = "P:" + Type.FullName; - 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)); + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); - 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(); + 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)); - _properties.Add(p); - } - } + 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); + } } _initialized = true; 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 0ae4b708e..767d49b7e 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 @@ -10,9 +10,27 @@ namespace Tango.Scripting.Editors.Intellisense { public List Parameters { get; set; } + public List TypeArguments { get; set; } + + public String NameWithTypeArguments + { + get + { + if (TypeArguments.Count == 0) + { + return Name; + } + else + { + return Name + $"<{String.Join(",", TypeArguments)}>"; + } + } + } + public KnownTypeMethod() { Parameters = new List(); + TypeArguments = new List(); } public KnownTypeMethod(KnownType knownType) : this() 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 index 0a0883ede..d2ee40920 100644 --- 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 @@ -28,6 +28,17 @@ namespace Tango.Scripting.Editors.Intellisense public List Parameters { get; set; } + public override void Complete(ScriptEditor editor) + { + base.Complete(editor); + + if (Text.Contains("")) + { + editor.CaretOffset -= 2; + editor.Select(editor.CaretOffset, 1); + } + } + public MethodCompletionItem() { Parameters = new List(); 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 e43322711..f6296ac5c 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 @@ -39,7 +39,7 @@ namespace Tango.Scripting.Editors { public class ScriptEditor : TextEditor { - private char[] word_separators = { ' ', '\t', '\n', '.', '(', ',', '-', '*', '/', '+', '$', '=' }; + private char[] word_separators = { ' ', '\t', '\n', '.', '(', ',', '-', '*', '/', '+', '$', '=', '<', '>' }; private string[] _blocking_type_words = { "class", "void" }; private DispatcherTimer _update_timer; @@ -51,6 +51,7 @@ namespace Tango.Scripting.Editors private List _current_usings; private List _knownTypes; private List _declaredTypes; + private bool _isLoadingTypes; #region Mini Classes @@ -151,6 +152,7 @@ namespace Tango.Scripting.Editors //Add basic assemblies... ReferenceAssemblies.Add(new ReferenceAssembly(typeof(String))); //mscorelib ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Enumerable))); //System.Core + ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Tango.Core.CoreSettings))); //System.Core _knownTypes = new List(); _parser = new ScriptParser(); @@ -400,7 +402,7 @@ namespace Tango.Scripting.Editors if (expression != null) { - var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "")).ToList(); + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); var variableName = tree.FirstOrDefault(); if (variableName != null && tree.Count > 1) @@ -523,103 +525,109 @@ namespace Tango.Scripting.Editors private void InvalidateHighlighting() { - _knownTypes.Clear(); + if (!_isLoadingTypes) + { + _isLoadingTypes = true; + _knownTypes.Clear(); - var assemblies = ReferenceAssemblies.ToList(); - var usings = _current_usings.ToList(); + var assemblies = ReferenceAssemblies.ToList(); + var usings = _current_usings.ToList(); - Thread t = new Thread(() => - { - 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)) { - if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + lock (_knownTypes) { - _knownTypes.Add(new KnownType(type)); + 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; - - Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); + }); + } - using (StreamReader reader = new StreamReader(xshd_stream)) + if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) { - text = reader.ReadToEnd(); - } + String text = String.Empty; - List referenceTypes = new List(); - List interfaceTypes = new List(); + Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); - lock (_knownTypes) - { - foreach (var type in _knownTypes.ToList().Where(x => x != null)) + using (StreamReader reader = new StreamReader(xshd_stream)) { - String name = type.Name; + text = reader.ReadToEnd(); + } + + List referenceTypes = new List(); + List interfaceTypes = new List(); - if (type.Type.ContainsGenericParameters) + lock (_knownTypes) + { + foreach (var type in _knownTypes.ToList().Where(x => x != null)) { - name = new String(name.TakeWhile(x => x != '`').ToArray()); + String name = type.Name; + + if (type.Type.ContainsGenericParameters) + { + name = new String(name.TakeWhile(x => x != '`').ToArray()); + } + + if (type.Type.IsInterface || type.Type.IsEnum) + { + interfaceTypes.Add(String.Format("{0}", name)); + } + else if (type.Type.IsClass) + { + referenceTypes.Add(String.Format("{0}", name)); + } } + } - if (type.Type.IsInterface || type.Type.IsEnum) + foreach (var type in _declaredTypes) + { + if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) { - interfaceTypes.Add(String.Format("{0}", name)); + interfaceTypes.Add(String.Format("{0}", type.Name)); } - else if (type.Type.IsClass) + else if (type.Kind == TypeKind.Class) { - referenceTypes.Add(String.Format("{0}", name)); + referenceTypes.Add(String.Format("{0}", type.Name)); } } - } - foreach (var type in _declaredTypes) - { - if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) + if (referenceTypes.Count > 0) { - interfaceTypes.Add(String.Format("{0}", type.Name)); + text = text.Replace("@ReferenceTypes@", String.Join(Environment.NewLine, referenceTypes.Distinct())); } - else if (type.Kind == TypeKind.Class) + + if (interfaceTypes.Count > 0) { - referenceTypes.Add(String.Format("{0}", type.Name)); + text = text.Replace("@InterfaceTypes@", String.Join(Environment.NewLine, interfaceTypes.Distinct())); } - } - if (referenceTypes.Count > 0) - { - text = text.Replace("@ReferenceTypes@", String.Join(Environment.NewLine, referenceTypes.Distinct())); - } - - if (interfaceTypes.Count > 0) - { - text = text.Replace("@InterfaceTypes@", String.Join(Environment.NewLine, interfaceTypes.Distinct())); - } + MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); - MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); + XmlTextReader xshd_reader = new XmlTextReader(ms); - XmlTextReader xshd_reader = new XmlTextReader(ms); + Dispatcher.BeginInvoke(new Action(() => + { + SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); + xshd_reader.Close(); + ms.Dispose(); + })); - Dispatcher.BeginInvoke(new Action(() => - { - SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); - xshd_reader.Close(); - ms.Dispose(); - })); + } - } - }); - t.IsBackground = true; - t.Start(); + _isLoadingTypes = false; + }); + t.IsBackground = true; + t.Start(); + } } private void InvalidateScriptTypesHighlightings() @@ -738,6 +746,10 @@ namespace Tango.Scripting.Editors CaretOffset = Document.GetLineByNumber(line.LineNumber + 1).EndOffset; } } + else if (e.Key == Key.End || e.Key == Key.Home) + { + HideCompletionWindow(); + } } #endregion @@ -797,38 +809,36 @@ namespace Tango.Scripting.Editors var typeMembers = knownType.Members.ToList(); - foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) + foreach (var methodGroup in typeMembers.OfType().GroupBy(x => x.NameWithTypeArguments)) { - var member = methodGroup.First(); + var method = methodGroup.First(); - if (member.GetType() == typeof(KnownTypeMethod)) + data.Add(new MethodCompletionItem() { - var method = member as KnownTypeMethod; + Class = knownType.FriendlyName, + Name = method.NameWithTypeArguments, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); + } - data.Add(new MethodCompletionItem() - { - Class = knownType.FriendlyName, - Name = method.Name, - ReturnType = method.ReturnTypeFriendlyName, - Description = method.Summary, - Parameters = method.Parameters, - Overloads = methodGroup.Count() - 1, - }); + foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) + { + var member = methodGroup.First(); - } - else + data.Add(new PropertyCompletionItem() { - data.Add(new PropertyCompletionItem() - { - Class = knownType.FriendlyName, - Name = member.Name, - Type = member.ReturnTypeFriendlyName, - Description = member.Summary, - }); - } + Class = knownType.FriendlyName, + Name = member.Name, + Type = member.ReturnTypeFriendlyName, + Description = member.Summary, + }); + } - ShowCompletionWindow(data, GetCurrentWord()); + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } else { @@ -855,7 +865,7 @@ namespace Tango.Scripting.Editors Description = member.Summary, Overloads = methodGroup.Count() - 1, }; - + for (int i = 0; i < member.Parameters.Count; i++) { @@ -971,7 +981,7 @@ namespace Tango.Scripting.Editors ShowCompletionWindow(data, GetCurrentWord()); } - else if (!currentWordIncludingParenthesis.Contains(".")) + else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') { if (completionWindow.IsVisible) { @@ -982,6 +992,11 @@ namespace Tango.Scripting.Editors var previous_word = GetPreviousWord(); var word = GetCurrentWord(); + if (word.Contains("<")) + { + word = word.Last(x => x != '<').ToString(); + } + if (previous_word != word) { if (_knownTypes.Exists(x => x.Name == previous_word)) @@ -1410,7 +1425,7 @@ namespace Tango.Scripting.Editors MethodDescription method = new MethodDescription(); method.ReturnType = session.Type.Name; method.Description = m.Summary; - method.Name = m.Name; + method.Name = m.NameWithTypeArguments; method.Class = session.Type.FriendlyName; //if (session.Type.Type.IsGenericType && session.TypeArguments != null) 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 101bfdda3..508801037 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 @@ -71,6 +71,36 @@ namespace Tango.Scripting.Parsing foreach (var symbol in symbols.DistinctBy(x => x.Name)) { + if (symbol.ContainingSymbol.GetType().Name == "LambdaSymbol") + { + var invocationNode = currentNode.Ancestors().OfType().FirstOrDefault(); + + if (invocationNode != null) + { + var expressionNode = invocationNode.Expression as MemberAccessExpressionSyntax; + + if (expressionNode != null && expressionNode.Name != null) + { + var name = expressionNode.Name as GenericNameSyntax; + + if (name != null) + { + var type = name.TypeArgumentList.Arguments.FirstOrDefault()?.ToString(); + + vars.Add(new ScriptSymbol() + { + Name = symbol.Name, + Type = ReplaceFakeScript(type), + Class = ReplaceFakeScript(symbol.ContainingType?.Name), + Kind = symbol.Kind, + Accessibility = symbol.DeclaredAccessibility, + ContainingNamespace = ReplaceFakeScript(symbol.ContainingNamespace?.Name), + Summary = GetSymbolDocumentation(symbol), + }); + } + } + } + } if (symbol.Kind == SymbolKind.Method) { var prop = symbol.GetType().GetProperty("ReturnType"); @@ -113,7 +143,7 @@ namespace Tango.Scripting.Parsing } } - return vars; + return vars.Where(x => x.Type != "?").ToList(); } public List GetUsings(String code) @@ -205,7 +235,10 @@ namespace Tango.Scripting.Parsing foreach (var p in symbol.DescendantNodes().OfType()) { - m.Parameters.Add(new KeyValuePair(p.Type.ToString(), p.Identifier.ToString())); + if (p.Type != null && p.Identifier != null) + { + m.Parameters.Add(new KeyValuePair(p.Type.ToString(), p.Identifier.ToString())); + } } scriptType.Symbols.Add(m); -- cgit v1.3.1 From ec4b039d1d72742943f67725dd3f2622d576c28b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 16 Mar 2019 01:27:14 +0200 Subject: Refactored known type doc reading. Added support for enum values. --- .../Intellisense/KnownType.cs | 192 +++++---------------- .../Intellisense/KnownTypeConstructor.cs | 1 + .../Intellisense/KnownTypeField.cs | 21 +++ .../Intellisense/KnownTypeMember.cs | 2 +- .../Intellisense/KnownTypeMethod.cs | 1 + .../Intellisense/KnownTypeProperty.cs | 2 +- .../Tango.Scripting.Editors/Intellisense/Utils.cs | 171 ++++++++++++++++++ .../Tango.Scripting.Editors/ScriptEditor.cs | 112 +++++++++--- .../Tango.Scripting.Editors.csproj | 4 +- .../Tango.Scripting/Parsing/ScriptParser.cs | 8 + 10 files changed, 339 insertions(+), 175 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeField.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') 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 7aec36a86..28f9ccb9a 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 @@ -7,66 +7,23 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Xml; +using Tango.Core; namespace Tango.Scripting.Editors.Intellisense { public class KnownType { - private static String dotNetXmlFolder = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.X"; - private static Dictionary _assemblies_docs_cache; - private bool _initialized; + private bool _documentationLoaded; public Type Type { get; private set; } public String Name { get; private set; } public String TypeDefinition { get; private set; } public String FriendlyName { get; private set; } - - private String _summary; - public String Summary - { - get - { - InitTypeDocumentation(); - return _summary; - } - private set { _summary = value; } - } - - - private List _constructors; - public List Constructors - { - get - { - InitTypeDocumentation(); - return _constructors; - } - private set { _constructors = value; } - } - - private List _methods; - public List Methods - { - get - { - InitTypeDocumentation(); - return _methods; - } - private set { _methods = value; } - } - - private List _properties; - public List Properties - { - get - { - InitTypeDocumentation(); - return _properties; - } - private set { _properties = value; } - } - + public String Summary { get; set; } + public List Constructors { get; set; } + public List Methods { get; set; } + public List Properties { get; set; } public List Members { get @@ -79,18 +36,15 @@ namespace Tango.Scripting.Editors.Intellisense return members.OrderBy(x => x.Name).ToList(); } } - - static KnownType() - { - _assemblies_docs_cache = new Dictionary(); - } + public List Fields { get; set; } public KnownType(Type type) { - _summary = "Loading documentation..."; - _constructors = new List(); - _methods = new List(); - _properties = new List(); + Summary = "Loading documentation..."; + Constructors = new List(); + Methods = new List(); + Properties = new List(); + Fields = new List(); Type = type; Name = type.Name; @@ -106,7 +60,7 @@ namespace Tango.Scripting.Editors.Intellisense { InitTypeDefinition(); InitFriendlyName(); - InitTypeDocumentation(); + InitType(); } private void InitFriendlyName() @@ -122,93 +76,31 @@ namespace Tango.Scripting.Editors.Intellisense else if (Type.IsValueType) TypeDefinition = "struct"; } - private void InitTypeDocumentation() + private void InitType() { if (!_initialized) { _initialized = true; - XmlDocument xmlDoc = null; - - if (_assemblies_docs_cache.ContainsKey(Type.Assembly)) - { - xmlDoc = _assemblies_docs_cache[Type.Assembly]; - } - - if (xmlDoc == null) - { - String dllPath = Type.Assembly.Location; - - string docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML"; - - if (File.Exists(docuPath)) - { - xmlDoc = new XmlDocument(); - xmlDoc.Load(docuPath); - } - else if (File.Exists(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath)))) - { - xmlDoc = new XmlDocument(); - xmlDoc.Load(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath))); - } - - if (xmlDoc != null) - { - _assemblies_docs_cache.Add(Type.Assembly, xmlDoc); - } - } - - xmlDoc = new XmlDocument(); - - //Load Type Summary - { - string path = "T:" + Type.FullName; - XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); - - if (xmlDocuOfType != null) - { - XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); - Summary = summaryNode.InnerText; - } - } - //Load Constructors... { - string path = "M:" + Type.FullName + ".#ctor"; - - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().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) - { - cDoc = docNodes[i]; - } KnownTypeConstructor c = new KnownTypeConstructor(this); - c.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerXml : $"Initializes a new instance of {FriendlyName}."; var parameters = constructor.GetParameters().ToList(); - var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType().ToList() : new List(); for (int j = 0; j < parameters.Count; j++) { var parameter = parameters[j]; - XmlNode pNode = null; - - 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) { @@ -218,15 +110,12 @@ namespace Tango.Scripting.Editors.Intellisense c.Parameters.Add(p); } - _constructors.Add(c); + Constructors.Add(c); } } //Load Methods... { - string path = "M:" + Type.FullName; - - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); //TODO: Separate extension methods! @@ -241,12 +130,8 @@ namespace Tango.Scripting.Editors.Intellisense for (int i = 0; i < methods.Count; i++) { var method = methods[i]; - XmlNode mDoc = null; - - mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(method.DeclaringType.Name + "." + method.Name)); 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(); @@ -260,7 +145,6 @@ namespace Tango.Scripting.Editors.Intellisense } var parameters = method.GetParameters().ToList(); - var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); bool isLinq = method.DeclaringType == typeof(Enumerable); @@ -268,17 +152,9 @@ namespace Tango.Scripting.Editors.Intellisense { var parameter = parameters[j]; - XmlNode pNode = null; - - 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) { @@ -289,34 +165,58 @@ namespace Tango.Scripting.Editors.Intellisense m.Parameters.Add(p); } - _methods.Add(m); + Methods.Add(m); } } //Load Properties { - string path = "P:" + Type.FullName; - - var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().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)); 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); + } + } + + //Load Enum Values + { + if (Type.IsEnum) + { + var values = Enum.GetNames(Type).ToList(); + + for (int i = 0; i < values.Count; i++) + { + var value = values[i]; + + KnownTypeField f = new KnownTypeField(this); + f.Name = value; + f.ReturnType = typeof(Int32); + f.ReturnTypeFriendlyName = typeof(Int32).Name; + Fields.Add(f); + } } } _initialized = true; } } + + public void LoadDocumentation() + { + if (!_documentationLoaded) + { + _documentationLoaded = true; + + Utils.LoadKnownTypeDocs(this); + } + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs index 273d61084..83dc3f750 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeConstructor.cs @@ -16,6 +16,7 @@ namespace Tango.Scripting.Editors.Intellisense public KnownTypeConstructor() { + Summary = "Loading documentation..."; Parameters = new List(); } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeField.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeField.cs new file mode 100644 index 000000000..cd1349744 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeField.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 KnownTypeField : KnownTypeMember + { + public KnownTypeField() + { + Summary = "Loading documentation..."; + } + + public KnownTypeField(KnownType knownType) : this() + { + Type = knownType; + } + } +} 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 1405a8c34..bae4edf41 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 @@ -20,7 +20,7 @@ namespace Tango.Scripting.Editors.Intellisense public KnownTypeMember() { - + Summary = "Loading documentation..."; } public KnownTypeMember(KnownType knownType) : this() 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 767d49b7e..f84e26fe5 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 @@ -29,6 +29,7 @@ namespace Tango.Scripting.Editors.Intellisense public KnownTypeMethod() { + Summary = "Loading documentation..."; Parameters = new List(); TypeArguments = new List(); } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs index a77dd7dc2..52717579a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeProperty.cs @@ -10,7 +10,7 @@ namespace Tango.Scripting.Editors.Intellisense { public KnownTypeProperty() { - + Summary = "Loading documentation..."; } public KnownTypeProperty(KnownType knownType) : this() diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs new file mode 100644 index 000000000..e30d0e37e --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace Tango.Scripting.Editors.Intellisense +{ + public static class Utils + { + private static String dotNetXmlFolder = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.X"; + private static Dictionary _assemblies_docs_cache; + + static Utils() + { + _assemblies_docs_cache = new Dictionary(); + } + + public static void LoadKnownTypeDocs(KnownType knownType) + { + XmlDocument xmlDoc = null; + + if (_assemblies_docs_cache.ContainsKey(knownType.Type.Assembly)) + { + xmlDoc = _assemblies_docs_cache[knownType.Type.Assembly]; + } + + if (xmlDoc == null) + { + String dllPath = knownType.Type.Assembly.Location; + + string docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML"; + + if (File.Exists(docuPath)) + { + xmlDoc = new XmlDocument(); + xmlDoc.Load(docuPath); + } + else if (File.Exists(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath)))) + { + xmlDoc = new XmlDocument(); + xmlDoc.Load(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath))); + } + + if (xmlDoc != null) + { + _assemblies_docs_cache.Add(knownType.Type.Assembly, xmlDoc); + } + } + + if (xmlDoc == null) + { + xmlDoc = new XmlDocument(); + } + + //Load Type Summary + { + string path = "T:" + knownType.Type.FullName; + XmlNode xmlDocuOfType = xmlDoc.SelectSingleNode("//member[starts-with(@name, '" + path + "')]"); + + if (xmlDocuOfType != null) + { + XmlNode summaryNode = xmlDocuOfType.SelectSingleNode("summary"); + knownType.Summary = summaryNode.InnerText; + } + } + + //Load Constructors... + { + string path = "M:" + knownType.Type.FullName + ".#ctor"; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + + for (int i = 0; i < knownType.Constructors.Count; i++) + { + var constructor = knownType.Constructors[i]; + XmlNode cDoc = null; + + if (i < docNodes.Count) + { + cDoc = docNodes[i]; + } + + constructor.Summary = cDoc != null ? cDoc.SelectSingleNode("summary").InnerXml : $"Initializes a new instance of {knownType.FriendlyName}."; + + var parameters = constructor.Parameters.ToList(); + var parametersNodes = cDoc != null ? cDoc.SelectNodes("param").OfType().ToList() : new List(); + + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; + XmlNode pNode = null; + + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } + + parameter.Description = pNode != null ? pNode.InnerText : null; + } + } + } + + //Load Methods... + { + string path = "M:" + knownType.Type.FullName; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + + for (int i = 0; i < knownType.Methods.Count; i++) + { + var method = knownType.Methods[i]; + XmlNode mDoc = null; + + mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(knownType.Type.Name + "." + method.Name)); + method.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + + var parameters = method.Parameters.ToList(); + var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); + + bool isLinq = knownType.Type == typeof(Enumerable); + + for (int j = 0; j < parameters.Count; j++) + { + var parameter = parameters[j]; + + XmlNode pNode = null; + + if (j < parametersNodes.Count) + { + pNode = parametersNodes[j]; + } + + parameter.Description = pNode != null ? pNode.InnerText : null; + } + } + } + + //Load Properties + { + string path = "P:" + knownType.Type.FullName; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType().ToList(); + + for (int i = 0; i < knownType.Properties.Count; i++) + { + 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"; + } + } + + //Load Enum Values + { + if (knownType.Type.IsEnum) + { + for (int i = 0; i < knownType.Fields.Count; i++) + { + 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"; + } + } + } + } + } +} 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 f6296ac5c..71b836f36 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 @@ -248,6 +248,7 @@ namespace Tango.Scripting.Editors public void IndentCode() { Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); + //Text = _parser.IndentCSharpCode(Text); } /// @@ -516,7 +517,7 @@ namespace Tango.Scripting.Editors { var currentLine = GetCurrentLine(); var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); - return currentText.Split(' ').ToList(); + return currentText.Split(' ',',').ToList(); } #endregion @@ -581,7 +582,7 @@ namespace Tango.Scripting.Editors { interfaceTypes.Add(String.Format("{0}", name)); } - else if (type.Type.IsClass) + else if (type.Type.IsClass || (type.Type.IsValueType)) { referenceTypes.Add(String.Format("{0}", name)); } @@ -621,6 +622,11 @@ namespace Tango.Scripting.Editors ms.Dispose(); })); + + foreach (var knownType in _knownTypes) + { + knownType.LoadDocumentation(); + } } _isLoadingTypes = false; @@ -775,7 +781,32 @@ namespace Tango.Scripting.Editors if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; - if (e.Text == " " && GetPreviousWord() == "new") + if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") + { + var expression = previousWords.First(); + var knownType = GetKnownTypeFromExpression(expression + "."); + + if (knownType != null && knownType.Type.IsEnum) + { + completionWindow.HideCompletion(); + IList data = new List(); + + foreach (var field in knownType.Fields) + { + data.Add(new FieldCompletionItem() + { + Class = knownType.FriendlyName, + Name = knownType.FriendlyName + "." + field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, + }); + } + + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); + } + + } + else if (e.Text == " " && GetPreviousWord() == "new") { var s = _parser.GetExpressionFirst(GetCurrentLineText()); @@ -807,35 +838,52 @@ namespace Tango.Scripting.Editors completionWindow.HideCompletion(); IList data = new List(); - var typeMembers = knownType.Members.ToList(); - - foreach (var methodGroup in typeMembers.OfType().GroupBy(x => x.NameWithTypeArguments)) + if (!knownType.Type.IsEnum) { - var method = methodGroup.First(); + var typeMembers = knownType.Members.ToList(); - data.Add(new MethodCompletionItem() + foreach (var methodGroup in typeMembers.OfType().GroupBy(x => x.NameWithTypeArguments)) { - Class = knownType.FriendlyName, - Name = method.NameWithTypeArguments, - ReturnType = method.ReturnTypeFriendlyName, - Description = method.Summary, - Parameters = method.Parameters, - Overloads = methodGroup.Count() - 1, - }); - } + var method = methodGroup.First(); - foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) - { - var member = methodGroup.First(); + data.Add(new MethodCompletionItem() + { + Class = knownType.FriendlyName, + Name = method.NameWithTypeArguments, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); + } - data.Add(new PropertyCompletionItem() + foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) { - Class = knownType.FriendlyName, - Name = member.Name, - Type = member.ReturnTypeFriendlyName, - Description = member.Summary, - }); + var member = methodGroup.First(); + + data.Add(new PropertyCompletionItem() + { + Class = knownType.FriendlyName, + Name = member.Name, + Type = member.ReturnTypeFriendlyName, + Description = member.Summary, + }); + + } + } + else + { + foreach (var field in knownType.Fields) + { + data.Add(new FieldCompletionItem() + { + Class = knownType.FriendlyName, + Name = field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, + }); + } } ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); @@ -1062,7 +1110,7 @@ namespace Tango.Scripting.Editors } } - foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) + foreach (var type in _knownTypes.ToList().Where(x => x.Name.StartsWith(word))) { if (type.Type.IsEnum) { @@ -1251,7 +1299,11 @@ namespace Tango.Scripting.Editors private KnownType GetCurrentKnownType() { var expression = GetPreviousWords().LastOrDefault(); + return GetKnownTypeFromExpression(expression); + } + private KnownType GetKnownTypeFromExpression(String expression) + { if (expression != null) { var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); @@ -1259,6 +1311,14 @@ namespace Tango.Scripting.Editors if (variableName != null) { + //Search for enum type first + var enumType = _knownTypes.FirstOrDefault(x => x.Name == variableName && x.Type.IsEnum); + + if (enumType != null) + { + return enumType; + } + tree.RemoveAt(0); var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); var variable = variables.FirstOrDefault(x => x.Name == variableName); 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 8b213a870..de8308271 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 @@ -336,6 +336,7 @@ + @@ -349,6 +350,7 @@ + @@ -622,7 +624,7 @@ - + \ No newline at end of file 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 508801037..f022f7999 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 @@ -368,5 +368,13 @@ namespace Tango.Scripting.Parsing return parameters; } + + public String IndentCSharpCode(String code) + { + var tree = CSharpSyntaxTree.ParseText(code); + var root = tree.GetRoot().NormalizeWhitespace(); + var ret = root.ToFullString(); + return ret; + } } } -- cgit v1.3.1 From c1c1e12fd3f0d89752b42d890ac43678bf9e7d69 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 16 Mar 2019 11:53:31 +0200 Subject: More work on script editor. --- .../Tango.Scripting.Editors/Intellisense/Utils.cs | 4 +- .../Tango.Scripting.Editors/ScriptEditor.cs | 2002 ++++++++++---------- .../Tango.Scripting/Parsing/ScriptParser.cs | 2 + 3 files changed, 1012 insertions(+), 996 deletions(-) (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs index e30d0e37e..f8cc7072d 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs @@ -116,7 +116,7 @@ namespace Tango.Scripting.Editors.Intellisense XmlNode mDoc = null; mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(knownType.Type.Name + "." + method.Name)); - method.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + method.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml.Remove("()") : "No documentation"; var parameters = method.Parameters.ToList(); var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType().ToList() : new List(); @@ -134,7 +134,7 @@ namespace Tango.Scripting.Editors.Intellisense pNode = parametersNodes[j]; } - parameter.Description = pNode != null ? pNode.InnerText : null; + parameter.Description = pNode != null ? pNode.InnerText.Remove("()") : null; } } } 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 71b836f36..efa1b087a 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 @@ -72,6 +72,7 @@ namespace Tango.Scripting.Editors { public KnownType Type { get; set; } public String MethodName { get; set; } + public int ParameterIndex { get; set; } } private class DeclaredMethodSession @@ -210,1115 +211,1265 @@ namespace Tango.Scripting.Editors #endregion - #region Public Methods + #region Override Methods /// - /// Invalidates all using statements in the script. + /// Invoked when an unhandled  attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// - public void InvalidateUsings() + /// The that contains the event data. + protected override void OnPreviewKeyDown(KeyEventArgs e) { - var oldUsings = _current_usings.ToList(); - _current_usings = _parser.GetUsings(Text); - - if (_current_usings.Exists(x => !oldUsings.Exists(y => y == x)) || oldUsings.Exists(x => !_current_usings.Exists(y => y == x))) + if (CurrentPopupContent is MethodPopup && (e.Key == Key.Down || e.Key == Key.Up)) { - InvalidateHighlighting(); - } - } + e.Handled = true; - /// - /// Invalidates the script folding if enabled. - /// - public void InvalidateFolding() - { - if (EnableFolding) - { - if (foldingManager == null) + if (e.Key == Key.Down) { - foldingManager = FoldingManager.Install(TextArea); + (CurrentPopupContent as MethodPopup).IncrementMethod(); + } + else if (e.Key == Key.Up) + { + (CurrentPopupContent as MethodPopup).DecrementMethod(); } - foldingStrategy.UpdateFoldings(foldingManager, Document); + return; } - } - /// - /// Indents the code. - /// - public void IndentCode() - { - Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); - //Text = _parser.IndentCSharpCode(Text); + base.OnPreviewKeyDown(e); + HidePopup(); + HandleKeyCombinations(e); } - /// - /// Gets the current line. - /// - /// - public DocumentLine GetCurrentLine() - { - int offset = CaretOffset; - var line = Document.GetLineByOffset(offset); - return line; - } + #endregion - /// - /// Gets the current line text. - /// - /// - public String GetCurrentLineText() - { - var text = Document.GetText(GetCurrentLine()); - return text; - } + #region Apply Template - /// - /// Gets the current word. - /// - /// - public String GetCurrentWord() + public override void OnApplyTemplate() { - return GetWordByEndIndex(CaretOffset); + base.OnApplyTemplate(); + + _popup = GetTemplateChild("PART_popup") as Popup; } - public String GetWordByEndIndex(int index) - { - String word = String.Empty; - var line = GetCurrentLine(); + #endregion - int position = index; + #region Key Combination Handling - for (int i = position - 1; i >= line.Offset; i--) + /// + /// Handles the key combinations. + /// + /// The instance containing the event data. + private void HandleKeyCombinations(KeyEventArgs e) + { + if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.K) && Keyboard.IsKeyDown(Key.D)) { - char c = Document.GetText(i, 1).First(); - - if (word_separators.Contains(c)) + try { - break; + int index = CaretOffset; + Document.BeginUpdate(); + IndentCode(); + Document.EndUpdate(); + e.Handled = true; + CaretOffset = index; + } + catch + { + Debug.WriteLine("Error indenting code."); } - - word += c; } + else if (e.Key == Key.Oem2) + { + int offset = CaretOffset; + var line = Document.GetLineByOffset(offset); - word = new string(word.Reverse().ToArray()); - - if (word.Length > 0) + String text = GetCurrentLineText(); + if (text.TrimStart('\t', ' ').StartsWith("//")) + { + Document.BeginUpdate(); + Document.Replace(line, "/// \n/// \n/// "); + Document.EndUpdate(); + e.Handled = true; + CaretOffset = Document.GetLineByNumber(line.LineNumber + 1).EndOffset; + } + } + else if (e.Key == Key.End || e.Key == Key.Home) { - word = word.Replace(".", ""); + HideCompletionWindow(); } - - return word; } - public int GetCurrentWordStartIndex() + #endregion + + #region Text Entered + + private void TextArea_TextEntered(object sender, TextCompositionEventArgs e) { - var line = GetCurrentLine(); + List items = new List(); - int position = CaretOffset; + HidePopup(); - for (int i = position - 1; i >= line.Offset; i--) + var lineText = GetCurrentLineText(); + var previousWords = GetPreviousWords(); + var previousWordsLast = previousWords.LastOrDefault(); + String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; + String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); + + if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; + + if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") { - char c = Document.GetText(i, 1).First(); + var expression = previousWords.First(); + var knownType = GetKnownTypeFromExpression(expression + "."); - if (word_separators.Contains(c)) + if (knownType != null && knownType.Type.IsEnum) { - return i + 1; + completionWindow.HideCompletion(); + IList data = new List(); + + foreach (var field in knownType.Fields) + { + data.Add(new FieldCompletionItem() + { + Class = knownType.FriendlyName, + Name = knownType.FriendlyName + "." + field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, + }); + } + + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } + } + else if (e.Text == " " && GetPreviousWord() == "new") + { + var s = _parser.GetExpressionFirst(GetCurrentLineText()); - return line.Offset; - } + if (s != null) + { + String type = s.Declaration.Type.ToString(); - public String GetPreviousWord() - { - int index = GetCurrentWordStartIndex() - 1; - return GetWordByEndIndex(index); - } + IList data = new List(); - private ConstructionSession GetConstructionSession() - { - var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); + data.Add(new ClassCompletionItem() + { + Name = type, + Description = "Auto generate assignment...", + }); - if (expression != null) + ShowCompletionWindow(data, type); + } + } + else if (e.Text == ";" || e.Text == " ") { - ConstructionSession session = new ConstructionSession(); + HideCompletionWindow(); + } + else if (e.Text == ".") + { + var knownType = GetCurrentKnownType(); - var line = GetCurrentLine(); - int parameterIndex = 0; - for (int i = CaretOffset; i > line.Offset; i--) + if (knownType != null) { - String c = Document.GetText(i, 1); + completionWindow.HideCompletion(); + IList data = new List(); - if (c == "(") + if (!knownType.Type.IsEnum) { - var typeDeclaration = expression.Type as GenericNameSyntax; - - KnownType type = null; + var typeMembers = knownType.Members.ToList(); - if (typeDeclaration != null) + foreach (var methodGroup in typeMembers.OfType().GroupBy(x => x.NameWithTypeArguments)) { - var typeName = typeDeclaration.Identifier.ToString(); - var argumentsCount = typeDeclaration.TypeArgumentList.Arguments.Count; - session.TypeArguments = typeDeclaration.TypeArgumentList.Arguments.Select(x => x.ToString()).ToList(); + var method = methodGroup.First(); - if (argumentsCount == 0) - { - type = _knownTypes.FirstOrDefault(x => x.Type.Name == expression.Type.ToString()); - } - else + data.Add(new MethodCompletionItem() { - type = _knownTypes.FirstOrDefault(x => x.Type.Name == typeName + "`" + argumentsCount); - } - } - else - { - type = _knownTypes.FirstOrDefault(x => x.Name == expression.Type.ToString()); + Class = knownType.FriendlyName, + Name = method.NameWithTypeArguments, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); } - if (type != null) - { - session.Type = type; - session.ParameterIndex = parameterIndex; - return session; - } - else + foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) { - return null; + var member = methodGroup.First(); + + data.Add(new PropertyCompletionItem() + { + Class = knownType.FriendlyName, + Name = member.Name, + Type = member.ReturnTypeFriendlyName, + Description = member.Summary, + }); + } } - else if (c == ",") + else { - parameterIndex++; + foreach (var field in knownType.Fields) + { + data.Add(new FieldCompletionItem() + { + Class = knownType.FriendlyName, + Name = field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, + }); + + } } + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } - } - - return null; - } - - private MethodSession GetMethodSession() - { - var expression = GetPreviousWords().LastOrDefault(); - - if (expression != null) - { - var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); - var variableName = tree.FirstOrDefault(); - - if (variableName != null && tree.Count > 1) + else { - tree.RemoveAt(0); - var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); - var variable = variables.FirstOrDefault(x => x.Name == variableName); + var declaredType = GetCurrentDeclaredType(); - if (variable != null) + if (declaredType != null) { - var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "")); + completionWindow.HideCompletion(); + IList data = new List(); - if (knownType != null) + var typeMembers = declaredType.Symbols.ToList(); + + foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) { - while (tree.Count > 1) + var member = methodGroup.First(); + + if (member.Kind == SymbolKind.Method) { - var memberName = tree.First(); - tree.RemoveAt(0); - var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + var methodCompletion = new MethodCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + ReturnType = member.Type, + Description = member.Summary, + Overloads = methodGroup.Count() - 1, + }; - if (member == null) + + for (int i = 0; i < member.Parameters.Count; i++) { - return null; + var pair = member.Parameters[i]; + + methodCompletion.Parameters.Add(new KnownTypeMethodParameter() + { + Type = pair.Key, + Name = pair.Value, + IsLast = (i == member.Parameters.Count - 1) + }); } - knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); - } + data.Add(methodCompletion); - return new MethodSession() + } + else if (member.Kind == SymbolKind.Property) { - Type = knownType, - MethodName = tree.Last(), - }; + data.Add(new PropertyCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } + else if (member.Kind == SymbolKind.Field) + { + data.Add(new FieldCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } } + + ShowCompletionWindow(data, GetCurrentWord()); } } } - - return null; - } - - private DeclaredMethodSession GetDeclaredMethodSession() - { - var expression = GetPreviousWords().LastOrDefault(); - - if (expression != null) + else if (e.Text == "(" || e.Text == ",") { - var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "")).ToList(); - var variableName = tree.FirstOrDefault(); + completionWindow.HideCompletion(); - if (variableName != null && tree.Count > 0) + try { - tree.RemoveAt(0); - var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); - var variable = variables.FirstOrDefault(x => x.Name == variableName); + var session = GetConstructionSession(); - if (variable != null) + if (session != null) { - var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Class, "<.+>", "")); - - if (declaredType != null) + var content = CreateConstructionSessionPopupContent(session); + if (content.Methods.Count > 0) { - while (tree.Count > 1) - { - var memberName = tree.First(); - tree.RemoveAt(0); - var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName); - - if (member == null) - { - return null; - } + ShowPopup(content); + return; + } + } - declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type); - } + var methodSession = GetMethodSession(); - var methodName = tree.Count > 0 ? tree.Last() : variableName; + if (methodSession != null) + { + var content = CreateMethodSessionPopupContent(methodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; + } + } - var method = declaredType.Symbols.FirstOrDefault(x => x.Kind == SymbolKind.Method && x.Name == methodName); + var declaredMethodSession = GetDeclaredMethodSession(); - if (method != null) - { - return new DeclaredMethodSession() - { - Type = declaredType, - Method = method, - }; - } - } - else if (tree.Count == 0) + if (declaredMethodSession != null) + { + var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession); + if (content.Methods.Count > 0) { - var method = variable; - - if (method != null) - { - return new DeclaredMethodSession() - { - Type = declaredType, - Method = method, - }; - } + ShowPopup(content); + return; } } } + catch (Exception ex) + { + Debug.WriteLine(ex); + } } + else if (lineText.StartsWith("using")) + { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } - return null; - } + IList data = new List(); - public List GetPreviousWords() - { - var currentLine = GetCurrentLine(); - var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); - return currentText.Split(' ',',').ToList(); - } + foreach (var asm in ReferenceAssemblies) + { + foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) + { + data.Add(new NamespaceCompletionItem() + { + Name = ns, + Assembly = asm.Assembly.GetName().Name, + }); + } + } - #endregion + data = data.DistinctBy(x => x.Text).ToList(); - #region Highlighting + ShowCompletionWindow(data, GetCurrentWord()); + } + else if (e.Text == "{") + { + int parentesisCount = lineText.TakeWhile(x => x != '{').Count(x => x == '\"'); - private void InvalidateHighlighting() - { - if (!_isLoadingTypes) + if (parentesisCount % 2 == 0) + { + Document.Insert(CaretOffset, "}"); + CaretOffset--; + } + } + else if (e.Text == "}") { - _isLoadingTypes = true; - _knownTypes.Clear(); + if (Document.GetText(CaretOffset - 2, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") + { + Document.Replace(CaretOffset, 1, ""); + } + } + else if (e.Text == "\n") + { + if (Document.GetText(CaretOffset - 3, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") + { + CaretOffset--; + Document.Insert(CaretOffset, "\n\t"); + } + } + else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') + { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } - var assemblies = ReferenceAssemblies.ToList(); - var usings = _current_usings.ToList(); + var previous_word = GetPreviousWord(); + var word = GetCurrentWord(); - Thread t = new Thread(() => + if (word.Contains("<")) { - foreach (var asm in assemblies.Select(x => x.Assembly)) + word = word.Last(x => x != '<').ToString(); + } + + if (previous_word != word) + { + if (_knownTypes.Exists(x => x.Name == previous_word)) { - Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => - { - if (usings.Exists(x => type.Namespace == x)) - { - lock (_knownTypes) - { - if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) - { - _knownTypes.Add(new KnownType(type)); - } - } - } - }); + return; } - if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) + if (_blocking_type_words.Contains(previous_word)) { - String text = String.Empty; + return; + } + } - Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); + if (!String.IsNullOrWhiteSpace(word)) + { + IList data = new List(); - using (StreamReader reader = new StreamReader(xshd_stream)) + foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) + { + if (type.Kind == TypeKind.Struct) { - text = reader.ReadToEnd(); + data.Add(new StructCompletionItem() + { + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); } - - List referenceTypes = new List(); - List interfaceTypes = new List(); - - lock (_knownTypes) + else if (type.Kind == TypeKind.Enum) { - foreach (var type in _knownTypes.ToList().Where(x => x != null)) + data.Add(new EnumCompletionItem() { - String name = type.Name; - - if (type.Type.ContainsGenericParameters) - { - name = new String(name.TakeWhile(x => x != '`').ToArray()); - } - - if (type.Type.IsInterface || type.Type.IsEnum) - { - interfaceTypes.Add(String.Format("{0}", name)); - } - else if (type.Type.IsClass || (type.Type.IsValueType)) - { - referenceTypes.Add(String.Format("{0}", name)); - } - } + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); } - - foreach (var type in _declaredTypes) + else if (type.Kind == TypeKind.Interface) { - if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) + data.Add(new InterfaceCompletionItem() { - interfaceTypes.Add(String.Format("{0}", type.Name)); - } - else if (type.Kind == TypeKind.Class) + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); + } + else if (type.Kind == TypeKind.Class) + { + data.Add(new ClassCompletionItem() { - referenceTypes.Add(String.Format("{0}", type.Name)); - } + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); } - - if (referenceTypes.Count > 0) + else { - text = text.Replace("@ReferenceTypes@", String.Join(Environment.NewLine, referenceTypes.Distinct())); + throw new NotImplementedException("Implement generic item here!"); } + } - if (interfaceTypes.Count > 0) + foreach (var type in _knownTypes.ToList().Where(x => x.Name.StartsWith(word))) + { + if (type.Type.IsEnum) { - text = text.Replace("@InterfaceTypes@", String.Join(Environment.NewLine, interfaceTypes.Distinct())); + data.Add(new EnumCompletionItem() + { + Namespace = type.Type.Namespace, + Description = type.Summary, + Name = type.FriendlyName, + Priority = 0, + }); } - - MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); - - XmlTextReader xshd_reader = new XmlTextReader(ms); - - Dispatcher.BeginInvoke(new Action(() => + else if (type.Type.IsInterface) { - SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); - xshd_reader.Close(); - ms.Dispose(); - })); - - - foreach (var knownType in _knownTypes) + data.Add(new InterfaceCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsValueType) { - knownType.LoadDocumentation(); + data.Add(new StructCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsClass) + { + data.Add(new ClassCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else + { + throw new NotImplementedException("Implement generic item here."); } } - _isLoadingTypes = false; - }); - t.IsBackground = true; - t.Start(); - } - } - - private void InvalidateScriptTypesHighlightings() - { - var declaredTypes = _parser.GetDeclaredTypes(Text); + foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset).Where(x => x.Name.StartsWith(GetCurrentWord()))) + { + if (symbol.Kind == SymbolKind.Property) + { + data.Add(new PropertyCompletionItem() + { + Class = symbol.Class, + Description = symbol.Summary, + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter) + { + data.Add(new FieldCompletionItem() + { + Class = symbol.Class, + Description = symbol.Summary, + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Method) + { + var methodCompletion = new MethodCompletionItem() + { + Class = symbol.Class, + Description = symbol.Summary, + Name = symbol.Name, + ReturnType = symbol.Type, + Priority = 2, + }; - if (declaredTypes.Exists(x => !_declaredTypes.Exists(y => y.Name == x.Name)) || _declaredTypes.Exists(x => !declaredTypes.Exists(y => y.Name == x.Name))) - { - _declaredTypes = declaredTypes; - InvalidateHighlighting(); - } + for (int i = 0; i < symbol.Parameters.Count; i++) + { + var pair = symbol.Parameters[i]; - _declaredTypes = declaredTypes; + methodCompletion.Parameters.Add(new KnownTypeMethodParameter() + { + Type = pair.Key, + Name = pair.Value, + IsLast = (i == symbol.Parameters.Count - 1) + }); + } - //for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++) - //{ - // if (TextArea.TextView.LineTransformers[i] is OffsetColorizer) - // { - // TextArea.TextView.LineTransformers.RemoveAt(i); - // } - //} + data.Add(methodCompletion); + } + } - //foreach (var cls in scriptClasses) - //{ - // Document.BeginUpdate(); + ShowCompletionWindow(data, word); + } + } + } - // var line = Document.GetLineByOffset(cls.Index); + #endregion - // OffsetColorizer colorizer = new OffsetColorizer(line, cls.Index, cls.Index + cls.Name.Length, Brushes.Red); - // TextArea.TextView.LineTransformers.Add(colorizer); + #region Completion Window Insertion - // Document.EndUpdate(); - //} + private void CompletionWindow_InsertionRequest(ICompletionData item) + { + item.Complete(this); } #endregion - #region Override Methods + #region Private/Internal Methods - /// - /// Invoked when an unhandled  attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. - /// - /// The that contains the event data. - protected override void OnPreviewKeyDown(KeyEventArgs e) + private void ShowCompletionWindow(IList suggestions, String filter) { - if (CurrentPopupContent is MethodPopup && (e.Key == Key.Down || e.Key == Key.Up)) + IList data = completionWindow.CompletionList.CompletionData; + data.Clear(); + + foreach (var item in suggestions) { - e.Handled = true; + data.Add(item); + } - if (e.Key == Key.Down) - { - (CurrentPopupContent as MethodPopup).IncrementMethod(); - } - else if (e.Key == Key.Up) + if (data.Count > 0) + { + completionWindow.ShowCompletion(); + + if (completionWindow.CompletionList.ListBox != null) { - (CurrentPopupContent as MethodPopup).DecrementMethod(); + completionWindow.CompletionList.SelectItemFiltering(filter); } - - return; } - - base.OnPreviewKeyDown(e); - HidePopup(); - HandleKeyCombinations(e); + else + { + completionWindow.HideCompletion(); + } } - #endregion - - #region Apply Template - - public override void OnApplyTemplate() + private void HideCompletionWindow() { - base.OnApplyTemplate(); - - _popup = GetTemplateChild("PART_popup") as Popup; + completionWindow.HideCompletion(); } - #endregion + private List GetScriptClassNames() + { + List list = new List(); - #region Key Combination Handling + Regex r = new Regex(@"(class\s+)(\w+)"); + var matches = r.Matches(Text); - /// - /// Handles the key combinations. - /// - /// The instance containing the event data. - private void HandleKeyCombinations(KeyEventArgs e) - { - if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.K) && Keyboard.IsKeyDown(Key.D)) + foreach (var m in matches.OfType()) { - try - { - int index = CaretOffset; - Document.BeginUpdate(); - IndentCode(); - Document.EndUpdate(); - e.Handled = true; - CaretOffset = index; - } - catch - { - Debug.WriteLine("Error indenting code."); - } + var g = m.Groups.OfType().Last(); + list.Add(g.Value); } - else if (e.Key == Key.Oem2) - { - int offset = CaretOffset; - var line = Document.GetLineByOffset(offset); - String text = GetCurrentLineText(); - if (text.TrimStart('\t', ' ').StartsWith("//")) - { - Document.BeginUpdate(); - Document.Replace(line, "/// \n/// \n/// "); - Document.EndUpdate(); - e.Handled = true; - CaretOffset = Document.GetLineByNumber(line.LineNumber + 1).EndOffset; - } - } - else if (e.Key == Key.End || e.Key == Key.Home) + return list.Distinct().ToList(); + } + + private List GetScriptInterfaceOfEnumNames() + { + List list = new List(); + + Regex r = new Regex(@"((enum|interface)\s+)(\w+)"); + var matches = r.Matches(Text); + + foreach (var m in matches.OfType()) { - HideCompletionWindow(); + var g = m.Groups.OfType().Last(); + list.Add(g.Value); } + + return list.Distinct().ToList(); } - #endregion + private List GetScriptEnumsAndInterfaces() + { + List list = new List(); - #region Intellisense + Regex r = new Regex(@"((public|private|internal)\s+(enum|interface)\s+\w+)"); + var matches = r.Matches(Text); - /// - /// Handles the TextEntered event of the TextArea control. - /// - /// The source of the event. - /// The instance containing the event data. - private void TextArea_TextEntered(object sender, TextCompositionEventArgs e) - { - List items = new List(); + foreach (var m in matches) + { - HidePopup(); + } - var lineText = GetCurrentLineText(); - var previousWords = GetPreviousWords(); - var previousWordsLast = previousWords.LastOrDefault(); - String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; - String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); + return list; + } - if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; + private KnownType GetCurrentKnownType() + { + var expression = GetPreviousWords().LastOrDefault(); + return GetKnownTypeFromExpression(expression); + } - if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") + private KnownType GetKnownTypeFromExpression(String expression) + { + if (expression != null) { - var expression = previousWords.First(); - var knownType = GetKnownTypeFromExpression(expression + "."); + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + var variableName = tree.FirstOrDefault(); - if (knownType != null && knownType.Type.IsEnum) + if (variableName != null) { - completionWindow.HideCompletion(); - IList data = new List(); + //Search for enum type first + var enumType = _knownTypes.FirstOrDefault(x => x.Name == variableName && x.Type.IsEnum); - foreach (var field in knownType.Fields) + if (enumType != null) { - data.Add(new FieldCompletionItem() - { - Class = knownType.FriendlyName, - Name = knownType.FriendlyName + "." + field.Name, - Type = field.ReturnTypeFriendlyName, - Description = field.Summary, - }); + return enumType; } - ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); - } + tree.RemoveAt(0); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); + var variable = variables.FirstOrDefault(x => x.Name == variableName); - } - else if (e.Text == " " && GetPreviousWord() == "new") - { - var s = _parser.GetExpressionFirst(GetCurrentLineText()); + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "")); - if (s != null) - { - String type = s.Declaration.Type.ToString(); + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); - IList data = new List(); + if (member == null) + { + return null; + } - data.Add(new ClassCompletionItem() - { - Name = type, - Description = "Auto generate assignment...", - }); + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } - ShowCompletionWindow(data, type); + return knownType; + } + } } } - else if (e.Text == ";" || e.Text == " ") - { - HideCompletionWindow(); - } - else if (e.Text == ".") + + return null; + } + + private ScriptType GetCurrentDeclaredType() + { + var expression = GetPreviousWords().LastOrDefault(); + + if (expression != null) { - var knownType = GetCurrentKnownType(); + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + var variableName = tree.FirstOrDefault(); - if (knownType != null) + if (variableName != null) { - completionWindow.HideCompletion(); - IList data = new List(); + tree.RemoveAt(0); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); + var variable = variables.FirstOrDefault(x => x.Name == variableName); - if (!knownType.Type.IsEnum) + if (variable != null) { - var typeMembers = knownType.Members.ToList(); + var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Type, "<.+>", "")); - foreach (var methodGroup in typeMembers.OfType().GroupBy(x => x.NameWithTypeArguments)) + if (declaredType != null) { - var method = methodGroup.First(); - - data.Add(new MethodCompletionItem() + while (tree.Count > 1) { - Class = knownType.FriendlyName, - Name = method.NameWithTypeArguments, - ReturnType = method.ReturnTypeFriendlyName, - Description = method.Summary, - Parameters = method.Parameters, - Overloads = methodGroup.Count() - 1, - }); - } - - foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) - { - var member = methodGroup.First(); + var memberName = tree.First(); + tree.RemoveAt(0); + var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName); - data.Add(new PropertyCompletionItem() - { - Class = knownType.FriendlyName, - Name = member.Name, - Type = member.ReturnTypeFriendlyName, - Description = member.Summary, - }); + if (member == null) + { + return null; + } - } - } - else - { - foreach (var field in knownType.Fields) - { - data.Add(new FieldCompletionItem() - { - Class = knownType.FriendlyName, - Name = field.Name, - Type = field.ReturnTypeFriendlyName, - Description = field.Summary, - }); + declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type); + } + return declaredType; } } - - ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } - else - { - var declaredType = GetCurrentDeclaredType(); + } - if (declaredType != null) - { - completionWindow.HideCompletion(); - IList data = new List(); + return null; + } - var typeMembers = declaredType.Symbols.ToList(); + private void ShowPopup(Object content) + { + var position = TextArea.Caret.Position; + var textView = TextArea.TextView; - foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) - { - var member = methodGroup.First(); + var visualLocation = textView.GetVisualPosition(position, VisualYPosition.LineBottom); + var visualLocationTop = textView.GetVisualPosition(position, VisualYPosition.LineTop); - if (member.Kind == SymbolKind.Method) - { - var methodCompletion = new MethodCompletionItem() - { - Class = declaredType.Name, - Name = member.Name, - ReturnType = member.Type, - Description = member.Summary, - Overloads = methodGroup.Count() - 1, - }; + Point location = textView.PointToScreen(visualLocation - textView.ScrollOffset); + Point locationTop = textView.PointToScreen(visualLocationTop - textView.ScrollOffset); + _popup.Placement = PlacementMode.Absolute; + _popup.PlacementRectangle = new Rect(location, new Size(200, 100)); - for (int i = 0; i < member.Parameters.Count; i++) - { - var pair = member.Parameters[i]; + CurrentPopupContent = content; - methodCompletion.Parameters.Add(new KnownTypeMethodParameter() - { - Type = pair.Key, - Name = pair.Value, - IsLast = (i == member.Parameters.Count - 1) - }); - } + _popup.IsOpen = true; + } - data.Add(methodCompletion); + private void HidePopup() + { + _popup.IsOpen = false; + CurrentPopupContent = null; + } - } - else if (member.Kind == SymbolKind.Property) - { - data.Add(new PropertyCompletionItem() - { - Class = declaredType.Name, - Name = member.Name, - Type = member.Type, - Description = member.Summary, - }); - } - else if (member.Kind == SymbolKind.Field) - { - data.Add(new FieldCompletionItem() - { - Class = declaredType.Name, - Name = member.Name, - Type = member.Type, - Description = member.Summary, - }); - } - } + private MethodPopup CreateConstructionSessionPopupContent(ConstructionSession session) + { + MethodPopup popup = new MethodPopup(); - ShowCompletionWindow(data, GetCurrentWord()); - } - } - } - else if (e.Text == "(" || e.Text == ",") + foreach (var c in session.Type.Constructors) { - completionWindow.HideCompletion(); + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Type.Name; + method.Description = c.Summary; - try + if (session.Type.Type.IsGenericType && session.TypeArguments != null) { - var session = GetConstructionSession(); + method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; + } - if (session != null) - { - var content = CreateConstructionSessionPopupContent(session); - if (content.Methods.Count > 0) - { - ShowPopup(content); - return; - } - } + var parameters = c.Parameters; - var methodSession = GetMethodSession(); + 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); + } - if (methodSession != null) - { - var content = CreateMethodSessionPopupContent(methodSession); - if (content.Methods.Count > 0) - { - ShowPopup(content); - return; - } - } + popup.Methods.Add(method); + } - var declaredMethodSession = GetDeclaredMethodSession(); + if (session.ParameterIndex > 0) + { + popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1); - if (declaredMethodSession != null) - { - var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession); - if (content.Methods.Count > 0) - { - ShowPopup(content); - return; - } - } - } - catch (Exception ex) + if (popup.CurrentMethod == null) { - Debug.WriteLine(ex); + popup.CurrentMethod = popup.Methods.FirstOrDefault(); } } - else if (lineText.StartsWith("using")) + else { - if (completionWindow.IsVisible) - { - completionWindow.UpdatePositionFix(); - return; - } + popup.CurrentMethod = popup.Methods.FirstOrDefault(); + } - IList data = new List(); + if (popup.CurrentMethod != null) + { + popup.CurrentMethodIndex = popup.Methods.IndexOf(popup.CurrentMethod) + 1; + } - foreach (var asm in ReferenceAssemblies) - { - foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) - { - data.Add(new NamespaceCompletionItem() - { - Name = ns, - Assembly = asm.Assembly.GetName().Name, - }); - } - } + return popup; + } - data = data.DistinctBy(x => x.Text).ToList(); + private MethodPopup CreateMethodSessionPopupContent(MethodSession session) + { + MethodPopup popup = new MethodPopup(); - ShowCompletionWindow(data, GetCurrentWord()); - } - else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') + foreach (var m in session.Type.Methods.Where(x => x.Name == session.MethodName)) { - if (completionWindow.IsVisible) + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Type.Name; + method.Description = m.Summary; + method.Name = m.NameWithTypeArguments; + method.Class = session.Type.FriendlyName; + + //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) { - completionWindow.UpdatePositionFix(); - return; + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Name = p.Name; + pDescription.Type = p.Type; + pDescription.Description = p.Description; + method.Parameters.Add(pDescription); } - var previous_word = GetPreviousWord(); - var word = GetCurrentWord(); + popup.Methods.Add(method); + } - if (word.Contains("<")) + if (session.ParameterIndex > 0) + { + popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1); + + if (popup.CurrentMethod == null) { - word = word.Last(x => x != '<').ToString(); + popup.CurrentMethod = popup.Methods.FirstOrDefault(); } + } + else + { + popup.CurrentMethod = popup.Methods.FirstOrDefault(); + } - if (previous_word != word) - { - if (_knownTypes.Exists(x => x.Name == previous_word)) - { - return; - } + if (popup.CurrentMethod != null) + { + popup.CurrentMethodIndex = popup.Methods.IndexOf(popup.CurrentMethod) + 1; + } - if (_blocking_type_words.Contains(previous_word)) - { - return; - } - } + return popup; + } - if (!String.IsNullOrWhiteSpace(word)) - { - IList data = new List(); + private MethodPopup CreateDeclaredMethodSessionPopupContent(DeclaredMethodSession session) + { + MethodPopup popup = new MethodPopup(); - foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) + MethodDescription method = new MethodDescription(); + method.ReturnType = session.Method.Type; + method.Description = session.Method.Summary; + method.Name = session.Method.Name; + method.Class = session.Method.Class; + + //if (session.Type.Type.IsGenericType && session.TypeArguments != null) + //{ + // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; + //} + + foreach (var p in session.Method.Parameters) + { + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Type = p.Key; + pDescription.Name = p.Value; + 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; + } + + private void InvalidateHighlighting() + { + if (!_isLoadingTypes) + { + _isLoadingTypes = true; + _knownTypes.Clear(); + + var assemblies = ReferenceAssemblies.ToList(); + var usings = _current_usings.ToList(); + + Thread t = new Thread(() => + { + foreach (var asm in assemblies.Select(x => x.Assembly)) { - if (type.Kind == TypeKind.Struct) - { - data.Add(new StructCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Enum) - { - data.Add(new EnumCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Interface) - { - data.Add(new InterfaceCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Class) + Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => { - data.Add(new ClassCompletionItem() + if (usings.Exists(x => type.Namespace == x)) { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else - { - throw new NotImplementedException("Implement generic item here!"); - } + lock (_knownTypes) + { + if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + { + _knownTypes.Add(new KnownType(type)); + } + } + } + }); } - foreach (var type in _knownTypes.ToList().Where(x => x.Name.StartsWith(word))) + if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) { - if (type.Type.IsEnum) - { - data.Add(new EnumCompletionItem() - { - Namespace = type.Type.Namespace, - Description = type.Summary, - Name = type.FriendlyName, - Priority = 0, - }); - } - else if (type.Type.IsInterface) - { - data.Add(new InterfaceCompletionItem() - { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); - } - else if (type.Type.IsValueType) + 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)) { - data.Add(new StructCompletionItem() - { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); + text = reader.ReadToEnd(); } - else if (type.Type.IsClass) + + List referenceTypes = new List(); + List interfaceTypes = new List(); + + lock (_knownTypes) { - data.Add(new ClassCompletionItem() + foreach (var type in _knownTypes.ToList().Where(x => x != null)) { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); - } - else - { - throw new NotImplementedException("Implement generic item here."); - } - } + String name = type.Name; - foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset).Where(x => x.Name.StartsWith(GetCurrentWord()))) - { - if (symbol.Kind == SymbolKind.Property) + if (type.Type.ContainsGenericParameters) + { + name = new String(name.TakeWhile(x => x != '`').ToArray()); + } + + if (type.Type.IsInterface || type.Type.IsEnum) + { + interfaceTypes.Add(String.Format("{0}", name)); + } + else if (type.Type.IsClass || (type.Type.IsValueType)) + { + referenceTypes.Add(String.Format("{0}", name)); + } + } + } + + foreach (var type in _declaredTypes) { - data.Add(new PropertyCompletionItem() + if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - Type = symbol.Type, - Priority = 2, - }); + interfaceTypes.Add(String.Format("{0}", type.Name)); + } + else if (type.Kind == TypeKind.Class) + { + referenceTypes.Add(String.Format("{0}", type.Name)); + } } - else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter) + + if (referenceTypes.Count > 0) { - data.Add(new FieldCompletionItem() - { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - Type = symbol.Type, - Priority = 2, - }); + text = text.Replace("@ReferenceTypes@", String.Join(Environment.NewLine, referenceTypes.Distinct())); } - else if (symbol.Kind == SymbolKind.Method) + + if (interfaceTypes.Count > 0) { - var methodCompletion = new MethodCompletionItem() - { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - ReturnType = symbol.Type, - Priority = 2, - }; + text = text.Replace("@InterfaceTypes@", String.Join(Environment.NewLine, interfaceTypes.Distinct())); + } - for (int i = 0; i < symbol.Parameters.Count; i++) - { - var pair = symbol.Parameters[i]; + MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); - methodCompletion.Parameters.Add(new KnownTypeMethodParameter() - { - Type = pair.Key, - Name = pair.Value, - IsLast = (i == symbol.Parameters.Count - 1) - }); - } + XmlTextReader xshd_reader = new XmlTextReader(ms); - data.Add(methodCompletion); + Dispatcher.BeginInvoke(new Action(() => + { + SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); + xshd_reader.Close(); + ms.Dispose(); + })); + + + foreach (var knownType in _knownTypes) + { + knownType.LoadDocumentation(); } } - ShowCompletionWindow(data, word); - } + _isLoadingTypes = false; + }); + t.IsBackground = true; + t.Start(); } } - private void CompletionWindow_InsertionRequest(ICompletionData item) + private void InvalidateScriptTypesHighlightings() { - item.Complete(this); + var declaredTypes = _parser.GetDeclaredTypes(Text); + + if (declaredTypes.Exists(x => !_declaredTypes.Exists(y => y.Name == x.Name)) || _declaredTypes.Exists(x => !declaredTypes.Exists(y => y.Name == x.Name))) + { + _declaredTypes = declaredTypes; + InvalidateHighlighting(); + } + + _declaredTypes = declaredTypes; + + //for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++) + //{ + // if (TextArea.TextView.LineTransformers[i] is OffsetColorizer) + // { + // TextArea.TextView.LineTransformers.RemoveAt(i); + // } + //} + + //foreach (var cls in scriptClasses) + //{ + // Document.BeginUpdate(); + + // var line = Document.GetLineByOffset(cls.Index); + + // OffsetColorizer colorizer = new OffsetColorizer(line, cls.Index, cls.Index + cls.Name.Length, Brushes.Red); + // TextArea.TextView.LineTransformers.Add(colorizer); + + // Document.EndUpdate(); + //} } - private void ShowCompletionWindow(IList suggestions, String filter) + private void InvalidateUsings() { - IList data = completionWindow.CompletionList.CompletionData; - data.Clear(); + var oldUsings = _current_usings.ToList(); + _current_usings = _parser.GetUsings(Text); - foreach (var item in suggestions) + if (_current_usings.Exists(x => !oldUsings.Exists(y => y == x)) || oldUsings.Exists(x => !_current_usings.Exists(y => y == x))) { - data.Add(item); + InvalidateHighlighting(); } + } - if (data.Count > 0) + private void InvalidateFolding() + { + if (EnableFolding) { - completionWindow.ShowCompletion(); + if (foldingManager == null) + { + foldingManager = FoldingManager.Install(TextArea); + } - if (completionWindow.CompletionList.ListBox != null) + foldingStrategy.UpdateFoldings(foldingManager, Document); + } + } + + private void IndentCode() + { + Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); + //Text = _parser.IndentCSharpCode(Text); + } + + internal DocumentLine GetCurrentLine() + { + int offset = CaretOffset; + var line = Document.GetLineByOffset(offset); + return line; + } + + private String GetCurrentLineText() + { + var text = Document.GetText(GetCurrentLine()); + return text; + } + + internal String GetCurrentWord() + { + return GetWordByEndIndex(CaretOffset); + } + + private String GetWordByEndIndex(int index) + { + String word = String.Empty; + var line = GetCurrentLine(); + + int position = index; + + for (int i = position - 1; i >= line.Offset; i--) + { + char c = Document.GetText(i, 1).First(); + + if (word_separators.Contains(c)) { - completionWindow.CompletionList.SelectItemFiltering(filter); + break; } + + word += c; } - else + + word = new string(word.Reverse().ToArray()); + + if (word.Length > 0) { - completionWindow.HideCompletion(); + word = word.Replace(".", ""); } - } - private void HideCompletionWindow() - { - completionWindow.HideCompletion(); + return word; } - private List GetScriptClassNames() + internal int GetCurrentWordStartIndex() { - List list = new List(); + var line = GetCurrentLine(); - Regex r = new Regex(@"(class\s+)(\w+)"); - var matches = r.Matches(Text); + int position = CaretOffset; - foreach (var m in matches.OfType()) + for (int i = position - 1; i >= line.Offset; i--) { - var g = m.Groups.OfType().Last(); - list.Add(g.Value); + char c = Document.GetText(i, 1).First(); + + if (word_separators.Contains(c)) + { + return i + 1; + } } - return list.Distinct().ToList(); + return line.Offset; } - private List GetScriptInterfaceOfEnumNames() + private String GetPreviousWord() { - List list = new List(); + int index = GetCurrentWordStartIndex() - 1; + return GetWordByEndIndex(index); + } - Regex r = new Regex(@"((enum|interface)\s+)(\w+)"); - var matches = r.Matches(Text); + private ConstructionSession GetConstructionSession() + { + var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); - foreach (var m in matches.OfType()) + if (expression != null) { - var g = m.Groups.OfType().Last(); - list.Add(g.Value); + ConstructionSession session = new ConstructionSession(); + + var line = GetCurrentLine(); + int parameterIndex = 0; + for (int i = CaretOffset; i > line.Offset; i--) + { + String c = Document.GetText(i, 1); + + if (c == "(") + { + var typeDeclaration = expression.Type as GenericNameSyntax; + + KnownType type = null; + + 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 (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 (type != null) + { + session.Type = type; + session.ParameterIndex = parameterIndex; + return session; + } + else + { + return null; + } + } + else if (c == ",") + { + parameterIndex++; + } + + } } - return list.Distinct().ToList(); + return null; } - private List GetScriptEnumsAndInterfaces() + private MethodSession GetMethodSession() { - List list = new List(); - - Regex r = new Regex(@"((public|private|internal)\s+(enum|interface)\s+\w+)"); - var matches = r.Matches(Text); + var words = GetCurrentLineText().Split(' '); - foreach (var m in matches) + if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) { - + return null; } - return list; - } - - private KnownType GetCurrentKnownType() - { - var expression = GetPreviousWords().LastOrDefault(); - return GetKnownTypeFromExpression(expression); - } + var expression = words.LastOrDefault(); - private KnownType GetKnownTypeFromExpression(String expression) - { if (expression != null) { - var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + int parameterIndex = expression.Count(x => x == ','); + expression = new string(expression.TakeWhile(x => x != '(').ToArray()); + + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); var variableName = tree.FirstOrDefault(); - if (variableName != null) + if (variableName != null && tree.Count > 1) { - //Search for enum type first - var enumType = _knownTypes.FirstOrDefault(x => x.Name == variableName && x.Type.IsEnum); - - if (enumType != null) - { - return enumType; - } - tree.RemoveAt(0); var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); var variable = variables.FirstOrDefault(x => x.Name == variableName); @@ -1343,7 +1494,12 @@ namespace Tango.Scripting.Editors knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); } - return knownType; + return new MethodSession() + { + Type = knownType, + MethodName = tree.Last(), + ParameterIndex = parameterIndex, + }; } } } @@ -1352,16 +1508,23 @@ namespace Tango.Scripting.Editors return null; } - private ScriptType GetCurrentDeclaredType() + private DeclaredMethodSession GetDeclaredMethodSession() { + var words = GetCurrentLineText().Split(' '); + + if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) + { + return null; + } + var expression = GetPreviousWords().LastOrDefault(); if (expression != null) { - var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "")).ToList(); var variableName = tree.FirstOrDefault(); - if (variableName != null) + if (variableName != null && tree.Count > 0) { tree.RemoveAt(0); var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); @@ -1369,7 +1532,7 @@ namespace Tango.Scripting.Editors if (variable != null) { - var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Type, "<.+>", "")); + var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Class, "<.+>", "")); if (declaredType != null) { @@ -1387,193 +1550,44 @@ namespace Tango.Scripting.Editors declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type); } - return declaredType; - } - } - } - } - - return null; - } - - #endregion - - #region Popup - - private void ShowPopup(Object content) - { - var position = TextArea.Caret.Position; - var textView = TextArea.TextView; - - var visualLocation = textView.GetVisualPosition(position, VisualYPosition.LineBottom); - var visualLocationTop = textView.GetVisualPosition(position, VisualYPosition.LineTop); - - Point location = textView.PointToScreen(visualLocation - textView.ScrollOffset); - Point locationTop = textView.PointToScreen(visualLocationTop - textView.ScrollOffset); - - _popup.Placement = PlacementMode.Absolute; - _popup.PlacementRectangle = new Rect(location, new Size(200, 100)); - - CurrentPopupContent = content; - - _popup.IsOpen = true; - } - - private void HidePopup() - { - _popup.IsOpen = false; - CurrentPopupContent = null; - } - - private MethodPopup CreateConstructionSessionPopupContent(ConstructionSession session) - { - MethodPopup popup = new MethodPopup(); - - foreach (var c in session.Type.Constructors) - { - MethodDescription method = new MethodDescription(); - method.ReturnType = session.Type.Name; - method.Description = c.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 = c.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 (session.ParameterIndex > 0) - { - 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; - } - - 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; - method.Name = m.NameWithTypeArguments; - method.Class = session.Type.FriendlyName; + var methodName = tree.Count > 0 ? tree.Last() : variableName; - //if (session.Type.Type.IsGenericType && session.TypeArguments != null) - //{ - // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; - //} + var method = declaredType.Symbols.FirstOrDefault(x => x.Kind == SymbolKind.Method && x.Name == methodName); - var parameters = m.Parameters; + if (method != null) + { + return new DeclaredMethodSession() + { + Type = declaredType, + Method = method, + }; + } + } + else if (tree.Count == 0) + { + var method = variable; - 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); + if (method != null) + { + return new DeclaredMethodSession() + { + Type = declaredType, + Method = method, + }; + } + } + } } - - 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; + return null; } - private MethodPopup CreateDeclaredMethodSessionPopupContent(DeclaredMethodSession session) + private List GetPreviousWords() { - MethodPopup popup = new MethodPopup(); - - MethodDescription method = new MethodDescription(); - method.ReturnType = session.Method.Type; - method.Description = session.Method.Summary; - method.Name = session.Method.Name; - method.Class = session.Method.Class; - - //if (session.Type.Type.IsGenericType && session.TypeArguments != null) - //{ - // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; - //} - - foreach (var p in session.Method.Parameters) - { - ParameterDescription pDescription = new ParameterDescription(method); - pDescription.Type = p.Key; - pDescription.Name = p.Value; - 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; + var currentLine = GetCurrentLine(); + var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); + return currentText.Split(' ', ',').ToList(); } #endregion 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 f022f7999..15760c950 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 @@ -48,6 +48,8 @@ namespace Tango.Scripting.Parsing { var currentNode = GetCaretOffsetNode(code, caretOffset); + if (currentNode == null) return new List(); + if (currentNode.Ancestors().OfType().Count() == 0) { var usings = GetUsingsFull(code); -- cgit v1.3.1 From c5e354289baee800f4cf93b6df1836a133c1addf Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 17 Mar 2019 09:12:33 +0200 Subject: Scripting Ide... --- .../Tango.Scripting.Editors.csproj | 1 + .../Tango.Scripting.IDE.UI/App.config | 46 ++++++++ .../Tango.Scripting.IDE.UI/App.xaml | 9 ++ .../Tango.Scripting.IDE.UI/App.xaml.cs | 17 +++ .../Tango.Scripting.IDE.UI/MainWindow.xaml | 13 +++ .../Tango.Scripting.IDE.UI/MainWindow.xaml.cs | 29 +++++ .../Tango.Scripting.IDE.UI/MainWindowVM.cs | 19 ++++ .../Properties/AssemblyInfo.cs | 55 +++++++++ .../Properties/Resources.Designer.cs | 71 ++++++++++++ .../Properties/Resources.resx | 117 +++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ .../Tango.Scripting.IDE.UI.csproj | 125 +++++++++++++++++++++ .../Tango.Scripting.IDE.UI/packages.config | 4 + .../Tango.Scripting.IDE/IScriptFile.cs | 13 +++ .../Tango.Scripting.IDE/IScriptProject.cs | 20 ++++ .../Tango.Scripting.IDE/Properties/AssemblyInfo.cs | 55 +++++++++ .../Properties/Resources.Designer.cs | 62 ++++++++++ .../Tango.Scripting.IDE/Properties/Resources.resx | 117 +++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ .../Tango.Scripting.IDE/Resources.xaml | 8 ++ .../Tango.Scripting.IDE/ScriptIDEView.xaml | 90 +++++++++++++++ .../Tango.Scripting.IDE/ScriptIDEView.xaml.cs | 28 +++++ .../Tango.Scripting.IDE/ScriptIDEViewVM.cs | 19 ++++ .../Tango.Scripting.IDE/StubsProject.cs | 17 +++ .../Tango.Scripting.IDE/Tango.Scripting.IDE.csproj | 118 +++++++++++++++++++ .../Tango.Scripting.IDE/Themes/Generic.xaml | 8 ++ .../Tango.Scripting.IDE/packages.config | 4 + .../TEMP/Tango.Scripting/Tango.Scripting.sln | 12 ++ .../TEMP/Tango.Scripting/TestApp/MainWindow.xaml | 16 +-- .../Tango.Scripting/TestApp/MainWindow.xaml.cs | 8 +- .../TEMP/Tango.Scripting/TestApp/TestApp.csproj | 10 ++ .../TEMP/Tango.Scripting/TestApp/packages.config | 1 + 34 files changed, 1171 insertions(+), 15 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindowVM.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.resx create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.settings create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.resx create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.settings create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') 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 de8308271..10236ee42 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 @@ -622,6 +622,7 @@ + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config new file mode 100644 index 000000000..b7f531317 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml new file mode 100644 index 000000000..9563551dd --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml.cs new file mode 100644 index 000000000..273731b71 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.Scripting.IDE.UI +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml new file mode 100644 index 000000000..0234ed063 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs new file mode 100644 index 000000000..be5d4ce2b --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs @@ -0,0 +1,29 @@ +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.IDE.UI +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainWindowVM(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindowVM.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindowVM.cs new file mode 100644 index 000000000..2ced386b3 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindowVM.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; + +namespace Tango.Scripting.IDE.UI +{ + public class MainWindowVM : ViewModel + { + public ScriptIDEViewVM IdeVM { get; set; } + + public MainWindowVM() + { + IdeVM = new ScriptIDEViewVM(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..56c3e1308 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Scripting.IDE.UI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.IDE.UI")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.Designer.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.Designer.cs new file mode 100644 index 000000000..45fc62ce0 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.IDE.UI.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.Scripting.IDE.UI.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.resx b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.Designer.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.Designer.cs new file mode 100644 index 000000000..fb153fa4c --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.IDE.UI.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.settings b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj new file mode 100644 index 000000000..db8eff963 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj @@ -0,0 +1,125 @@ + + + + + Debug + AnyCPU + {B0EFE7A0-7039-4DC4-8B39-465E521299F6} + WinExe + Tango.Scripting.IDE.UI + Tango.Scripting.IDE.UI + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + + + ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll + + + + + + + + + 4.0 + + + ..\..\..\Build\Core\Debug\Tango.Core.dll + + + ..\..\..\Build\Core\Debug\Tango.SharedUI.dll + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + {6c55b776-26d4-4db3-a6ab-87e783b2f3d1} + Tango.Scripting.Editors + + + {c9f60285-91fb-4293-bcf5-164d76755cdd} + Tango.Scripting.IDE + + + {1e938fd2-c669-4738-98c9-77f96ce4d451} + Tango.Scripting + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config new file mode 100644 index 000000000..07b683c3f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs new file mode 100644 index 000000000..f26a0064f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE +{ + public interface IScriptFile + { + String Name { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs new file mode 100644 index 000000000..f68114e8b --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE +{ + public interface IScriptProject + { + String Name { get; set; } + + String FilePath { get; set; } + + ObservableCollection References { get; set; } + + ObservableCollection Items { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/AssemblyInfo.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..3ac597e08 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Scripting.IDE")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.IDE")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.Designer.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.Designer.cs new file mode 100644 index 000000000..ec92331cb --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.Designer.cs @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.IDE.Properties { + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if ((resourceMan == null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.Scripting.IDE.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.resx b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.Designer.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.Designer.cs new file mode 100644 index 000000000..2a0fdc6a9 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.IDE.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.settings b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml new file mode 100644 index 000000000..3393e6888 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml @@ -0,0 +1,8 @@ + + + #202020 + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml new file mode 100644 index 000000000..3636089da --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml.cs new file mode 100644 index 000000000..3c816be05 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml.cs @@ -0,0 +1,28 @@ +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.IDE +{ + /// + /// Interaction logic for ScriptIDEControl.xaml + /// + public partial class ScriptIDEView : UserControl + { + public ScriptIDEView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs new file mode 100644 index 000000000..16644b6da --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; + +namespace Tango.Scripting.IDE +{ + public class ScriptIDEViewVM : ViewModel + { + private IScriptProject _project; + public IScriptProject Project + { + get { return _project; } + set { _project = value; RaisePropertyChangedAuto(); } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs new file mode 100644 index 000000000..88f538e7c --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE +{ + public class StubsProject : IScriptProject + { + public string Name { get; set; } + public string FilePath { get; set; } + public ObservableCollection References { get; set; } + public ObservableCollection Items { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj new file mode 100644 index 000000000..7c3b47ea6 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj @@ -0,0 +1,118 @@ + + + + + Debug + AnyCPU + {C9F60285-91FB-4293-BCF5-164D76755CDD} + library + Tango.Scripting.IDE + Tango.Scripting.IDE + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + + + ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll + + + + + + + + + 4.0 + + + False + ..\..\..\Build\Core\Debug\Tango.Core.dll + + + ..\..\..\Build\Core\Debug\Tango.SharedUI.dll + + + + + + + + + + ScriptIDEView.xaml + + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + {6c55b776-26d4-4db3-a6ab-87e783b2f3d1} + Tango.Scripting.Editors + + + {1e938fd2-c669-4738-98c9-77f96ce4d451} + Tango.Scripting + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml new file mode 100644 index 000000000..d7cedf6c6 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config new file mode 100644 index 000000000..07b683c3f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.sln b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.sln index bd59e05d9..e77aad451 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.sln +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.sln @@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.Scripting.Editors", "Tango.Scripting.Editors\Tango.Scripting.Editors.csproj", "{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.Scripting.IDE", "Tango.Scripting.IDE\Tango.Scripting.IDE.csproj", "{C9F60285-91FB-4293-BCF5-164D76755CDD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.Scripting.IDE.UI", "Tango.Scripting.IDE.UI\Tango.Scripting.IDE.UI.csproj", "{B0EFE7A0-7039-4DC4-8B39-465E521299F6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Debug|Any CPU.Build.0 = Debug|Any CPU {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Release|Any CPU.ActiveCfg = Release|Any CPU {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Release|Any CPU.Build.0 = Release|Any CPU + {C9F60285-91FB-4293-BCF5-164D76755CDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9F60285-91FB-4293-BCF5-164D76755CDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9F60285-91FB-4293-BCF5-164D76755CDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9F60285-91FB-4293-BCF5-164D76755CDD}.Release|Any CPU.Build.0 = Release|Any CPU + {B0EFE7A0-7039-4DC4-8B39-465E521299F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0EFE7A0-7039-4DC4-8B39-465E521299F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0EFE7A0-7039-4DC4-8B39-465E521299F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0EFE7A0-7039-4DC4-8B39-465E521299F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml index e9cc002ba..56fe9da3c 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml @@ -5,22 +5,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:editors="clr-namespace:Tango.Scripting.Editors;assembly=Tango.Scripting.Editors" xmlns:local="clr-namespace:TestApp" + xmlns:ide="clr-namespace:Tango.Scripting.IDE;assembly=Tango.Scripting.IDE" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> - - - - - - - - - Enable Folding - - - - - + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml.cs index 59bd4ef50..8ae84b20e 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/MainWindow.xaml.cs @@ -34,7 +34,13 @@ namespace TestApp private async void Button_Click(object sender, RoutedEventArgs e) { Script s = new Script(); - s.Code = editor.Text; + s.Code = +@" +using System; +using System.Windows.Forms; + +MessageBox.Show(""Hi Roy""); +"; try { diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/TestApp.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/TestApp.csproj index 1f264b981..ebcb2f004 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/TestApp.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/TestApp.csproj @@ -38,8 +38,14 @@ ..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll + + ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll + @@ -103,6 +109,10 @@ {6c55b776-26d4-4db3-a6ab-87e783b2f3d1} Tango.Scripting.Editors + + {c9f60285-91fb-4293-bcf5-164d76755cdd} + Tango.Scripting.IDE + {1e938fd2-c669-4738-98c9-77f96ce4d451} Tango.Scripting diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/packages.config b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/packages.config index f69b3c48f..893958c68 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/packages.config +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file -- cgit v1.3.1 From c4b03559eec69b2c69048dc88ed42ea1969b8d52 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Mar 2019 18:47:20 +0200 Subject: Fixed issue with Machine Studio Resume. Worked on Scripting IDE. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1344 -> 1516 bytes .../ViewModels/MainViewVM.cs | 8 +- .../Tango.Scripting.Editors.csproj | 2 +- .../Tango.Scripting.IDE.UI/App.config | 37 +----- .../Tango.Scripting.IDE.UI/App.xaml | 20 +++- .../Tango.Scripting.IDE.UI/MainWindow.xaml | 7 +- .../Tango.Scripting.IDE.UI/MainWindow.xaml.cs | 5 +- .../Tango.Scripting.IDE.UI.csproj | 75 +++++++++++++ .../Tango.Scripting.IDE.UI/packages.config | 44 ++++++++ .../Controls/SolutionItemControl.cs | 52 +++++++++ .../Dialogs/NewProjectDialog.xaml | 12 ++ .../Dialogs/NewProjectDialog.xaml.cs | 28 +++++ .../Dialogs/NewProjectDialogVM.cs | 14 +++ .../Tango.Scripting.IDE/IProject.cs | 23 ++++ .../Tango.Scripting.IDE/IProjectItem.cs | 18 +++ .../Tango.Scripting.IDE/IProjectType.cs | 21 ++++ .../Tango.Scripting.IDE/IScriptFile.cs | 13 --- .../Tango.Scripting.IDE/IScriptProject.cs | 20 ---- .../Tango.Scripting.IDE/ISolutionItem.cs | 18 +++ .../Tango.Scripting.IDE/Images/CSharpProject.png | Bin 0 -> 200 bytes .../Images/CSharpScriptItem.png | Bin 0 -> 238 bytes .../Tango.Scripting.IDE/Images/Reference.png | Bin 0 -> 141 bytes .../Tango.Scripting.IDE/Images/StubProject.png | Bin 0 -> 392 bytes .../Tango.Scripting/Tango.Scripting.IDE/Project.cs | 56 +++++++++ .../Tango.Scripting.IDE/ProjectItem.cs | 57 ++++++++++ .../ProjectItems/CSharpScriptItem.cs | 30 +++++ .../ProjectItems/ReferenceAssembliesItem.cs | 27 +++++ .../ProjectItems/ReferenceAssemblyItem.cs | 24 ++++ .../ProjectItemsViews/CSharpScriptItemView.xaml | 13 +++ .../ProjectItemsViews/CSharpScriptItemView.xaml.cs | 29 +++++ .../ProjectTypes/StubProjectType.cs | 45 ++++++++ .../ProjectTypes/UnitTestProjectType.cs | 43 +++++++ .../Tango.Scripting.IDE/Projects/CSharpProject.cs | 14 +++ .../Tango.Scripting.IDE/Projects/StubProject.cs | 25 +++++ .../Projects/UnitTestProject.cs | 24 ++++ .../Tango.Scripting.IDE/Resources.xaml | 125 ++++++++++++++++++++- .../Tango.Scripting.IDE/ScriptIDEView.xaml | 73 ++++++++++-- .../Tango.Scripting.IDE/ScriptIDEViewVM.cs | 97 +++++++++++++++- .../Tango.Scripting.IDE/Solution.cs | 19 ++++ .../Tango.Scripting.IDE/StubsProject.cs | 17 --- .../Tango.Scripting.IDE/Tango.Scripting.IDE.csproj | 53 ++++++++- .../Tango.Scripting.IDE/Themes/Generic.xaml | 20 +++- .../Tango.Scripting/Tango.Scripting.IDE/app.config | 43 +++++++ .../Tango.Scripting.IDE/packages.config | 1 + 46 files changed, 1136 insertions(+), 116 deletions(-) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Controls/SolutionItemControl.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialogVM.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectType.cs delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ISolutionItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpProject.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpScriptItem.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/Reference.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/StubProject.png create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Project.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/CSharpScriptItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssembliesItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssemblyItem.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/StubProjectType.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/UnitTestProjectType.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/CSharpProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/StubProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/UnitTestProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Solution.cs delete mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/app.config (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 6b59af4b3..fbc4736e1 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 5ab7fc785..cfd096d15 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 57e613c14..b3a55c2f1 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 04d2fae4b..1a295f23c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1332,16 +1332,16 @@ namespace Tango.MachineStudio.Developer.ViewModels _preparingTaskItem = item; JobHandler = await MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); } - - _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); - IsJobRunning = true; - ShowJobStatus = true; } else { JobHandler = resumeFunc(ActiveJob); } + _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); + IsJobRunning = true; + ShowJobStatus = true; + _eventLogger.Log(String.Format("Job '{0}' started...", ActiveJob.Name)); JobHandler.StatusChanged += (x, status) => 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 10236ee42..2a21f0264 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 @@ -625,7 +625,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config index b7f531317..aa58e3cac 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.config @@ -5,42 +5,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml index 9563551dd..be9fdd055 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/App.xaml @@ -4,6 +4,24 @@ xmlns:local="clr-namespace:Tango.Scripting.IDE.UI" StartupUri="MainWindow.xaml"> - + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml index 0234ed063..2bc6100ce 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml @@ -1,13 +1,14 @@ - + Title="MainWindow" Height="720" Width="1280" d:DataContext="{d:DesignInstance Type=local:MainWindowVM, IsDesignTimeCreatable=False}" TitlebarHeight="40" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen"> - + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs index be5d4ce2b..13f2bf7a9 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System; +using MahApps.Metro.Controls; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -18,7 +19,7 @@ namespace Tango.Scripting.IDE.UI /// /// Interaction logic for MainWindow.xaml /// - public partial class MainWindow : Window + public partial class MainWindow : MetroWindow { public MainWindow() { diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj index db8eff963..f87325bc9 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/Tango.Scripting.IDE.UI.csproj @@ -34,11 +34,70 @@ 4 + + ..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll + ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + ..\packages\Microsoft.CodeAnalysis.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + + + ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + + ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll + + + ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + + + ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll @@ -51,6 +110,18 @@ 4.0 + + ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + + + ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + + + ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll + + + ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + ..\..\..\Build\Core\Debug\Tango.Core.dll @@ -121,5 +192,9 @@ Tango.Scripting + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config index 07b683c3f..e207a9750 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE.UI/packages.config @@ -1,4 +1,48 @@  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Controls/SolutionItemControl.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Controls/SolutionItemControl.cs new file mode 100644 index 000000000..ad6c65f22 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Controls/SolutionItemControl.cs @@ -0,0 +1,52 @@ +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.IDE.Controls +{ + public class SolutionItemControl : Control + { + public ISolutionItem SolutionItem + { + get { return (ISolutionItem)GetValue(SolutionItemProperty); } + set { SetValue(SolutionItemProperty, value); } + } + public static readonly DependencyProperty SolutionItemProperty = + DependencyProperty.Register("SolutionItem", typeof(ISolutionItem), typeof(SolutionItemControl), new PropertyMetadata(null)); + + public ICommand OpenCommand + { + get { return (ICommand)GetValue(OpenCommandProperty); } + set { SetValue(OpenCommandProperty, value); } + } + public static readonly DependencyProperty OpenCommandProperty = + DependencyProperty.Register("OpenCommand", typeof(ICommand), typeof(SolutionItemControl), new PropertyMetadata(null)); + + static SolutionItemControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(SolutionItemControl), new FrameworkPropertyMetadata(typeof(SolutionItemControl))); + } + + public SolutionItemControl() + { + PreviewMouseDoubleClick += (_, __) => + { + if (SolutionItem.CanOpen) + { + OpenCommand?.Execute(SolutionItem); + } + }; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml new file mode 100644 index 000000000..7942a7165 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml.cs new file mode 100644 index 000000000..376190e3a --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialog.xaml.cs @@ -0,0 +1,28 @@ +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.IDE.Dialogs +{ + /// + /// Interaction logic for NewProjectDialog.xaml + /// + public partial class NewProjectDialog : UserControl + { + public NewProjectDialog() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialogVM.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialogVM.cs new file mode 100644 index 000000000..3c25e70f3 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Dialogs/NewProjectDialogVM.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; + +namespace Tango.Scripting.IDE.Dialogs +{ + public class NewProjectDialogVM : ViewModel + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProject.cs new file mode 100644 index 000000000..18d95a7d8 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProject.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE +{ + public interface IProject : ISolutionItem + { + String FilePath { get; set; } + + String WorkingFolder { get; } + + ObservableCollection Items { get; set; } + + Task Build(); + + Task Run(); + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectItem.cs new file mode 100644 index 000000000..0d34cf2e6 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE +{ + public interface IProjectItem : ISolutionItem + { + ObservableCollection Items { get; set; } + + FrameworkElement View { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectType.cs new file mode 100644 index 000000000..ed9ff51a8 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IProjectType.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE +{ + public interface IProjectType + { + IProject NewProject(String projectPath); + + String Name { get; } + + String Description { get; } + + BitmapSource Image { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs deleted file mode 100644 index f26a0064f..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptFile.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Scripting.IDE -{ - public interface IScriptFile - { - String Name { get; set; } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs deleted file mode 100644 index f68114e8b..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/IScriptProject.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Scripting.IDE -{ - public interface IScriptProject - { - String Name { get; set; } - - String FilePath { get; set; } - - ObservableCollection References { get; set; } - - ObservableCollection Items { get; set; } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ISolutionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ISolutionItem.cs new file mode 100644 index 000000000..74bdab066 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ISolutionItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE +{ + public interface ISolutionItem + { + String Name { get; } + + BitmapSource Image { get; } + + bool CanOpen { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpProject.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpProject.png new file mode 100644 index 000000000..5b0f29960 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpProject.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpScriptItem.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpScriptItem.png new file mode 100644 index 000000000..37e4e1727 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/CSharpScriptItem.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/Reference.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/Reference.png new file mode 100644 index 000000000..fa5430947 Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/Reference.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/StubProject.png b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/StubProject.png new file mode 100644 index 000000000..cd0ad20ad Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Images/StubProject.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Project.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Project.cs new file mode 100644 index 000000000..5a950d2c7 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Project.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using Tango.SharedUI.Helpers; + +namespace Tango.Scripting.IDE +{ + public abstract class Project : IProject + { + private static Dictionary _imageCache; + + static Project() + { + _imageCache = new Dictionary(); + } + + public string FilePath { get; set; } + + public string WorkingFolder => Path.GetDirectoryName(FilePath); + + public string Name => Path.GetFileNameWithoutExtension(FilePath); + + public abstract BitmapSource Image { get; } + + public ObservableCollection Items { get; set; } + + public Project() + { + Items = new ObservableCollection(); + } + + public abstract Task Build(); + public abstract Task Run(); + + protected static BitmapSource GetImage(String name) + { + if (_imageCache.ContainsKey(name)) + { + return _imageCache[name]; + } + else + { + var image = ResourceHelper.GetImageFromResources(name); + _imageCache.Add(name, image); + return image; + } + } + + public bool CanOpen => false; + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItem.cs new file mode 100644 index 000000000..8adc26dc7 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItem.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.Core; +using Tango.SharedUI.Helpers; + +namespace Tango.Scripting.IDE +{ + public abstract class ProjectItem : ExtendedObject, IProjectItem + { + private static Dictionary _imageCache; + + static ProjectItem() + { + _imageCache = new Dictionary(); + } + + public string Name { get; set; } + public ObservableCollection Items { get; set; } + + public ProjectItem() + { + Items = new ObservableCollection(); + } + + public abstract BitmapSource Image { get; } + + public abstract FrameworkElement OnGetView(); + + private FrameworkElement GetView() + { + return OnGetView(); + } + + protected static BitmapSource GetImage(String name) + { + if (_imageCache.ContainsKey(name)) + { + return _imageCache[name]; + } + else + { + var image = ResourceHelper.GetImageFromResources(name); + _imageCache.Add(name, image); + return image; + } + } + + public abstract bool CanOpen { get; } + public FrameworkElement View => GetView(); + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/CSharpScriptItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/CSharpScriptItem.cs new file mode 100644 index 000000000..cf4811047 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/CSharpScriptItem.cs @@ -0,0 +1,30 @@ +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.IDE.ProjectItemsViews; + +namespace Tango.Scripting.IDE.ProjectItems +{ + public class CSharpScriptItem : ProjectItem + { + public override BitmapSource Image => GetImage("Images/CSharpScriptItem.png"); + + private String _code; + public String Code + { + get { return _code; } + set { _code = value; RaisePropertyChangedAuto(); } + } + + public override bool CanOpen => true; + + public override FrameworkElement OnGetView() + { + return new CSharpScriptItemView(this); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssembliesItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssembliesItem.cs new file mode 100644 index 000000000..0e66fd241 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssembliesItem.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE.ProjectItems +{ + public class ReferenceAssembliesItem : ProjectItem + { + public ReferenceAssembliesItem() + { + Name = "References"; + } + + public override BitmapSource Image => GetImage("Images/Reference.png"); + + public override FrameworkElement OnGetView() + { + return null; + } + + public override bool CanOpen => false; + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssemblyItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssemblyItem.cs new file mode 100644 index 000000000..e9cd1e8f2 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItems/ReferenceAssemblyItem.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE.ProjectItems +{ + public class ReferenceAssemblyItem : ProjectItem + { + public String Path { get; set; } + public override BitmapSource Image => GetImage("Images/Reference.png"); + + public override FrameworkElement OnGetView() + { + return null; + } + + public override bool CanOpen => false; + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml new file mode 100644 index 000000000..682956205 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml.cs new file mode 100644 index 000000000..34c604b83 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectItemsViews/CSharpScriptItemView.xaml.cs @@ -0,0 +1,29 @@ +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; +using Tango.Scripting.IDE.ProjectItems; + +namespace Tango.Scripting.IDE.ProjectItemsViews +{ + /// + /// Interaction logic for CSharpScriptItemView.xaml + /// + public partial class CSharpScriptItemView : UserControl + { + public CSharpScriptItemView(CSharpScriptItem scriptItem) + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/StubProjectType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/StubProjectType.cs new file mode 100644 index 000000000..e5947a38e --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/StubProjectType.cs @@ -0,0 +1,45 @@ +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.IDE.ProjectItems; +using Tango.Scripting.IDE.Projects; + +namespace Tango.Scripting.IDE.ProjectTypes +{ + public class StubProjectType : IProjectType + { + public IProject NewProject(string projectPath) + { + StubProject project = new StubProject(); + + project.FilePath = projectPath; + + var referenceAssembliesItem = new ReferenceAssembliesItem(); + + referenceAssembliesItem.Items.Add(new ReferenceAssemblyItem() + { + Path = "mscorelib.dll", + Name = "System.dll", + }); + referenceAssembliesItem.Items.Add(new ReferenceAssemblyItem() + { + Path = "System.Core.dll", + Name = "System.Core.dll", + }); + + project.Items.Add(referenceAssembliesItem); + + project.Items.Add(new CSharpScriptItem() { Name = "main.csx" }); + + return project; + } + + public string Name => "Unit Test Project"; + public string Description => "Create a unit test project template."; + public BitmapSource Image { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/UnitTestProjectType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/UnitTestProjectType.cs new file mode 100644 index 000000000..4519e5aca --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ProjectTypes/UnitTestProjectType.cs @@ -0,0 +1,43 @@ +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.IDE.ProjectItems; +using Tango.Scripting.IDE.Projects; + +namespace Tango.Scripting.IDE.ProjectTypes +{ + public class UnitTestProjectType : IProjectType + { + public IProject NewProject(string projectPath) + { + UnitTestProject project = new UnitTestProject(); + + project.FilePath = projectPath; + + var referenceAssembliesItem = new ReferenceAssembliesItem(); + + referenceAssembliesItem.Items.Add(new ReferenceAssemblyItem() + { + Path = "mscorelib.dll", + Name = "System.dll", + }); + referenceAssembliesItem.Items.Add(new ReferenceAssemblyItem() + { + Path = "System.Core.dll", + Name = "System.Core.dll", + }); + + project.Items.Add(referenceAssembliesItem); + + return project; + } + + public string Name => "Unit Test Project"; + public string Description => "Create a unit test project template."; + public BitmapSource Image { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/CSharpProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/CSharpProject.cs new file mode 100644 index 000000000..62e830d06 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/CSharpProject.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE.Projects +{ + public abstract class CSharpProject : Project + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/StubProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/StubProject.cs new file mode 100644 index 000000000..bc915fa77 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/StubProject.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE.Projects +{ + public class StubProject : CSharpProject + { + public override BitmapSource Image => GetImage("Images/StubProject.png"); + + public override Task Build() + { + throw new NotImplementedException(); + } + + public override Task Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/UnitTestProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/UnitTestProject.cs new file mode 100644 index 000000000..e5510ad45 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Projects/UnitTestProject.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.IDE.Projects +{ + public class UnitTestProject : CSharpProject + { + public override BitmapSource Image { get; } + + public override Task Build() + { + throw new NotImplementedException(); + } + + public override Task Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml index 3393e6888..ef5d1b599 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Resources.xaml @@ -1,8 +1,127 @@  - #202020 - + #202020 + #252526 + #2D2D30 + #676767 + #007ACC + #007ACC + + + + + + - \ No newline at end of file + + + + + #2D2D30 + #FFFFFFFF + #2D2D30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml index 3636089da..7fc5bf930 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEView.xaml @@ -3,9 +3,13 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:fa="http://schemas.fontawesome.io/icons/" + xmlns:controls="clr-namespace:Tango.Scripting.IDE.Controls" xmlns:local="clr-namespace:Tango.Scripting.IDE" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:ScriptIDEViewVM, IsDesignTimeCreatable=False}"> + d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:ScriptIDEViewVM, IsDesignTimeCreatable=False}" x:Name="control"> @@ -17,6 +21,7 @@ + @@ -28,7 +33,7 @@ - + @@ -58,7 +63,7 @@ - + @@ -69,20 +74,72 @@ - + + + + + + + + + + + - + - + - + - + + + + + + + + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs index 16644b6da..e52b58775 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/ScriptIDEViewVM.cs @@ -1,19 +1,108 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Scripting.IDE.Projects; +using Tango.Scripting.IDE.ProjectTypes; using Tango.SharedUI; namespace Tango.Scripting.IDE { public class ScriptIDEViewVM : ViewModel { - private IScriptProject _project; - public IScriptProject Project + private List _projectTypes; + + #region Properties + + private Solution _solution; + public Solution Solution + { + get { return _solution; } + set { _solution = value; RaisePropertyChangedAuto(); } + } + + private IProject _selectedProject; + public IProject SelectedProject + { + get { return _selectedProject; } + set { _selectedProject = value; RaisePropertyChangedAuto(); } + } + + private IProjectItem _selectedProjectItem; + public IProjectItem SelectedProjectItem + { + get { return _selectedProjectItem; } + set { _selectedProjectItem = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection _openProjectItems; + public ObservableCollection OpenProjectItems + { + get { return _openProjectItems; } + set { _openProjectItems = value; RaisePropertyChangedAuto(); } + } + + #endregion + + #region Commands + + public RelayCommand OpenProjectItemCommand { get; set; } + + public RelayCommand CloseProjectItemCommand { get; set; } + + #endregion + + #region Constructors + + public ScriptIDEViewVM() { - get { return _project; } - set { _project = value; RaisePropertyChangedAuto(); } + _projectTypes = new List(); + OpenProjectItems = new ObservableCollection(); + + RegisterProjectType(new StubProjectType()); + + Solution = new Solution(); + Solution.Projects.Add(_projectTypes.First().NewProject("Test Project.stub")); + + //Init Commands + OpenProjectItemCommand = new RelayCommand(OpenProjectItem); + CloseProjectItemCommand = new RelayCommand(CloseProjectItem); + } + + #endregion + + #region Public Methods + + private void OpenProjectItem(IProjectItem projectItem) + { + if (!OpenProjectItems.Contains(projectItem)) + { + OpenProjectItems.Add(projectItem); + } + + SelectedProjectItem = projectItem; + } + + private void CloseProjectItem(IProjectItem projectItem) + { + OpenProjectItems.Remove(projectItem); + + SelectedProjectItem = OpenProjectItems.FirstOrDefault(); + } + + public void RegisterProjectType(IProjectType projectType) + { + _projectTypes.Add(projectType); } + + public void UnRegisterProjectItemHandler(IProjectType projectType) + { + _projectTypes.Remove(projectType); + } + + #endregion } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Solution.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Solution.cs new file mode 100644 index 000000000..eded27413 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Solution.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE +{ + public class Solution + { + public ObservableCollection Projects { get; set; } + + public Solution() + { + Projects = new ObservableCollection(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs deleted file mode 100644 index 88f538e7c..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/StubsProject.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Scripting.IDE -{ - public class StubsProject : IScriptProject - { - public string Name { get; set; } - public string FilePath { get; set; } - public ObservableCollection References { get; set; } - public ObservableCollection Items { get; set; } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj index 7c3b47ea6..d3d81640a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Tango.Scripting.IDE.csproj @@ -31,6 +31,9 @@ 4 + + ..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll + ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll @@ -60,13 +63,41 @@ - - + + + NewProjectDialog.xaml + + + + + + + CSharpScriptItemView.xaml + + + + + + + + + + + ScriptIDEView.xaml - + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -98,6 +129,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator @@ -114,5 +146,20 @@ Tango.Scripting + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml index d7cedf6c6..643fbf889 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Themes/Generic.xaml @@ -1,8 +1,26 @@ - + + diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/app.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/app.config new file mode 100644 index 000000000..a00da21b0 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/app.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config index 07b683c3f..893958c68 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file -- cgit v1.3.1