public override SyntaxNode Visit(SyntaxNode node) { _cancellationToken.ThrowIfCancellationRequested(); if (node == null || !_spans.IntersectsWith(node.FullSpan)) { return(node); } return(base.Visit(node)); }
private IList <TextChange> CreateTextChanges(CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.Formatting_AggregateCreateTextChanges, cancellationToken)) { // quick check var changes = CreateTextChangesWorker(cancellationToken); // formatted spans and formatting spans are different, filter returns to formatting span return(_formattingSpans == null ? changes : changes.Where(s => _formattingSpans.IntersectsWith(s.Span)).ToList()); } }
private static bool ContainsInterleavedDirective( TextSpan textSpan, SyntaxTrivia trivia, ref SimpleIntervalTree <TextSpan> ifEndIfSpans, CancellationToken cancellationToken) { if (trivia.HasStructure) { var parentSpan = trivia.GetStructure().Span; if (trivia.GetStructure().IsKind(SyntaxKind.RegionDirectiveTrivia) || trivia.GetStructure().IsKind(SyntaxKind.EndRegionDirectiveTrivia) || trivia.GetStructure().IsKind(SyntaxKind.IfDirectiveTrivia) || trivia.GetStructure().IsKind(SyntaxKind.EndIfDirectiveTrivia)) { var match = ((DirectiveTriviaSyntax)trivia.GetStructure()).GetMatchingDirective(cancellationToken); if (match != null) { var matchSpan = match.Span; if (!textSpan.Contains(matchSpan.Start)) { // The match for this pp directive is outside // this node. return(true); } if (trivia.GetStructure().IsKind(SyntaxKind.IfDirectiveTrivia) || trivia.GetStructure().IsKind(SyntaxKind.EndIfDirectiveTrivia)) { var ppSpan = TextSpan.FromBounds( Math.Min(parentSpan.Start, matchSpan.Start), Math.Max(parentSpan.End, matchSpan.End)); ifEndIfSpans = ifEndIfSpans.AddInterval(ppSpan); } } } else if ( trivia.GetStructure().IsKind(SyntaxKind.ElseDirectiveTrivia) || trivia.GetStructure().IsKind(SyntaxKind.ElifDirectiveTrivia)) { if (!ifEndIfSpans.IntersectsWith(parentSpan.Start)) { // This else/elif belongs to a pp span that isn't // entirely within this node. return(true); } } } return(false); }