コード例 #1
0
ファイル: SyntaxNodeExtensions.cs プロジェクト: belav/roslyn
 internal static SyntaxNode?AsRootOfNewTreeWithOptionsFrom(
     this SyntaxNode?node,
     SyntaxTree oldTree
     )
 {
     return(node != null
       ? oldTree.WithRootAndOptions(node, oldTree.Options).GetRoot()
       : null);
 }
コード例 #2
0
 public Microsoft.CodeAnalysis.SyntaxTree Translate(VSGraphModel graphModel, CompilationOptions options)
 {
     Profiler.BeginSample("Translation");
     Microsoft.CodeAnalysis.SyntaxTree syntaxTree = ToSyntaxTree(graphModel, options);
     Profiler.EndSample();
     if (syntaxTree is CSharpSyntaxTree cSharpSyntaxTree && syntaxTree.TryGetRoot(out var treeRoot))
     {
         var treeOptions = cSharpSyntaxTree.Options.WithLanguageVersion(LanguageVersion);
         return(syntaxTree.WithRootAndOptions(treeRoot, treeOptions));
     }
     return(syntaxTree);
 }
コード例 #3
0
        internal static async Task <SyntaxTree> FixOneAsync(SyntaxTree syntaxTree, FormattingProvider formattingProvider, SyntaxFormattingOptions options, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            // The span to format is the full line(s) containing the diagnostic
            var text = await syntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);

            var diagnosticSpan             = diagnostic.Location.SourceSpan;
            var diagnosticLinePositionSpan = text.Lines.GetLinePositionSpan(diagnosticSpan);
            var spanToFormat = TextSpan.FromBounds(
                text.Lines[diagnosticLinePositionSpan.Start.Line].Start,
                text.Lines[diagnosticLinePositionSpan.End.Line].End);

            var root = await syntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var formattedRoot = Formatter.Format(root, spanToFormat, formattingProvider, options, cancellationToken);

            return(syntaxTree.WithRootAndOptions(formattedRoot, syntaxTree.Options));
        }
コード例 #4
0
        internal static async Task <SyntaxTree> FixOneAsync(
            SyntaxTree syntaxTree,
            FormatterState formatterState,
            OptionSet options,
            Diagnostic diagnostic,
            CancellationToken cancellationToken
            )
        {
            // The span to format is the full line(s) containing the diagnostic
            var text = await syntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);

            var diagnosticSpan             = diagnostic.Location.SourceSpan;
            var diagnosticLinePositionSpan = text.Lines.GetLinePositionSpan(diagnosticSpan);
            var spanToFormat = TextSpan.FromBounds(
                text.Lines[diagnosticLinePositionSpan.Start.Line].Start,
                text.Lines[diagnosticLinePositionSpan.End.Line].End
                );

            var root = await syntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

#if CODE_STYLE
            var formattedRoot = Formatter.Format(
                root,
                formatterState,
                new[] { spanToFormat },
                options,
                Formatter.GetDefaultFormattingRules(formatterState),
                cancellationToken
                );
#else
            var formattedRoot = Formatter.Format(
                root,
                spanToFormat,
                formatterState,
                options,
                cancellationToken
                );
#endif

            return(syntaxTree.WithRootAndOptions(formattedRoot, syntaxTree.Options));
        }
コード例 #5
0
 /// <summary>
 /// Attaches the node to a SyntaxTree that the same options as <paramref name="oldTree"/>
 /// </summary>
 internal static SyntaxNode AsRootOfNewTreeWithOptionsFrom(this SyntaxNode node, SyntaxTree oldTree)
 {
     return(oldTree.WithRootAndOptions(node, oldTree.Options).GetRoot());
 }