From 27e290d2f7efc93297420a68073d7b66430ada96 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 10:43:59 +0300 Subject: CodeFormatter and auto assembly redirects for FSE finally works. --- .../Tango.Scripting.Editors/ScriptEditor.cs | 4 +- .../Tango.Scripting.Editors.csproj | 6 +- .../Tango.Scripting.Formatting/CodeFormatter.cs | 61 ++++++++ .../Properties/AssemblyInfo.cs | 36 +++++ .../Tango.Scripting.Formatting.csproj | 160 +++++++++++++++++++++ .../Tango.Scripting.Formatting/app.config | 47 ++++++ .../Tango.Scripting.Formatting/packages.config | 61 ++++++++ 7 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Tango.Scripting.Formatting.csproj create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/app.config create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/packages.config (limited to 'Software/Visual_Studio/Scripting') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index d1ea9de43..02615e0d2 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -36,6 +36,7 @@ using Tango.Scripting.Editors.Highlighting.Xshd; using Tango.Scripting.Editors.Intellisense; using Tango.Scripting.Editors.Popups; using Tango.Scripting.Editors.Rendering; +using Tango.Scripting.Formatting; using Tango.Scripting.Parsing; namespace Tango.Scripting.Editors @@ -1681,7 +1682,8 @@ namespace Tango.Scripting.Editors private void IndentCode() { - Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); + Text = CodeFormatter.Format(Text); + //Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); //Text = _parser.IndentCSharpCode(Text); } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj index cabacbc28..5f9548262 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj @@ -590,6 +590,10 @@ {5812E1C6-ABAA-4066-94AC-971C27B4F46A} Tango.Scripting.Core + + {8d8f06ed-7f75-4933-b0c5-829b0ff654d0} + Tango.Scripting.Formatting + {1e938fd2-c669-4738-98c9-77f96ce4d451} Tango.Scripting @@ -642,7 +646,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs new file mode 100644 index 000000000..c933f7e09 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs @@ -0,0 +1,61 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Formatting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Formatting +{ + public static class CodeFormatter + { + public static String Format(String code) + { + SyntaxTree tree = CSharpSyntaxTree.ParseText(code); + CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); + + //var node = ApplyBraceNewLineRule(root); + //node = ApplyCopyrightHeaderRule(node); + //node = ApplyNewLineAboveRule(node); + //node = ApplyUsingLocationRule(node); + + //Just to make VS copy the dll to output folder. + Microsoft.CodeAnalysis.CSharp.Formatting.BinaryOperatorSpacingOptions a = Microsoft.CodeAnalysis.CSharp.Formatting.BinaryOperatorSpacingOptions.Ignore; + + var node = Formatter.Format(root, new AdhocWorkspace()); + + return node.ToString(); + } + + //private static SyntaxNode ApplyUsingLocationRule(SyntaxNode node) + //{ + // UsingLocationRule rule = new UsingLocationRule(); + // return rule.Process(node, "CSharp"); + //} + + //private static SyntaxNode ApplyBraceNewLineRule(SyntaxNode node) + //{ + // BraceNewLineRule rule = new BraceNewLineRule(); + // return rule.Process(node, "CSharp"); + //} + + //private static SyntaxNode ApplyNewLineAboveRule(SyntaxNode node) + //{ + // NewLineAboveRule rule = new NewLineAboveRule(); + // return rule.Process(node, "CSharp"); + //} + + //private static SyntaxNode ApplyCopyrightHeaderRule(SyntaxNode node) + //{ + // CopyrightHeaderRule rule = new CopyrightHeaderRule(new Microsoft.DotNet.CodeFormatting.Options() + // { + + // }); + + // return rule.ProcessCSharp(node); + //} + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5436fc65e --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Scripting.Formatting")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.Formatting")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8d8f06ed-7f75-4933-b0c5-829b0ff654d0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Tango.Scripting.Formatting.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Tango.Scripting.Formatting.csproj new file mode 100644 index 000000000..4e5b927b0 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/Tango.Scripting.Formatting.csproj @@ -0,0 +1,160 @@ + + + + + Debug + AnyCPU + {8D8F06ED-7F75-4933-B0C5-829B0FF654D0} + Library + Properties + Tango.Scripting.Formatting + Tango.Scripting.Formatting + v4.6.1 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\ManagedEsent.1.9.4\lib\net40\Esent.Interop.dll + + + ..\..\packages\Microsoft.CodeAnalysis.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + + + ..\..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll + + + ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.4.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.dll + + + ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.4.0\lib\net46\Microsoft.CodeAnalysis.Workspaces.Desktop.dll + + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + + + ..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + ..\..\packages\System.Composition.AttributedModel.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll + + + ..\..\packages\System.Composition.Convention.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll + + + ..\..\packages\System.Composition.Hosting.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll + + + ..\..\packages\System.Composition.Runtime.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll + + + ..\..\packages\System.Composition.TypedParts.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll + + + ..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + + ..\..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + + + ..\..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll + + + ..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + ..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + + ..\..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + + + ..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + ..\..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll + + + ..\..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + + + ..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + + + + + + + + + ..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + + + ..\..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + + + ..\..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll + + + ..\..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/app.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/app.config new file mode 100644 index 000000000..9da0b3b67 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/app.config @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/packages.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/packages.config new file mode 100644 index 000000000..6844de8c2 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/packages.config @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.3.1 From a440c6477a12a263969a507c2178981642ffb457 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 12:27:01 +0300 Subject: Stubs module format code. --- .../Tango.FSE.Stubs/Contracts/ITestDesignerView.cs | 5 +++-- .../ViewModels/TestDesignerViewVM.cs | 10 +++++++++- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 22 ++++++++++++++-------- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs | 15 ++++++++++++++- .../ExtensionMethods/IFSEViewExtensions.cs | 16 ++++++++++++++++ .../FSE/Tango.FSE.Common/Tango.FSE.Common.csproj | 1 + .../Scripting/Tango.Scripting.Basic/Project.cs | 12 ------------ .../Tango.Scripting.Editors/ScriptEditor.cs | 20 ++++++++++++++++++++ 8 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs (limited to 'Software/Visual_Studio/Scripting') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs index 604d54571..bba69bac1 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs @@ -3,11 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.FSE.Common; namespace Tango.FSE.Stubs.Contracts { - public interface ITestDesignerView + public interface ITestDesignerView : IFSEView { - + void FormatCode(); } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs index 1afc0478a..e1fc8c539 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -12,6 +12,7 @@ using Tango.Core; using Tango.Core.Commands; using Tango.Core.ExtensionMethods; using Tango.FSE.Common; +using Tango.FSE.Stubs.Contracts; using Tango.FSE.Stubs.Dialogs; using Tango.Integration.Operation; using Tango.Scripting.Basic; @@ -22,7 +23,7 @@ using Tango.Transport; namespace Tango.FSE.Stubs.ViewModels { - public class TestDesignerViewVM : FSEViewModel, ITestLogger + public class TestDesignerViewVM : FSEViewModel, ITestLogger { public enum ToolWindows { @@ -124,6 +125,7 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand RemoveReferenceAssemblyCommand { get; set; } public RelayCommand AddProjectInputCommand { get; set; } public RelayCommand RemoveProjectInputCommand { get; set; } + public RelayCommand FormatCodeCommand { get; set; } #endregion @@ -153,6 +155,7 @@ namespace Tango.FSE.Stubs.ViewModels RemoveReferenceAssemblyCommand = new RelayCommand(RemoveReferenceAssembly); AddProjectInputCommand = new RelayCommand(AddProjectInput); RemoveProjectInputCommand = new RelayCommand(RemoveProjectInput); + FormatCodeCommand = new RelayCommand(FormatCode); _compileTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); _compileTimer.Interval = TimeSpan.FromSeconds(2); @@ -162,6 +165,11 @@ namespace Tango.FSE.Stubs.ViewModels CreateNewProject(); } + private void FormatCode() + { + View.FormatCode(); + } + #endregion #region Script Editor Symbols Loading Handlers diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml index 715960932..4d31b9083 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml @@ -28,7 +28,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -66,9 +66,15 @@ + + + + + + - + @@ -115,13 +121,13 @@ @@ -148,14 +154,14 @@ - + - + - + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs index ab9289ddb..5bd798cc0 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs @@ -12,21 +12,24 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.FSE.Stubs.Contracts; using Tango.FSE.Stubs.ViewModels; using Tango.Scripting.Basic; +using Tango.Scripting.Editors; namespace Tango.FSE.Stubs.Views { /// /// Interaction logic for TestDesignerView.xaml /// - public partial class TestDesignerView : UserControl + public partial class TestDesignerView : UserControl, ITestDesignerView { private TestDesignerViewVM _vm; public TestDesignerView() { InitializeComponent(); + this.Register(); Loaded += (_, __) => _vm = DataContext as TestDesignerViewVM; } @@ -34,5 +37,15 @@ namespace Tango.FSE.Stubs.Views { _vm.OpenScript((sender as FrameworkElement).DataContext as Script); } + + public void FormatCode() + { + var editor = tabControl.FindVisualChildren().FirstOrDefault(x => x.IsVisible); + + if (editor != null) + { + editor.FormatCode(); + } + } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs new file mode 100644 index 000000000..7707100ad --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.FSE.Common; + +public static class IFSEViewExtensions +{ + public static void Register(this T view) where T : class, IFSEView + { + TangoIOC.Default.Register(view); + } +} + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj index 47bc2c36f..f79bfba03 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj @@ -125,6 +125,7 @@ + diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs index 446e5b529..776c21e53 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs @@ -60,18 +60,6 @@ namespace Tango.Scripting.Basic Scripts.CollectionChanged += (x, e) => { RaisePropertyChanged(nameof(AdditionalScripts)); }; } - public static TProject New(String name) where TProject : Project where TContext : IContext - { - TProject p = Activator.CreateInstance(); - - p.Name = name; - - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(String))); - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Enumerable))); - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Form))); - return p; - } - public Task Compile() { return Task.Factory.StartNew(() => diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index 02615e0d2..42103a1b1 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -2102,5 +2102,25 @@ namespace Tango.Scripting.Editors } #endregion + + #region Public Methods + + public void FormatCode() + { + try + { + int index = CaretOffset; + Document.BeginUpdate(); + IndentCode(); + Document.EndUpdate(); + CaretOffset = index; + } + catch + { + Debug.WriteLine("Error formatting code."); + } + } + + #endregion } } -- cgit v1.3.1 From 4c0712fb9ac9ea65b0c66c16639f847307c84f98 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 17:55:12 +0300 Subject: Improvements on test designer. --- .../Tango.FSE.Stubs/Contracts/ITestDesignerView.cs | 1 + .../Dialogs/AddReferenceAssemblyViewVM.cs | 55 +++-- .../FSE/Modules/Tango.FSE.Stubs/TestProject.cs | 22 ++ .../ViewModels/TestDesignerViewVM.cs | 240 ++++++++++++++++++++- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 226 ++++++++++++------- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs | 16 +- .../FSE/Tango.FSE.Common/Resources/Converters.xaml | 1 + .../Tango.Scripting.Basic/CompilationError.cs | 1 + .../Scripting/Tango.Scripting.Basic/Project.cs | 3 + .../Scripting/Tango.Scripting.Basic/Script.cs | 27 ++- .../Tango.Scripting.Editors/ScriptEditor.cs | 5 + 11 files changed, 486 insertions(+), 111 deletions(-) (limited to 'Software/Visual_Studio/Scripting') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs index bba69bac1..ea87a4f19 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs @@ -10,5 +10,6 @@ namespace Tango.FSE.Stubs.Contracts public interface ITestDesignerView : IFSEView { void FormatCode(); + void HighlightCode(int position, int length); } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs index aa32f6a03..cee06ed91 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs @@ -17,6 +17,8 @@ namespace Tango.FSE.Stubs.Dialogs { public class AddReferenceAssemblyViewVM : FSEDialogViewVM { + private List _existing; + [TangoInject] private IFSEApplicationManager ApplicationManager { get; set; } @@ -24,42 +26,53 @@ namespace Tango.FSE.Stubs.Dialogs public AddReferenceAssemblyViewVM(List existing) { + _existing = existing; OKText = "DONE"; - TangoIOC.Default.Inject(this); + } - List source = new List(); - - var startPath = ApplicationManager.StartPath; + public override void OnShow() + { + base.OnShow(); - foreach (var file in Directory.GetFiles(startPath, "*.dll")) + Task.Factory.StartNew(() => { - if (Path.GetFileName(file).StartsWith("Tango")) + System.Threading.Thread.Sleep(200); + List source = new List(); + + var startPath = ApplicationManager.StartPath; + + foreach (var file in Directory.GetFiles(startPath, "*.dll")) { - source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + if (Path.GetFileName(file).StartsWith("Tango")) + { + source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + } } - } - String dotNetPath = AssemblyHelper.GetAssemblyTargetFrameworkFolder(Assembly.GetExecutingAssembly()); + String dotNetPath = AssemblyHelper.GetAssemblyTargetFrameworkFolder(Assembly.GetExecutingAssembly()); - foreach (var file in Directory.GetFiles(dotNetPath, "*.dll")) - { - source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); - } + foreach (var file in Directory.GetFiles(dotNetPath, "*.dll")) + { + source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + } - source = source.DistinctBy(x => x.Name).ToList(); + source = source.DistinctBy(x => x.Name).ToList(); - List existingReferences = new List(); + List existingReferences = new List(); - foreach (var asm in source) - { - if (existing.Exists(x => x.Name == asm.Name)) + foreach (var asm in source) { - existingReferences.Add(asm); + if (_existing.Exists(x => x.Name == asm.Name)) + { + existingReferences.Add(asm); + } } - } - ReferenceAssemblies = new SelectedObjectCollection(source.ToObservableCollection(), existingReferences.ToObservableCollection()); + ReferenceAssemblies = new SelectedObjectCollection(source.ToObservableCollection(), existingReferences.ToObservableCollection()); + + RaisePropertyChanged(nameof(ReferenceAssemblies)); + }); } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs index 1600c9752..0bb4783dd 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs @@ -1,4 +1,5 @@ using Google.Protobuf; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -14,8 +15,19 @@ namespace Tango.FSE.Stubs { public class TestProject : Project { + private static JsonSerializerSettings _jsonSettings; + public ObservableCollection Inputs { get; set; } + static TestProject() + { + _jsonSettings = new JsonSerializerSettings() + { + TypeNameHandling = TypeNameHandling.Auto, + PreserveReferencesHandling = PreserveReferencesHandling.All, + }; + } + public TestProject() : base() { Inputs = new ObservableCollection(); @@ -41,5 +53,15 @@ namespace Tango.FSE.Stubs return project; } + + public String ToJson() + { + return JsonConvert.SerializeObject(this, _jsonSettings); + } + + public static TestProject FromJson(String json) + { + return JsonConvert.DeserializeObject(json, _jsonSettings); + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs index e1fc8c539..1550da2ed 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -1,7 +1,9 @@ using Google.Protobuf; +using MaterialDesignThemes.Wpf; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -35,6 +37,10 @@ namespace Tango.FSE.Stubs.ViewModels } private DispatcherTimer _compileTimer; + private String _projectFile; + private String PROJECT_FILE_EXTENSION = ".tproj"; + private String PROJECT_DIALOG_FILTER = $"Test Project Files|*.tproj"; + private bool _isProjectChanged; #region Properties @@ -126,6 +132,14 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand AddProjectInputCommand { get; set; } public RelayCommand RemoveProjectInputCommand { get; set; } public RelayCommand FormatCodeCommand { get; set; } + public RelayCommand HighlightErrorCommand { get; set; } + public RelayCommand NewProjectCommand { get; set; } + public RelayCommand SaveProjectCommand { get; set; } + public RelayCommand SaveAsProjectCommand { get; set; } + public RelayCommand OpenProjectCommand { get; set; } + public RelayCommand AddLibraryCommand { get; set; } + public RelayCommand