title: How to remove a list of SyntaxNode from the Document using Roslyn code fix provider APIs?
body: <p>I'm having a custom generated variable declaration using <code>SyntaxFactory.VariableDeclaration</code> and a list of <code>SyntaxNode</code>'s collected according to some conditions.</p>
  
  <p>I did the following:</p>
  
  <ol>
  <li><p><strong>Modify the node</strong></p>
  
  <pre><code>var newRoot = root.ReplaceNode(expression, newVariableDeclaration)
  </code></pre>
  
  <p>This successfully modified the node with the <code>newVariableDeclaration</code>.</p></li>
  <li><p><strong>In a loop remove the nodes corresponding to the ones present in the list</strong></p>
  
  <pre><code>foreach (var listObject in listObjects)
  {
      newRoot = newRoot.RemoveNode(listObject, SyntaxRemoveOptions.KeepNoTrivia);
  }
  </code></pre>
  
  <p>This doesn't change the <code>newRoot</code> and all the <code>listObject</code> required to be changed remains the same.</p></li>
  </ol>
  
  <p><em>If we use <code>root.RemoveNode(listObject, SyntaxRemoveOptions.KeepNoTrivia)</code> instead it will, obviously, keep on replacing the previous changes.</em></p>
  
  <p>So here the <code>newVariableDeclaration</code> is the <strong>only node that is changed</strong> in the whole document, is this because <code>newRoot</code> <code>SyntaxNodes</code> have changes from that of the <code>SyntaxNode</code> that I obtained from <code>root</code>.</p>
  
  <p>Please correct me if I'm doing it wrong.</p>
  
  <p><strong>EDIT:</strong>
  I looked into <code>CSharpSyntaxRewriter</code> but it appears that it is analyzing a single node everytime it's visiting a node and can only modify a single node at a time. In my scenario, I'll have to visit a particular node, make changes to it, and remove other nodes with respect to the changes made to visited node.</p>