Let's report some diagnostic and register code fix for this diagnostic.
private static void OnCompilation(CompilationAnalysisContext context) {
var compilation = context.Compilation;
var diagnostic = Diagnostic.Create( Rule, (Location) null );
context.ReportDiagnostic( diagnostic );
}
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) {
var document = context.Document;
//var span = context.Span;
var diagnostic = context.Diagnostics.Single();
RegisterCodeFix( context, $"Fix compilation", diagnostic, Action );
Task<Solution> Action(CancellationToken cancellationToken) {
return Task.FromResult( document.Project.Solution );
}
}
Problem is that: there is no way to execute code fix action. Light bulb is not shown. And even if I could execute it then document were null here.
So, is it possible to make code fix for compilation-level diagnostics?