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

Script with a Source Generator doesn't compile #233

Open
mdonatas opened this issue Jul 21, 2024 · 4 comments
Open

Script with a Source Generator doesn't compile #233

mdonatas opened this issue Jul 21, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mdonatas
Copy link

A script with a Source Generator fails to compile when run although intelli-sense shows that a Source Generator has run (at least during edit time) as correct xml-doc was made for the partial method.

Ext.AbcOrDefGeneratedRegex().IsMatch("abc").Dump();

public static partial class Ext
{
    [GeneratedRegex("abc|def", RegexOptions.IgnoreCase, "en-US")]
    public static partial Regex AbcOrDefGeneratedRegex();
}
image
@tareqimbasher
Copy link
Owner

@mdonatas thank you for the feedback. I haven't messed with this scenario within NetPad yet, but this is a great use case that I'd like to support. I'll check it out.

@tareqimbasher tareqimbasher added the bug Something isn't working label Aug 13, 2024
@tareqimbasher
Copy link
Owner

Update: I tried to create a fix for this for the upcoming release but as far as I can tell .NET is missing a couple APIs to make this possible via the implementation currently used by NetPad. I'll give it another push after the next update.

@mdonatas
Copy link
Author

Thanks for the update and for the effort. I take it NetPad uses different pipelines for intellisense and for building as intellisense can handle generators.
Best of luck with this! There are more and more generators being used in dotnet so it would be really nice to have support for them.

@tareqimbasher
Copy link
Owner

I take it NetPad uses different pipelines for intellisense and for building as intellisense can handle generators.

It does. The problem I'm facing currently is I need to get the code the generator would output to include it when compiling your user code but there's no straightforward way to do that programmatically with a generator defined in the BCL (and not in your user code) that I've found so far. One rather hacky way to do it is to create a temp project and have Roslyn run the generator and grab the output but I'm trying to find a more elegant solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants