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.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 ++++++++ 5 files changed, 365 insertions(+) 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/Tango.Scripting.Formatting') 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