Add support for debugging of source generators
I want to request support for debugging of source generators.
When developing a source generator having the possibility to debug the application is equally important as it is for any other application. Therefore debugging an source generator should be as easy as it is for any other dotnet application.
I don't know how feasible this is -- the language service and compiler are going to load your source generator which means you really need a separate instance of VS / VS Code that just has your source generator opened.
Your best bet is probably to add something like:
#pragma warning disable RS1035 // Do not use APIs banned for analyzers
// Wait for the debugger to attach if the environment variable is set
if (Environment.GetEnvironmentVariable("DEBUG_MY_SOURCE_GENERATOR")?.Equals("1") ?? false)
{
while (!Debugger.IsAttached)
{
Thread.Sleep(100);
}
}
#pragma warning restore RS1035 // Do not use APIs banned for analyzers
Then open two instances of VS Code (or VS if you are on Windows).
Resolving this as a duplicate of #8117