Following this answer I'm trying to reimplement my ISourceGenerator
as an IIncrementalGenerator
following along with these docs.
Now, I've got my main initializer method here:
public void Initialize(IncrementalGeneratorInitializationContext context)
{
SpinWait.SpinUntil(() => Debugger.IsAttached); // Manually attach debugger here
IncrementalValuesProvider<AdditionalText> extraTexts = context.AdditionalTextsProvider.Where(f => f.Path.EndsWith(".fluid.yml"));
IncrementalValuesProvider<(string Name, string Content)> namesAndContents = extraTexts.Select((text, cancellationToken)
=> (Name: Path.GetFileNameWithoutExtension(text.Path),
Content: text.GetText(cancellationToken)!.ToString()));
context.RegisterSourceOutput(namesAndContents, (spc, nameAndContent) =>
{
Dictionary<string, string> generatedSource = _generatorService.Generate(nameAndContent.Content);
foreach ((string fileName, string source) in generatedSource)
{
spc.AddSource(fileName, source);
}
});
}
If I drop a breakpoint on the spc.AddSource()
line, I can see that the contents of my generatedSource
dictionary looks like:
ICanLockOrEnter.fluid.g.cs
:
namespace SuperFluid.Tests.Cars;
public interface ICanLockOrEnter
{
public ICanUnlockOrInitialize Lock();
public ICanStartOrExit Enter();
}
Which all looks fine to me.
If I add EmitCompilerGeneratedFiles
to my .csproj, I can even see that the files are correctly generated within the obj folder.
However, despite this, I can't reference any of these interfaces in my test project that's using the analyzer.
Am I missing a trick here? The analyzer seems to be running, if I debug it, the sources look fine, so why can't I reference them?