英文:
IncrementalGenerator Generated Source Not Available
问题
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?
英文:
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?
答案1
得分: 0
这似乎是一个IDE问题。
清除Rider的缓存并重新启动解决了这个问题。
英文:
This seems to be an IDE issue.
Invalidating Rider's caches and restarting solved the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论