'C# Incremental Source Generator caching bug?

I'm trying to wrap my head around the new Roslyn Incremental Source Generators, by making a simple generator, that lists all invoked methods in a file called InvokedMethods.g.cs.

It almost works, but there is an issue when typing in Visual Studio. Or more specfically, when deleting the last method invocation, because then the source generator doesn't produce an empty file, as I would expect it to do.

Either I don't fully understand the way CreateSyntaxProvider is supposed to work (which is quite likely) otherwise there is a bug in the Visual Studio 2022 implementation?

[Generator]
public class ListMethodInvocationsGenerator : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        IncrementalValueProvider<ImmutableArray<string>> invokedMethodsProvider = context.SyntaxProvider.CreateSyntaxProvider(
                predicate: (node, _) => node is InvocationExpressionSyntax,
                transform: (ctx, _) => (ctx.SemanticModel.GetSymbolInfo(ctx.Node).Symbol)?.Name ?? "<< method not found >>")
            .Collect();

        context.RegisterSourceOutput(invokedMethodsProvider, (SourceProductionContext spc, ImmutableArray<string> invokedMethods) =>
        {
            var src = new StringBuilder();
            foreach (var method in invokedMethods)
            {
                src.AppendLine("// " + method);
            }
            spc.AddSource("InvokedMethods.g.cs", src.ToString());
        });
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source