The formatting changes are used to format a specific region inside a document and apply a minimal formatting changeset to a given document. This is useful for a text editor environment.
Example #1
0
        public FormattingVisitor(CSharpFormatter formatter, IDocument document, FormattingChanges changes, CancellationToken token)
        {
            if (formatter == null)
                throw new ArgumentNullException("formatter");
            if (document == null)
                throw new ArgumentNullException("document");
            if (changes == null)
                throw new ArgumentNullException("changes");

            this.formatter = formatter;
            this.changes = changes;
            this.document = document;
            this.token = token;

            curIndent = new Indent(formatter.TextEditorOptions);
        }
Example #2
0
        /// <summary>
        /// Analyzes the formatting of a given document and syntax tree.
        /// </summary>
        /// <param name="document">Document.</param>
        /// <param name="syntaxTree">Syntax tree.</param>
        /// <param name="token">The cancellation token.</param>
        public FormattingChanges AnalyzeFormatting(IDocument document, SyntaxTree syntaxTree, CancellationToken token = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (syntaxTree == null)
            {
                throw new ArgumentNullException("syntaxTree");
            }
            var result  = new FormattingChanges(document);
            var visitor = new FormattingVisitor(this, document, result, token);

            syntaxTree.AcceptVisitor(visitor);
            return(result);
        }
Example #3
0
        public FormattingVisitor(CSharpFormatter formatter, IDocument document, FormattingChanges changes, CancellationToken token)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (changes == null)
            {
                throw new ArgumentNullException("changes");
            }

            this.formatter = formatter;
            this.changes   = changes;
            this.document  = document;
            this.token     = token;

            curIndent = new Indent(formatter.TextEditorOptions);
        }
Example #4
0
		/// <summary>
		/// Analyzes the formatting of a given document and syntax tree.
		/// </summary>
		/// <param name="document">Document.</param>
		/// <param name="syntaxTree">Syntax tree.</param>
		/// <param name="token">The cancellation token.</param>
		public FormattingChanges AnalyzeFormatting(IDocument document, SyntaxTree syntaxTree, CancellationToken token = default (CancellationToken))
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (syntaxTree == null)
				throw new ArgumentNullException("syntaxTree");
			var result = new FormattingChanges(document);
			var visitor = new FormattingVisitor(this, document, result, token);
			syntaxTree.AcceptVisitor(visitor);
			return result;
		}