예제 #1
0
        public static SyntaxFormattingOptions Create(OptionSet options, HostWorkspaceServices services, string language)
        {
            var formattingService = services.GetRequiredLanguageService <ISyntaxFormattingService>(language);
            var configOptions     = options.AsAnalyzerConfigOptions(services.GetRequiredService <IOptionService>(), language);

            return(formattingService.GetFormattingOptions(configOptions));
        }
        public Task <SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray <TextSpan> spans, SyntaxFormattingOptions options, HostWorkspaceServices services, CancellationToken cancellationToken)
        {
            var formatter = services.GetRequiredLanguageService <ISyntaxFormattingService>(root.Language);
            var result    = formatter.GetFormattingResult(root, spans, options, _rules, cancellationToken);

            // apply changes to an old text if it already exists
            return((root.SyntaxTree != null && root.SyntaxTree.TryGetText(out var oldText)) ?
                   root.SyntaxTree.WithChangedText(oldText.WithChanges(result.GetTextChanges(cancellationToken))).GetRootAsync(cancellationToken) :
                   Task.FromResult(result.GetFormattedRoot(cancellationToken)));
        }
예제 #3
0
파일: Formatter.cs 프로젝트: taori/roslyn
        internal static IList <TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable <TextSpan>?spans, HostWorkspaceServices services, SyntaxFormattingOptions options, IEnumerable <AbstractFormattingRule>?rules, CancellationToken cancellationToken = default)
        {
            var formatter = services.GetRequiredLanguageService <ISyntaxFormattingService>(node.Language);

            return(formatter.GetFormattingResult(node, spans, options, rules, cancellationToken).GetTextChanges(cancellationToken));
        }