diff options
| author | Avi Levkovich <avi@twine-s.com> | 2019-03-11 12:09:21 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2019-03-11 12:09:21 +0200 |
| commit | 5fa5212d329651dfed37575e8bd942e974030083 (patch) | |
| tree | d2800a0f17fea6109b1be0ee2e652c4cec7b93dd /Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors | |
| parent | eaeb19841e1d5195362ec1bd1fa8fb70557932cc (diff) | |
| parent | 42a4c114efafe342f562eb8ab8b28e994fccd74c (diff) | |
| download | Tango-5fa5212d329651dfed37575e8bd942e974030083.tar.gz Tango-5fa5212d329651dfed37575e8bd942e974030083.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors')
51 files changed, 2201 insertions, 269 deletions
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..7766d323a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs @@ -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 @@ -289,7 +290,7 @@ namespace Tango.Scripting.Editors.CodeCompletion //sourceIsInitialized = true; } - private void SetPosition() + public void SetPosition() { if (document != null && this.StartOffset != this.TextArea.Caret.Offset) { @@ -300,6 +301,16 @@ namespace Tango.Scripting.Editors.CodeCompletion SetPosition(this.TextArea.Caret.Position); } } + + public void UpdatePositionFix() + { + SetPosition(this.TextArea.Caret.Position); + } + + //public void UpdatePosition() + //{ + // SetPosition(this.TextArea.Caret.Position); + //} /// <inheritdoc/> protected override void OnClosed(EventArgs e) @@ -336,7 +347,7 @@ namespace Tango.Scripting.Editors.CodeCompletion /// Updates the position of the CompletionWindow based on the parent TextView position and the screen working area. /// It ensures that the CompletionWindow is completely visible on the screen. /// </summary> - protected void UpdatePosition() + public void UpdatePosition() { TextView textView = this.TextArea.TextView; // PointToScreen returns device dependent units (physical pixels) @@ -367,6 +378,8 @@ namespace Tango.Scripting.Editors.CodeCompletion bounds = bounds.TransformFromDevice(textView); this.Left = bounds.X; this.Top = bounds.Y; + + Debug.WriteLine($"Position: {Left}x{Top}"); } /// <inheritdoc/> diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs index b0e9eeccb..9f16876b3 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/ICompletionData.cs @@ -3,6 +3,7 @@ using System; using System.Windows.Media; +using System.Windows.Media.Imaging; using Tango.Scripting.Editors.Document; using Tango.Scripting.Editors.Editing; @@ -13,32 +14,26 @@ namespace Tango.Scripting.Editors.CodeCompletion /// </summary> public interface ICompletionData { - /// <summary> - /// Gets the image. - /// </summary> - ImageSource Image { get; } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - string Text { get; } - - /// <summary> - /// The displayed content. This can be the same as 'Text', or a WPF UIElement if - /// you want to display rich content. - /// </summary> - object Content { get; } + /// <summary> + /// Gets the image. + /// </summary> + BitmapSource Image { get; } + + /// <summary> + /// Gets the text. This property is used to filter the list of visible elements. + /// </summary> + string Text { get; } /// <summary> /// Gets the description. /// </summary> - object Description { get; } + object Description { get; set; } /// <summary> /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items /// which the user is accessing most frequently. /// </summary> - double Priority { get; } + double Priority { get; set; } /// <summary> /// Perform the completion. @@ -49,6 +44,6 @@ namespace Tango.Scripting.Editors.CodeCompletion /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how /// the insertion was triggered.</param> - void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs); + void Complete(ScriptEditor editor); } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/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/ExtensionMethods.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ExtensionMethods.cs new file mode 100644 index 000000000..1605ff281 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ExtensionMethods.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors +{ + internal static class ExtensionMethodsNoName + { + public static String Remove(this String str, String pattern) + { + return Regex.Replace(str, pattern, ""); + } + + public static String GetFriendlyName(this Type type) + { + String name = type.Name; + + if (type.IsGenericType) + { + List<String> args = new List<string>(); + + foreach (var lGenericArgument in type.GetGenericTypeDefinition().GetGenericArguments()) + { + args.Add(lGenericArgument.Name); + } + + String gArgs = String.Join(",", args); + + name = $"{new String(type.Name.TakeWhile(x => x != '`').ToArray())}<{gArgs}>"; + } + + return name; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/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 @@ <Word>uint</Word> <Word>ushort</Word> <Word>ulong</Word> + <Word>null</Word> </Keywords> <Keywords color="ReferenceTypes"> 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 Binary files differnew file mode 100644 index 000000000..91b35a829 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/class.png 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 Binary files differnew file mode 100644 index 000000000..b79aa844f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/enum.png 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 Binary files differnew file mode 100644 index 000000000..3b07597dd --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/interface.png 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 Binary files differnew file mode 100644 index 000000000..249689941 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/method.png 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 Binary files differnew file mode 100644 index 000000000..7f2b6b5ef --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/namespace.png 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 Binary files differnew file mode 100644 index 000000000..001a8c66a --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/property.png 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 Binary files differdeleted file mode 100644 index 28abc36a7..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubclass.gif +++ /dev/null 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 Binary files differdeleted file mode 100644 index 7c2466f0e..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubevent.gif +++ /dev/null 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 Binary files differdeleted file mode 100644 index 040280d15..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubmethod.gif +++ /dev/null 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 Binary files differdeleted file mode 100644 index 49d5042b9..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/pubproperty.gif +++ /dev/null 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 Binary files differnew file mode 100644 index 000000000..02fbdbde7 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Images/struct.png diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs new file mode 100644 index 000000000..a1734ba30 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItem.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class ClassCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("class.png"); + + public override BitmapSource Image => image; + public override string Text => Name; + + public String Name { get; set; } + public String Namespace { get; set; } + public override CompletionItemPopupControl PopupControl => new ClassCompletionItemPopup(); + + public override void Complete(ScriptEditor editor) + { + base.Complete(editor); + + if (Text.Contains("<T>")) + { + editor.CaretOffset -= 2; + editor.Select(editor.CaretOffset, 1); + } + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs new file mode 100644 index 000000000..d575ba9db --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ClassCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class ClassCompletionItemPopup : CompletionItemPopupControl + { + static ClassCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ClassCompletionItemPopup), new FrameworkPropertyMetadata(typeof(ClassCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs new file mode 100644 index 000000000..83ada090f --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.Scripting.Editors.Document; +using Tango.Scripting.Editors.Editing; + +namespace Tango.Scripting.Editors.Intellisense +{ + public abstract class CompletionItem : DependencyObject, ICompletionItem + { + public abstract string Text { get; } + public object Description { get; set; } + public double Priority { get; set; } + public abstract CompletionItemPopupControl PopupControl { get; } + + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + public static readonly DependencyProperty IsSelectedProperty = + DependencyProperty.Register("IsSelected", typeof(bool), typeof(CompletionItem), new PropertyMetadata(false)); + + public virtual void Complete(ScriptEditor editor) + { + int index = editor.GetCurrentWordStartIndex(); + int max = editor.GetCurrentLine().EndOffset; + + editor.Document.Replace(index, Math.Min(max - index, Text.Length), Text); + } + + public abstract BitmapSource Image { get; } + + protected static BitmapSource GetImage(String name) + { + return new BitmapImage(new Uri($"pack://application:,,,/Tango.Scripting.Editors;component/Images/{name}", UriKind.Absolute)); + } + + public override string ToString() + { + return Text; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs new file mode 100644 index 000000000..14e5b6681 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/CompletionItemPopupControl.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace Tango.Scripting.Editors.Intellisense +{ + public abstract class CompletionItemPopupControl : Control + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs new file mode 100644 index 000000000..c8f34347e --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItem.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class EnumCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("enum.png"); + + public override BitmapSource Image => image; + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new EnumCompletionItemPopup(); + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs new file mode 100644 index 000000000..0ef29c338 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/EnumCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class EnumCompletionItemPopup : CompletionItemPopupControl + { + static EnumCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(EnumCompletionItemPopup), new FrameworkPropertyMetadata(typeof(EnumCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs new file mode 100644 index 000000000..83e304e8b --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Scripting.Editors.CodeCompletion; + +namespace Tango.Scripting.Editors.Intellisense +{ + public interface ICompletionItem : ICompletionData + { + CompletionItemPopupControl PopupControl { get; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs new file mode 100644 index 000000000..bc48ce401 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/ICompletionProvider.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public interface ICompletionProvider + { + + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs new file mode 100644 index 000000000..56f6db7af --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItem.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class InterfaceCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("interface.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new InterfaceCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs new file mode 100644 index 000000000..126a81c4c --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/InterfaceCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class InterfaceCompletionItemPopup : CompletionItemPopupControl + { + static InterfaceCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(InterfaceCompletionItemPopup), new FrameworkPropertyMetadata(typeof(InterfaceCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs new file mode 100644 index 000000000..06282e15d --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -0,0 +1,320 @@ +using System; +using System.Collections; +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<Assembly, XmlDocument> _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<KnownTypeConstructor> _constructors; + public List<KnownTypeConstructor> Constructors + { + get + { + InitTypeDocumentation(); + return _constructors; + } + private set { _constructors = value; } + } + + private List<KnownTypeMethod> _methods; + public List<KnownTypeMethod> Methods + { + get + { + InitTypeDocumentation(); + return _methods; + } + private set { _methods = value; } + } + + private List<KnownTypeProperty> _properties; + public List<KnownTypeProperty> Properties + { + get + { + InitTypeDocumentation(); + return _properties; + } + private set { _properties = value; } + } + + public List<KnownTypeMember> Members + { + get + { + List<KnownTypeMember> members = new List<KnownTypeMember>(); + + members.AddRange(Properties); + members.AddRange(Methods); + + return members.OrderBy(x => x.Name).ToList(); + } + } + + static KnownType() + { + _assemblies_docs_cache = new Dictionary<Assembly, XmlDocument>(); + } + + public KnownType(Type type) + { + _summary = "Loading documentation..."; + _constructors = new List<KnownTypeConstructor>(); + _methods = new List<KnownTypeMethod>(); + _properties = new List<KnownTypeProperty>(); + Type = type; + Name = type.Name; + + Init(); + } + + public override string ToString() + { + return Type.ToString(); + } + + private void Init() + { + InitTypeDefinition(); + InitFriendlyName(); + InitTypeDocumentation(); + } + + private void InitFriendlyName() + { + FriendlyName = Type.GetFriendlyName(); + } + + 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) + { + _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); + } + } + + if (xmlDoc != null) + { + Task.Factory.StartNew(() => + { + + //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<XmlNode>().ToList(); + var constructors = Type.GetConstructors().Where(x => x.IsPublic).ToList(); + + for (int i = 0; i < constructors.Count; i++) + { + var constructor = constructors[i]; + XmlNode cDoc = null; + + if (i < docNodes.Count) + { + 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<XmlNode>().ToList() : new List<XmlNode>(); + + 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) + { + 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<XmlNode>().ToList(); + var methods = Type.GetRuntimeMethods().Where(x => x.IsPublic && !x.IsSpecialName).ToList(); + + //TODO: Separate extension methods! + methods.AddRange(Type.GetExtensionMethods(Type.Assembly).ToList()); + + if (typeof(IEnumerable).IsAssignableFrom(Type)) + { + var linqMethods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList(); + methods.AddRange(linqMethods); + } + + 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(); + + var parameters = method.GetParameters().ToList(); + var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); + + bool isLinq = method.DeclaringType == typeof(Enumerable); + + 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) + { + p.IsLast = true; + } + + if (j == 0 && isLinq) continue; + m.Parameters.Add(p); + } + + _methods.Add(m); + } + } + + //Load Properties + { + string path = "P:" + Type.FullName; + + var docNodes = xmlDoc.SelectNodes("//member[starts-with(@name, '" + path + "')]").OfType<XmlNode>().ToList(); + var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); + + 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); + } + } + + }); + } + + _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<KnownTypeMethodParameter> Parameters { get; set; } + + public KnownTypeConstructor() + { + Parameters = new List<KnownTypeMethodParameter>(); + } + + 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..1405a8c34 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMember.cs @@ -0,0 +1,31 @@ +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 String ReturnTypeFriendlyName { 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..0ae4b708e --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs @@ -0,0 +1,23 @@ +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 List<KnownTypeMethodParameter> Parameters { get; set; } + + public KnownTypeMethod() + { + Parameters = new List<KnownTypeMethodParameter>(); + } + + 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..59f6db4fd --- /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 String Type { get; set; } + public String Name { get; set; } + public String Description { get; set; } + public bool IsLast { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/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/Intellisense/MethodCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItem.cs new file mode 100644 index 000000000..0a0883ede --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItem.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class MethodCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("method.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new MethodCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Class { get; set; } + public String Name { get; set; } + public String ReturnType { get; set; } + + public int Overloads { get; set; } + + public bool HasOverloads + { + get { return Overloads > 0; } + } + + public List<KnownTypeMethodParameter> Parameters { get; set; } + + public MethodCompletionItem() + { + Parameters = new List<KnownTypeMethodParameter>(); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs new file mode 100644 index 000000000..1b9717307 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/MethodCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class MethodCompletionItemPopup : CompletionItemPopupControl + { + static MethodCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MethodCompletionItemPopup), new FrameworkPropertyMetadata(typeof(MethodCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs new file mode 100644 index 000000000..d5c8db38a --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItem.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class NamespaceCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("namespace.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new NamespaceCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Assembly { get; set; } + + public override void Complete(ScriptEditor editor) + { + var line = editor.GetCurrentLine(); + editor.Document.Replace(line, "using " + Name); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs new file mode 100644 index 000000000..7adc82fd8 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/NamespaceCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class NamespaceCompletionItemPopup : CompletionItemPopupControl + { + static NamespaceCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(NamespaceCompletionItemPopup), new FrameworkPropertyMetadata(typeof(NamespaceCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.cs new file mode 100644 index 000000000..c301e8ede --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItem.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class PropertyCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("property.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new PropertyCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Class { get; set; } + public String Type { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs new file mode 100644 index 000000000..7790d6c43 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/PropertyCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class PropertyCompletionItemPopup : CompletionItemPopupControl + { + static PropertyCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyCompletionItemPopup), new FrameworkPropertyMetadata(typeof(PropertyCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs new file mode 100644 index 000000000..b89a7cee2 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItem.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class StructCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("struct.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new StructCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Namespace { get; set; } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs new file mode 100644 index 000000000..09512f405 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/StructCompletionItemPopup.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class StructCompletionItemPopup : CompletionItemPopupControl + { + static StructCompletionItemPopup() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(StructCompletionItemPopup), new FrameworkPropertyMetadata(typeof(StructCompletionItemPopup))); + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/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<ParameterDescription> Parameters { get; set; } + + public MethodDescription() + { + Parameters = new List<ParameterDescription>(); + } + } +} 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<MethodDescription> 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<MethodDescription>(); + } + + 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<VisualLine> VisualLines { get { - if (visibleVisualLines == null) - throw new VisualLinesInvalidException(); - return visibleVisualLines; + if (visibleVisualLines == null) + { + return new ReadOnlyCollection<VisualLine>(new List<VisualLine>()); + } + 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..49d745d6c 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -8,9 +9,11 @@ using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; @@ -27,6 +30,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 +41,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<String> _current_usings; - private List<Type> _knownTypes; + private List<KnownType> _knownTypes; private List<INamedTypeSymbol> _declaredTypes; - private Dictionary<Type, String> _known_types_docs_cache; - private Dictionary<Assembly, XmlDocument> _assemblies_docs_cache; #region Mini Classes @@ -56,112 +60,17 @@ namespace Tango.Scripting.Editors public int Index { get; set; } } - #endregion - - #region Completion - - /// <summary> - /// Represents an auto complete item. - /// </summary> - /// <seealso cref="ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData" /> - internal class CompletionData : DependencyObject, ICompletionData + private class ConstructionSession { - private String _description; - - /// <summary> - /// Gets or sets the icon source. - /// </summary> - public BitmapSource Source { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="CompletionData"/> class. - /// </summary> - /// <param name="name">The text.</param> - /// <param name="description">The description.</param> - public CompletionData(String type, string name, String ns, String description) - { - Type = type; - this.Text = name; - Namespace = ns; - _description = description; - } - - /// <summary> - /// Gets the image. - /// </summary> - public System.Windows.Media.ImageSource Image - { - get { return Source; } - } - - /// <summary> - /// Gets the text. This property is used to filter the list of visible elements. - /// </summary> - public string Text { get; private set; } - - // Use this property if you want to show a fancy UIElement in the drop down list. - public object Content - { - get { return this.Text; } - } - - /// <summary> - /// Gets the description. - /// </summary> - public object Description - { - get { return _description; } - } - - public String Type { get; set; } - - public String Namespace { get; set; } - - /// <summary> - /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items - /// which the user is accessing most frequently. - /// </summary> - public double Priority { get { return 0; } } - - /// <summary> - /// Perform the completion. - /// </summary> - /// <param name="textArea">The text area on which completion is performed.</param> - /// <param name="completionSegment">The text segment that was used by the completion window if - /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset).</param> - /// <param name="insertionRequestEventArgs">The EventArgs used for the insertion request. - /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how - /// the insertion was triggered.</param> - public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) - { - textArea.Document.Replace(completionSegment, this.Text); - } - - public bool IsSelected - { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } - } - public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register("IsSelected", typeof(bool), typeof(CompletionData), new PropertyMetadata(false, IsSelectedChanged)); - - private static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - Debug.WriteLine("Selected"); - } - - + public KnownType Type { get; set; } + public int ParameterIndex { get; set; } + public List<String> TypeArguments { get; set; } + } - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Text; - } + private class MethodSession + { + public KnownType Type { get; set; } + public String MethodName { get; set; } } #endregion @@ -201,6 +110,15 @@ namespace Tango.Scripting.Editors public static readonly DependencyProperty ReferenceAssembliesProperty = DependencyProperty.Register("ReferenceAssemblies", typeof(ObservableCollection<ReferenceAssembly>), 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 +136,6 @@ namespace Tango.Scripting.Editors /// </summary> public ScriptEditor() { - _known_types_docs_cache = new Dictionary<Type, string>(); - _assemblies_docs_cache = new Dictionary<Assembly, XmlDocument>(); _declaredTypes = new List<INamedTypeSymbol>(); _current_usings = new List<string>(); @@ -230,7 +146,7 @@ namespace Tango.Scripting.Editors ReferenceAssemblies.Add(new ReferenceAssembly(typeof(String))); //mscorelib ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Enumerable))); //System.Core - _knownTypes = new List<Type>(); + _knownTypes = new List<KnownType>(); _parser = new ScriptParser(); TextArea.IndentationStrategy = new Indentation.CSharp.CSharpIndentationStrategy(Options); @@ -410,11 +326,128 @@ 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 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 > 1) + { + tree.RemoveAt(0); + var variables = _parser.GetScriptVariables(Document.Text); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); + + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } + + return new MethodSession() + { + Type = knownType, + MethodName = tree.Last(), + }; + } + } + } + } + + return null; + } + + public List<String> GetPreviousWords() + { + var currentLine = GetCurrentLine(); + var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); + return currentText.Split(' ').ToList(); + } + #endregion #region Highlighting - private async void InvalidateHighlighting() + private void InvalidateHighlighting() { _parser.GetDeclaredTypes(Text); @@ -423,26 +456,29 @@ namespace Tango.Scripting.Editors var assemblies = ReferenceAssemblies.ToList(); var usings = _current_usings.ToList(); - foreach (var asm in assemblies.Select(x => x.Assembly)) + Thread t = new Thread(() => { - Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => + foreach (var asm in assemblies.Select(x => x.Assembly)) { - if (usings.Exists(x => type.Namespace == x)) + Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => { - lock (_knownTypes) + if (usings.Exists(x => type.Namespace == x)) { - _knownTypes.Add(type); + lock (_knownTypes) + { + if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + { + _knownTypes.Add(new KnownType(type)); + } + } } - } - }); - } - - if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) - { - String text = String.Empty; + }); + } - await Task.Factory.StartNew(() => + if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) { + String text = String.Empty; + Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); using (StreamReader reader = new StreamReader(xshd_stream)) @@ -453,22 +489,25 @@ namespace Tango.Scripting.Editors List<String> referenceTypes = new List<string>(); List<String> interfaceTypes = new List<string>(); - 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("<Word>{0}</Word>", name)); - } - else if (type.IsInterface || type.IsEnum) - { - interfaceTypes.Add(String.Format("<Word>{0}</Word>", name)); + if (type.Type.ContainsGenericParameters) + { + name = new String(name.TakeWhile(x => x != '`').ToArray()); + } + + if (type.Type.IsInterface || type.Type.IsEnum) + { + interfaceTypes.Add(String.Format("<Word>{0}</Word>", name)); + } + else if (type.Type.IsClass) + { + referenceTypes.Add(String.Format("<Word>{0}</Word>", name)); + } } } @@ -493,15 +532,22 @@ namespace Tango.Scripting.Editors { text = text.Replace("<Word>@InterfaceTypes@</Word>", String.Join(Environment.NewLine, interfaceTypes.Distinct())); } - }); - using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text))) - { + MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); + XmlTextReader xshd_reader = new XmlTextReader(ms); - SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); - xshd_reader.Close(); + + Dispatcher.BeginInvoke(new Action(() => + { + SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); + xshd_reader.Close(); + ms.Dispose(); + })); + } - } + }); + t.IsBackground = true; + t.Start(); } private void InvalidateScriptTypesHighlightings() @@ -545,12 +591,40 @@ namespace Tango.Scripting.Editors /// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs" /> that contains the event data.</param> 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 /// <summary> @@ -605,12 +679,144 @@ namespace Tango.Scripting.Editors { List<Object> items = new List<object>(); - if (e.Text == ".") + HidePopup(); + + var lineText = GetCurrentLineText(); + var previousWordsLast = GetPreviousWords().LastOrDefault(); + String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; + String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); + + + if (e.Text == " " && GetPreviousWord() == "new") { - var word = GetCurrentWord(); + var s = _parser.GetExpression<FieldDeclarationSyntax>(GetCurrentLineText()); + + if (s != null) + { + String type = s.Declaration.Type.ToString(); + + IList<ICompletionData> data = new List<ICompletionData>(); + + data.Add(new ClassCompletionItem() + { + Name = type, + Description = "Auto generate assignment...", + }); + + ShowCompletionWindow(data, type); + } } - else + else if (e.Text == ";" || e.Text == " ") { + HideCompletionWindow(); + } + else if (e.Text == ".") + { + var knownType = GetCurrentKnownType(); + + if (knownType != null) + { + completionWindow.HideCompletion(); + IList<ICompletionData> data = new List<ICompletionData>(); + + var typeMembers = knownType.Members.ToList(); + + foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) + { + var member = methodGroup.First(); + + if (member.GetType() == typeof(KnownTypeMethod)) + { + var method = member as KnownTypeMethod; + + data.Add(new MethodCompletionItem() + { + Class = knownType.FriendlyName, + Name = method.Name, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); + + } + else + { + data.Add(new PropertyCompletionItem() + { + Class = knownType.FriendlyName, + Name = member.Name, + Type = member.ReturnTypeFriendlyName, + Description = member.Summary, + }); + } + } + + ShowCompletionWindow(data, GetCurrentWord()); + } + } + else if (e.Text == "(" || e.Text == ",") + { + 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) + { + var content = CreateMethodSessionPopupContent(methodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + } + } + + var a = GetMethodSession(); + } + else if (lineText.StartsWith("using")) + { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } + + IList<ICompletionData> data = new List<ICompletionData>(); + + foreach (var asm in ReferenceAssemblies) + { + foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) + { + data.Add(new NamespaceCompletionItem() + { + Name = ns, + Assembly = asm.Assembly.GetName().Name, + }); + } + } + + data = data.DistinctBy(x => x.Text).ToList(); + + ShowCompletionWindow(data, GetCurrentWord()); + } + else if (!currentWordIncludingParenthesis.Contains(".")) + { + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } + var previous_word = GetPreviousWord(); var word = GetCurrentWord(); @@ -631,33 +837,97 @@ namespace Tango.Scripting.Editors { if (char.IsUpper(word.First())) { - IList<ICompletionData> data = completionWindow.CompletionList.CompletionData; - data.Clear(); + IList<ICompletionData> data = new List<ICompletionData>(); 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...")); + if (type.TypeKind == TypeKind.Struct) + { + data.Add(new StructCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Enum) + { + data.Add(new EnumCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Interface) + { + data.Add(new InterfaceCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else if (type.TypeKind == TypeKind.Class) + { + data.Add(new ClassCompletionItem() + { + Name = type.Name, + Description = "Declared inside the current script...", + Namespace = type.ContainingNamespace?.Name, + }); + } + else + { + throw new NotImplementedException("Implement generic item here!"); + } } foreach (var type in _knownTypes.Where(x => x.Name.StartsWith(word))) { - String doc = GetKnownTypeDocumentation(type); - data.Add(new CompletionData(GetTypeOfType(type), type.Name, type.Namespace, doc)); - } - - if (data.Count > 0) - { - completionWindow.ShowCompletion(); - - if (completionWindow.CompletionList.ListBox != null) + if (type.Type.IsEnum) { - completionWindow.CompletionList.SelectItemFiltering(word); + data.Add(new EnumCompletionItem() + { + Namespace = type.Type.Namespace, + Description = type.Summary, + Name = type.FriendlyName, + }); + } + else if (type.Type.IsInterface) + { + data.Add(new InterfaceCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else if (type.Type.IsValueType) + { + data.Add(new StructCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else if (type.Type.IsClass) + { + data.Add(new ClassCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + }); + } + else + { + throw new NotImplementedException("Implement generic item here."); } } - else - { - completionWindow.HideCompletion(); - } + + ShowCompletionWindow(data, word); } } } @@ -665,67 +935,37 @@ namespace Tango.Scripting.Editors private void CompletionWindow_InsertionRequest(ICompletionData item) { - int index = GetCurrentWordStartIndex(); - int max = GetCurrentLine().EndOffset; - - Document.Replace(index, Math.Min(max - index, item.Text.Length), item.Text); + item.Complete(this); } - private String GetKnownTypeDocumentation(Type type) + private void ShowCompletionWindow(IList<ICompletionData> suggestions, String filter) { - if (_known_types_docs_cache.ContainsKey(type)) - { - return _known_types_docs_cache[type]; - } - - XmlDocument _docuDoc = null; + IList<ICompletionData> data = completionWindow.CompletionList.CompletionData; + data.Clear(); - 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)) - { - _docuDoc = new XmlDocument(); - _docuDoc.Load(docuPath); - } - else if (File.Exists(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath)))) + if (completionWindow.CompletionList.ListBox != null) { - _docuDoc = new XmlDocument(); - _docuDoc.Load(System.IO.Path.Combine(dotNetXmlFolder, System.IO.Path.GetFileName(docuPath))); + completionWindow.CompletionList.SelectItemFiltering(filter); } - - _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<String> GetScriptClassNames() @@ -775,6 +1015,181 @@ namespace Tango.Scripting.Editors return list; } + private KnownType GetCurrentKnownType() + { + var expression = GetPreviousWords().LastOrDefault(); + + if (expression != null) + { + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); + var variableName = tree.FirstOrDefault(); + + if (variableName != null) + { + tree.RemoveAt(0); + var variables = _parser.GetScriptVariables(Document.Text); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); + + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } + + return knownType; + } + } + } + } + + return null; + } + + #endregion + + #region Popup + + 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; + + //if (session.Type.Type.IsGenericType && session.TypeArguments != null) + //{ + // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>"; + //} + + var parameters = m.Parameters; + + foreach (var p in parameters) + { + ParameterDescription pDescription = new ParameterDescription(method); + pDescription.Name = p.Name; + pDescription.Type = p.Type; + pDescription.Description = p.Description; + method.Parameters.Add(pDescription); + } + + popup.Methods.Add(method); + } + + //if (false) + //{ + // popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1); + + // if (popup.CurrentMethod == null) + // { + // popup.CurrentMethod = popup.Methods.FirstOrDefault(); + // } + //} + //else + //{ + popup.CurrentMethod = popup.Methods.FirstOrDefault(); + //} + + if (popup.CurrentMethod != null) + { + popup.CurrentMethodIndex = popup.Methods.IndexOf(popup.CurrentMethod) + 1; + } + + return popup; + } + #endregion } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj index 18ed1ff70..5422ba805 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj @@ -189,6 +189,19 @@ <Compile Include="CodeCompletion\IOverloadProvider.cs" /> <Compile Include="CodeCompletion\OverloadInsightWindow.cs" /> <Compile Include="CodeCompletion\OverloadViewer.cs" /> + <Compile Include="Converters\BooleanToVisibilityConverter.cs" /> + <Compile Include="Converters\BooleanToVisibilityInversedConverter.cs" /> + <Compile Include="ExtensionMethods.cs" /> + <Compile Include="Intellisense\ClassCompletionItemPopup.cs" /> + <Compile Include="Intellisense\CompletionItem.cs" /> + <Compile Include="Intellisense\CompletionItemPopupControl.cs" /> + <Compile Include="Intellisense\EnumCompletionItem.cs" /> + <Compile Include="Intellisense\EnumCompletionItemPopup.cs" /> + <Compile Include="Intellisense\ICompletionItem.cs" /> + <Compile Include="Intellisense\ICompletionProvider.cs" /> + <Compile Include="Intellisense\InterfaceCompletionItem.cs" /> + <Compile Include="Intellisense\InterfaceCompletionItemPopup.cs" /> + <Compile Include="Intellisense\KnownType.cs" /> <Compile Include="Document\ChangeTrackingCheckpoint.cs" /> <Compile Include="Document\DocumentChangeOperation.cs"> <DependentUpon>UndoStack.cs</DependentUpon> @@ -320,6 +333,23 @@ <Compile Include="Indentation\CSharp\DocumentAccessor.cs" /> <Compile Include="Indentation\DefaultIndentationStrategy.cs" /> <Compile Include="Indentation\IIndentationStrategy.cs" /> + <Compile Include="Intellisense\KnownTypeConstructor.cs" /> + <Compile Include="Intellisense\KnownTypeMember.cs" /> + <Compile Include="Intellisense\KnownTypeMethodParameter.cs" /> + <Compile Include="Intellisense\KnownTypeMethod.cs" /> + <Compile Include="Intellisense\KnownTypeProperty.cs" /> + <Compile Include="Intellisense\ClassCompletionItem.cs" /> + <Compile Include="Intellisense\MethodCompletionItem.cs" /> + <Compile Include="Intellisense\MethodCompletionItemPopup.cs" /> + <Compile Include="Intellisense\NamespaceCompletionItem.cs" /> + <Compile Include="Intellisense\NamespaceCompletionItemPopup.cs" /> + <Compile Include="Intellisense\PropertyCompletionItem.cs" /> + <Compile Include="Intellisense\PropertyCompletionItemPopup.cs" /> + <Compile Include="Intellisense\StructCompletionItem.cs" /> + <Compile Include="Intellisense\StructCompletionItemPopup.cs" /> + <Compile Include="Popups\MethodDescription.cs" /> + <Compile Include="Popups\MethodPopup.cs" /> + <Compile Include="Popups\ParameterDescription.cs" /> <Compile Include="Rendering\BackgroundGeometryBuilder.cs"> <DependentUpon>IBackgroundRenderer.cs</DependentUpon> </Compile> @@ -561,18 +591,33 @@ <None Include="packages.config" /> </ItemGroup> <ItemGroup> - <Resource Include="Images\pubclass.gif" /> - <Resource Include="Images\pubevent.gif" /> - <Resource Include="Images\pubmethod.gif" /> - <Resource Include="Images\pubproperty.gif" /> - </ItemGroup> - <ItemGroup> <Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" /> <Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\enum.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\class.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\interface.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\struct.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\namespace.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\method.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\property.png" /> + </ItemGroup> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UseGlobalSettings="True" /> + <UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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..7a6588239 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml @@ -1,9 +1,12 @@ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Tango.Scripting.Editors" + xmlns:popups="clr-namespace:Tango.Scripting.Editors.Popups" xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:editing="clr-namespace:Tango.Scripting.Editors.Editing" xmlns:folding="clr-namespace:Tango.Scripting.Editors.Folding" + xmlns:intellisense="clr-namespace:Tango.Scripting.Editors.Intellisense" + xmlns:converters="clr-namespace:Tango.Scripting.Editors.Converters" xmlns:completion="clr-namespace:Tango.Scripting.Editors.CodeCompletion"> <ResourceDictionary.MergedDictionaries> @@ -21,6 +24,9 @@ <Color x:Key="ScriptForeground">#E6E6E6</Color> <Color x:Key="ScriptFoldingForeground">#A0A0A0</Color> <Color x:Key="ScriptLineNumberForeground">#2B91AF</Color> + <Color x:Key="ScriptReferenceTypesColor">#4EC9B0</Color> + <Color x:Key="ScriptKeywordColor">#3F8FD6</Color> + <Color x:Key="ScriptInterfaceColor">#B5CE8A</Color> <!--Brushes--> <SolidColorBrush x:Key="ScriptBackgroundBrush" Color="{StaticResource ScriptBackground}"></SolidColorBrush> @@ -29,6 +35,22 @@ <SolidColorBrush x:Key="ScriptLineNumberForegroundBrush" Color="{StaticResource ScriptLineNumberForeground}"></SolidColorBrush> <SolidColorBrush x:Key="CompletionBackgroundBrush" Color="{StaticResource CompletionBackground}"></SolidColorBrush> <SolidColorBrush x:Key="CompletionToolTipBackgroundBrush" Color="{StaticResource CompletionToolTipBackground}"></SolidColorBrush> + <SolidColorBrush x:Key="ScriptReferenceTypesBrush" Color="{StaticResource ScriptReferenceTypesColor}"></SolidColorBrush> + <SolidColorBrush x:Key="ScriptKeywordBrush" Color="{StaticResource ScriptKeywordColor}"></SolidColorBrush> + <SolidColorBrush x:Key="ScriptInterfaceBrush" Color="{StaticResource ScriptInterfaceColor}"></SolidColorBrush> + + <!--Images--> + <BitmapImage x:Key="interface" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/interface.png" /> + <BitmapImage x:Key="class" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/class.png" /> + <BitmapImage x:Key="enum" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/enum.png" /> + <BitmapImage x:Key="struct" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/struct.png" /> + <BitmapImage x:Key="namespace" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/namespace.png" /> + <BitmapImage x:Key="method" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/method.png" /> + <BitmapImage x:Key="property" UriSource="pack://application:,,,/Tango.Scripting.Editors;component/Images/property.png" /> + + <!--Converters--> + <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> + <converters:BooleanToVisibilityInversedConverter x:Key="BooleanToVisibilityInversedConverter" /> <Style TargetType="{x:Type completion:CompletionList}"> <Setter Property="Background" Value="{StaticResource CompletionBackgroundBrush}"></Setter> @@ -61,12 +83,96 @@ <Setter.Value> <DataTemplate> <Border Background="{StaticResource CompletionToolTipBackgroundBrush}" CornerRadius="3" BorderThickness="0.5" BorderBrush="#434343" Padding="10 5" TextElement.Foreground="{StaticResource ScriptForegroundBrush}" TextElement.FontSize="12"> - <TextBlock TextWrapping="Wrap"> - <Run Text="{Binding Type,Mode=OneWay}" Foreground="#3F8FD6"></Run> - <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Text,Mode=OneWay}" Foreground="#4EC9B0"></Run> - <LineBreak/> - <Run Text="{Binding Description,Mode=OneWay}"></Run> - </TextBlock> + <!--<ContentControl Content="{Binding}"> + <ContentControl.Style> + <Style TargetType="ContentControl"> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <ContentPresenter Content="{Binding PopupControl}" /> + </DataTemplate> + </Setter.Value> + </Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding Type}" Value="method"> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Text}"></TextBlock> + <TextBlock>(</TextBlock> + <ItemsControl ItemsSource="{Binding Parameters}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <StackPanel Orientation="Horizontal"></StackPanel> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type.Name}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Name}"></TextBlock> + <TextBlock Margin="0 0 5 0" Text="," Visibility="{Binding IsLast,Converter={StaticResource BooleanToVisibilityInversedConverter}}"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <TextBlock>)</TextBlock> + + <StackPanel Margin="5 0 0 0" Orientation="Horizontal" Visibility="{Binding HasOverloads,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock>(+</TextBlock> + <TextBlock Margin="2 0" Text="{Binding Overloads}"></TextBlock> + <TextBlock>overloads)</TextBlock> + </StackPanel> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + </DataTemplate> + </Setter.Value> + </Setter> + </DataTrigger> + + <DataTrigger Binding="{Binding Type}" Value="property"> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Text}"></TextBlock> + <TextBlock Margin="5 0 0 0"> + <Run>{</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">get</Run><Run>;</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">set</Run><Run>;</Run> + <Run>}</Run> + </TextBlock> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + </DataTemplate> + </Setter.Value> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </ContentControl.Style> + + <ContentControl.ContentTemplate> + <DataTemplate> + <ContentPresenter Content="{Binding PopupControl}" /> + </DataTemplate> + </ContentControl.ContentTemplate> + </ContentControl>--> + + <ContentPresenter DataContext="{Binding}" Content="{Binding PopupControl}" /> </Border> </DataTemplate> </Setter.Value> @@ -90,8 +196,8 @@ <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> - <Image Source="{Binding Image}" Width="16" Height="16" Margin="0,0,4,0"/> - <ContentControl Content="{Binding Content}" /> + <Image Width="16" Height="16" Margin="0,0,4,0" Source="{Binding Image}"></Image> + <ContentControl Content="{Binding}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> @@ -160,17 +266,266 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> - <ScrollViewer - Focusable="False" - Name="PART_ScrollViewer" - CanContentScroll="True" - VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" - HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" - Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextArea}" - VerticalContentAlignment="Top" - HorizontalContentAlignment="Left" - Background="{TemplateBinding Background}" - Padding="{TemplateBinding Padding}"/> + <Grid> + <ScrollViewer + Focusable="False" + Name="PART_ScrollViewer" + CanContentScroll="True" + VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" + HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" + Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextArea}" + VerticalContentAlignment="Top" + HorizontalContentAlignment="Left" + Background="{TemplateBinding Background}" + Padding="{TemplateBinding Padding}"/> + + <Popup x:Name="PART_popup" IsOpen="False" AllowsTransparency="True"> + <Border Background="{StaticResource CompletionToolTipBackgroundBrush}" CornerRadius="3" BorderThickness="0.5" BorderBrush="#434343" Padding="10 5" TextElement.Foreground="{StaticResource ScriptForegroundBrush}" TextElement.FontSize="12"> + <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CurrentPopupContent}" /> + </Border> + </Popup> + </Grid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type popups:MethodPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type popups:MethodPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <DockPanel> + <StackPanel Orientation="Horizontal" VerticalAlignment="Top"> + <fa:ImageAwesome VerticalAlignment="Center" Icon="ChevronUp" Width="10" Height="10" Foreground="{StaticResource ScriptForegroundBrush}" /> + <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethodIndex}"></TextBlock> + <TextBlock VerticalAlignment="Center" Margin="5 0 0 0">of</TextBlock> + <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Methods.Count}"></TextBlock> + <fa:ImageAwesome VerticalAlignment="Center" Margin="5 0 0 0" Icon="ChevronDown" Width="10" Height="10" Foreground="{StaticResource ScriptForegroundBrush}" /> + </StackPanel> + + <StackPanel Margin="10 0 0 0"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>(</TextBlock> + <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Parameters}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <StackPanel Orientation="Horizontal"></StackPanel> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type popups:ParameterDescription}"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Name}"></TextBlock> + <TextBlock Margin="0 0 5 0" Visibility="{Binding IsLast,Converter={StaticResource BooleanToVisibilityInversedConverter}}">,</TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <TextBlock>)</TextBlock> + </StackPanel> + + <TextBlock Margin="0 5 0 0" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Description}" TextWrapping="Wrap"></TextBlock> + + <ItemsControl Margin="0 10 0 0" ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Parameters}"> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type popups:ParameterDescription}"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Name}"></TextBlock> + <TextBlock>:</TextBlock> + <TextBlock Opacity="0.7" Margin="5 0 0 0" Text="{Binding Description}"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </StackPanel> + </DockPanel> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <!--Completion Items--> + + <Style TargetType="{x:Type intellisense:ClassCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:ClassCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + <TextBlock TextWrapping="Wrap"> + <Run Text="class" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:EnumCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:EnumCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + <TextBlock TextWrapping="Wrap"> + <Run Text="enum" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Text,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:MethodCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:MethodCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Name}"></TextBlock> + <TextBlock>(</TextBlock> + <ItemsControl ItemsSource="{Binding Parameters}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <StackPanel Orientation="Horizontal"></StackPanel> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Name}"></TextBlock> + <TextBlock Margin="0 0 5 0" Text="," Visibility="{Binding IsLast,Converter={StaticResource BooleanToVisibilityInversedConverter}}"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <TextBlock>)</TextBlock> + + <StackPanel Margin="5 0 0 0" Orientation="Horizontal" Visibility="{Binding HasOverloads,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock>(+</TextBlock> + <TextBlock Margin="2 0" Text="{Binding Overloads}"></TextBlock> + <TextBlock>overloads)</TextBlock> + </StackPanel> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:InterfaceCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:InterfaceCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="interface" Foreground="#3F8FD6"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:NamespaceCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:NamespaceCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="namespace" Foreground="{StaticResource ScriptKeywordBrush}"></Run> + <Run Text="{Binding Name,Mode=OneWay}"></Run> + </TextBlock> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:PropertyCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:PropertyCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <StackPanel> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Type}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock> + <TextBlock>.</TextBlock> + <TextBlock Text="{Binding Text}"></TextBlock> + <TextBlock Margin="5 0 0 0"> + <Run>{</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">get</Run><Run>;</Run> + <Run Foreground="{StaticResource ScriptKeywordBrush}">set</Run><Run>;</Run> + <Run>}</Run> + </TextBlock> + </StackPanel> + + <TextBlock Text="{Binding Description}"></TextBlock> + </StackPanel> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="{x:Type intellisense:StructCompletionItemPopup}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type intellisense:StructCompletionItemPopup}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <TextBlock TextWrapping="Wrap"> + <Run Text="struct" Foreground="#3F8FD6"></Run> + <Run Text="{Binding Namespace,Mode=OneWay}"></Run>.<Run Text="{Binding Name,Mode=OneWay}" Foreground="{StaticResource ScriptInterfaceBrush}"></Run> + <LineBreak/> + <Run Text="{Binding Description,Mode=OneWay}"></Run> + </TextBlock> + </Border> </ControlTemplate> </Setter.Value> |
