public void ComputeRefactoringsForNodeInsideTrivia() { SyntaxNode node = Root.FindNode(Span, findInsideTrivia: true, getInnermostNodeForTie: true); for (; node != null; node = node.Parent) { if (node is DirectiveTriviaSyntax directiveTrivia) { DirectiveTriviaRefactoring.ComputeRefactorings(this, directiveTrivia); SyntaxKind kind = node.Kind(); if (kind == SyntaxKind.RegionDirectiveTrivia || kind == SyntaxKind.EndRegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this); } RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(this); if (kind == SyntaxKind.RegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (RegionDirectiveTriviaSyntax)node); } else if (kind == SyntaxKind.EndRegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (EndRegionDirectiveTriviaSyntax)node); } break; } } }
public void ComputeRefactoringsForNodeInsideTrivia() { SyntaxNode node = Root.FindNode(Span, findInsideTrivia: true, getInnermostNodeForTie: true); if (node == null) { return; } bool fDirectiveTrivia = false; using (IEnumerator <SyntaxNode> en = node.AncestorsAndSelf().GetEnumerator()) { while (en.MoveNext()) { node = en.Current; Debug.WriteLine(node.Kind().ToString()); if (!fDirectiveTrivia) { var directiveTrivia = node as DirectiveTriviaSyntax; if (directiveTrivia != null) { DirectiveTriviaRefactoring.ComputeRefactorings(this, directiveTrivia); SyntaxKind kind = node.Kind(); if (kind == SyntaxKind.RegionDirectiveTrivia || kind == SyntaxKind.EndRegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this); } RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(this); if (kind == SyntaxKind.RegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (RegionDirectiveTriviaSyntax)node); } else if (kind == SyntaxKind.EndRegionDirectiveTrivia) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (EndRegionDirectiveTriviaSyntax)node); } fDirectiveTrivia = true; } } } } }
public static void ComputeRefactoringsForNodeInsideTrivia(this RefactoringContext context) { SyntaxNode node = context.FindNode(findInsideTrivia: true); if (node == null) { return; } bool fDirectiveTrivia = false; using (IEnumerator <SyntaxNode> en = node.AncestorsAndSelf().GetEnumerator()) { while (en.MoveNext()) { node = en.Current; Debug.WriteLine(node.Kind().ToString()); if (!fDirectiveTrivia) { var directiveTrivia = node as DirectiveTriviaSyntax; if (directiveTrivia != null) { DirectiveTriviaRefactoring.ComputeRefactorings(context, directiveTrivia); if (node.IsKind(SyntaxKind.RegionDirectiveTrivia, SyntaxKind.EndRegionDirectiveTrivia)) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(context); } RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(context); if (node.IsKind(SyntaxKind.RegionDirectiveTrivia, SyntaxKind.EndRegionDirectiveTrivia)) { RegionDirectiveTriviaRefactoring.ComputeRefactorings(context, (RegionDirectiveTriviaSyntax)node); } fDirectiveTrivia = true; } } } } }