Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method for launching a debugger during type initialization #31

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ driver = driver.RunGenerators(compilation);
```
The only unique feature is the wrapper class `{YourGeneratorName}Host`. This class is an internal feature of `SGF` and is used to make sure all dependencies are resolved before calling into your source generator.


## Advanced Features
There are some features that are designed for more advanced users or niche cases.

### Debugger Attaching
When your source generator is being used in the wild it can happen there are exceptions that are thrown which can be hard to track down. There is no nice way to debug these issues besides logging. To get around this you can set the environment variable `SGF_DEBUGGER_LAUNCH=true` the debugger will be launched at the entrypoint of SGF.



## Project Layout

This library is made up of quite a few different components leveraging various techniques to help
Expand Down
2 changes: 0 additions & 2 deletions src/SourceGenerator.Foundations/HoistSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ internal class HoistSourceGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{

var provider = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: static (s, _) => IsSyntaxTargetForGeneration(s),
transform: static (ctx, _) => GetSemanticTargetForGeneration(ctx))
.Where(static m => m is not null);

context.RegisterSourceOutput(context.AnalyzerConfigOptionsProvider, AddCoreTypes);
context.RegisterSourceOutput(provider,
static (spc, source) => Execute(source!, spc));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ internal abstract class SourceGeneratorHoist

static SourceGeneratorHoist()
{
if(bool.TryParse(System.Environment.GetEnvironmentVariable("SGF_DEBUGGER_LAUNCH"), out bool launchDebugger)
&& launchDebugger)
{
System.Diagnostics.Debugger.Launch();
}


s_assembliesWithResources = new List<Assembly>();
s_loadedAssemblies = new Dictionary<AssemblyName, Assembly>(new AssemblyNameComparer());
Initialize();
Expand Down
Loading