title: How can I make my code diagnostic syntax node action work on closed files?
body: <p>I'm building a set of code diagnostics using Roslyn (in VS2015 Preview). Ideally, I'd like any errors they produce to act as persistent errors, just as if I were violating a normal language rule.</p>
  
  <p>There are a bunch of options, but I'm having a hard time getting any of them to work consistently. I've managed to implement a rudimentary syntax node action, i.e. one registered with </p>
  
  <pre><code>context.RegisterSyntaxNodeAction(AnalyzeSyntaxNode, SyntaxKind.InvocationExpression);
  </code></pre>
  
  <p>in the <code>Initialize</code> method of my diagnostic class. Lo and behold, when I open up a file which violates this diagnostic (while running the VSIX project), VS2015 shows an error:</p>
  
  <ul>
  <li>Red squiggle under the right bit of code</li>
  <li>Red block in the margin</li>
  <li>Error in the error list</li>
  </ul>
  
  <p>However, the error goes away when I close the file.</p>
  
  <p>I've tried using <code>context.RegisterCompilationEndAction</code> as well, but this has two problems:</p>
  
  <ul>
  <li>It seems to fire inconsistently. <em>Usually</em> when I open the solution it fires, but not always. It doesn't fire on a clean/rebuild, which seems odd.</li>
  <li><p>Although diagnostics created <em>directly</em> in the analysis method fire, in order to implement the diagnostics I'm using a visitor, like this - which may be inept:</p>
  
  <pre><code>private static void AnalyzeEndCompilation(CompilationEndAnalysisContext context)
  {
      foreach (var tree in context.Compilation.SyntaxTrees)
      {
          var visitor = new ReportingVisitor(context.Compilation.GetSemanticModel(tree));
          visitor.Visit(tree.GetRoot());
          foreach (var diagnostic in visitor.Diagnostics)
          {
              context.ReportDiagnostic(diagnostic);
          }
      }
  }
  </code></pre>
  
  <p>I know that the diagnostics are being created - a breakpoint on the <code>ReportDiagnostic</code> line is hit several times - but I'm not seeing anything in the error list. (Whereas a similar <code>ReportDiagnostic</code> call at the start of the method, or one per syntax tree with the file path, <em>does</em> get shown.)</p></li>
  </ul>
  
  <p>What am I doing wrong here? The first approach (a syntax node action) would be ideal if feasible - it gives me exactly the context I need. Is there some setting in the project properties that I need to make the compiler use that for "full project" compilation as well as just interactive "in the IDE" handling? Is this perhaps just a bit of Roslyn integration which isn't quite finished yet?</p>
  
  <p>(I can include the full code for the class if it would be useful - in this case I suspect it would be more noise than signal though.)</p>