Ejemplo n.º 1
0
        internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable<TextSpan> spans, Workspace workspace, OptionSet options = null, IEnumerable<IFormattingRule> rules = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (workspace == null)
            {
                throw new ArgumentNullException("workspace");
            }

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var languageFormatter = workspace.Services.GetLanguageServices(node.Language).GetService<ISyntaxFormattingService>();
            if (languageFormatter != null)
            {
                options = options ?? workspace.GetOptions();
                rules = rules ?? GetDefaultFormattingRules(workspace, node.Language);
                return languageFormatter.Format(node, spans, options, rules, cancellationToken).GetTextChanges(cancellationToken);
            }
            else
            {
                return SpecializedCollections.EmptyList<TextChange>();
            }
        }
Ejemplo n.º 2
0
        internal static SyntaxNode Format(SyntaxNode node, IEnumerable<TextSpan> spans, Workspace workspace, OptionSet options, IEnumerable<IFormattingRule> rules, CancellationToken cancellationToken)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException("workspace");
            }

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (spans == null)
            {
                throw new ArgumentNullException("spans");
            }

            var languageFormatter = workspace.Services.GetLanguageServices(node.Language).GetService<ISyntaxFormattingService>();
            if (languageFormatter != null)
            {
                options = options ?? workspace.GetOptions();
                rules = rules ?? GetDefaultFormattingRules(workspace, node.Language);
                return languageFormatter.Format(node, spans, options, rules, cancellationToken).GetFormattedRoot(cancellationToken);
            }
            else
            {
                return node;
            }
        }