Exemple #1
0
		public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null)
		{
			options = options ?? DFormattingOptions.CreateDStandard();
			textStyle = textStyle ?? TextEditorOptions.Default;
			ast = ast ?? DParser.ParseString(code) as DModule;
			
			var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument{ Text = code }, ast, textStyle);
			
			formattingVisitor.WalkThroughAst();
			
			var sb = new StringBuilder(code);
			
			formattingVisitor.ApplyChanges((int start, int length, string insertedText) => {
			                               	sb.Remove(start,length);
			                               	sb.Insert(start,insertedText);
			                               });
			
			return sb.ToString();
		}
Exemple #2
0
        public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null)
        {
            options   = options ?? DFormattingOptions.CreateDStandard();
            textStyle = textStyle ?? TextEditorOptions.Default;
            ast       = ast ?? DParser.ParseString(code) as DModule;

            var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument {
                Text = code
            }, ast, textStyle);

            formattingVisitor.WalkThroughAst();

            var sb = new StringBuilder(code);

            formattingVisitor.ApplyChanges((int start, int length, string insertedText) => {
                sb.Remove(start, length);
                sb.Insert(start, insertedText);
            });

            return(sb.ToString());
        }