diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2020-04-26 13:06:17 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2020-04-26 13:06:17 +0300 |
| commit | 257919304a46076138cd31d688323f80f3081f7f (patch) | |
| tree | cf00acb22513a7b111228485a1a85e41079f15e1 /Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs | |
| parent | ebd7e4dee4f13c30a1d73a681c23d45e1045e6e5 (diff) | |
| parent | a4fe52cb35c01fa02b7b69ae0e5efd7194c06e43 (diff) | |
| download | Tango-257919304a46076138cd31d688323f80f3081f7f.tar.gz Tango-257919304a46076138cd31d688323f80f3081f7f.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs')
| -rw-r--r-- | Software/Visual_Studio/Scripting/Tango.Scripting.Formatting/CodeFormatter.cs | 61 |
1 files changed, 61 insertions, 0 deletions
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); + //} + } +} |
