Open Jejuni opened 2 years ago
Further information:
The issue seems to be related to using context.RegisterForPostInitialization
and / or adding an attribute.
Removing everything but the following code still causes the issue:
private const string attributeText = @"
using System;
namespace AutoNotify
{
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
[System.Diagnostics.Conditional(""AutoNotifyGenerator_DEBUG"")]
sealed class AutoNotifyAttribute : Attribute
{
public AutoNotifyAttribute()
{
}
public string PropertyName { get; set; }
}
}
";
public void Initialize(GeneratorInitializationContext context)
{
// Register the attribute source
context.RegisterForPostInitialization((i) => i.AddSource("AutoNotifyAttribute", attributeText));
}
public void Execute(GeneratorExecutionContext context) {}
Problem Description
When referencing a source generator the syntax highlighting of classes randomly stops working:
This image is using a stripped down version of the official sample: https://github.com/dotnet/roslyn-sdk/tree/main/samples/CSharp/SourceGenerators
Sometimes syntax highlighting works for a second and classes appear green, but they then immediately turn white again. Sometimes, after fresh VisualStudio start without touching anything the classes appear green, but navigating to definition (F12) or switching tabs causes them to turn white again.
GitHub repo showing the problem:
https://github.com/Jejuni/SourceGeneratorsProblem
Repro steps and further description:
CSharpSourceGeneratorSamples
project except forAutoNotifyGenerator.cs
.AutoNotifyGenerator.cs
stays untouched.CSharpGeneratedDemo
except forProgram.cs
andUseAutoNotifyGenerator.cs
UseAutoNotifyGenerator.cs
stays untouched.Program.cs
to:namespace GeneratedDemo { class Program { static void Main(string[] args) { var vm = new ExampleViewModel(); UseAutoNotifyGenerator.Run(); } } }
change
CSharpGeneratedDemo.csproj
to: