internal override SourceLocation GetLocation(int position)
            {
                var textLine       = _textLineCollection.GetLineFromPosition(position);
                var sourceLocation = new SourceLocation(position, textLine.LineNumber, position - textLine.Start);

                return(sourceLocation);
            }
示例#2
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(
                    root,
                    context.Span,
                    out ExpressionSyntax expression,
                    predicate: f => f.IsKind(
                        SyntaxKind.InvocationExpression,
                        SyntaxKind.ElementAccessExpression,
                        SyntaxKind.ConditionalAccessExpression)))
            {
                return;
            }

            Document   document   = context.Document;
            Diagnostic diagnostic = context.Diagnostics[0];

            CodeAction codeAction = CodeAction.Create(
                "Fix formatting",
                ct =>
            {
                TextLineCollection lines = expression.SyntaxTree.GetText().Lines;

                TextLine line = lines.GetLineFromPosition(expression.SpanStart);

                TextSpan span = TextSpan.FromBounds(line.EndIncludingLineBreak, expression.Span.End);

                return(CodeFixHelpers.FixCallChainAsync(document, expression, span, ct));
            },
                GetEquivalenceKey(diagnostic));

            context.RegisterCodeFix(codeAction, diagnostic);
        }
示例#3
0
        internal override SourceLocation GetLocation(int position)
        {
            var line = _textLines.GetLineFromPosition(position);

            return(new SourceLocation(_filePath, position, line.LineNumber, position));
        }