Esempio n. 1
0
        private static async Task <SourceText> BuildRecoverableTreeTextAsync(SyntaxTree tree, Encoding encoding, CancellationToken cancellationToken)
        {
            // build text from root, so recoverable tree won't cycle.
            var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            return(root.GetText(encoding));
        }
        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));
        }
Esempio n. 3
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));
        }
 private static async Task<SourceText> BuildRecoverableTreeTextAsync(SyntaxTree tree, Encoding encoding, CancellationToken cancellationToken)
 {
     // build text from root, so recoverable tree won't cycle.
     var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
     return root.GetText(encoding);
 }
		internal static SyntaxToken FindToken (SyntaxTree snapshot, int position, CancellationToken cancellationToken)
		{
			var root = snapshot.GetRootAsync(cancellationToken).WaitAndGetResult(CancellationToken.None);
			return root.FindToken(position, findInsideTrivia: true);
		}
		public static async Task<Tuple<BaseMethodDeclarationSyntax, IMethodSymbol>> FindMethodSyntaxAsync(
            SemanticModel model, SyntaxTree tree, MethodDescriptor method)
		{
			var root = await tree.GetRootAsync();
			var visitor = new MethodFinder(method, model);
			visitor.Visit(root);

			if (visitor.Result != null)
			{
				return new Tuple<BaseMethodDeclarationSyntax, IMethodSymbol>(
					visitor.Result,
					(IMethodSymbol)model.GetDeclaredSymbol(visitor.Result)
					);
			}
			else
			{
				return null;
			}
		}