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

Move code that retrieves source generators to running in OOP only #72825

Merged
merged 4 commits into from
Apr 1, 2024

Conversation

CyrusNajmabadi
Copy link
Member

This will be part of a series of PRs. The main purpose here is to get all calls to ProjectState.SourceGenerators and AnalyzerReference.GetGenerators to run in OOP only. By doing that, we don't even have to load it in VS and we don't have to worry about the .net fx loading semantics for generators (versus the .net core semantics, which can reload generators).

Example of where this matters. Imagine if a user starts with an AnalyzerReference with no source generators in it, but then replaces those (while VS is running) with references that do have source-generators in them. With teh current code, because we loaded the generators within VS, and then checked if we had any, we'll always stay in teh state where we think we have none. However, by moving these loads/checks to OOP, we can realistically reload the reference/generators and then now know that we should be running generators on a particular project.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 1, 2024 16:24
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 1, 2024
// We don't have any source generators. Trivially bail out.
var compilationWithGeneratedFiles = compilationWithoutGeneratedFiles;
return (compilationWithGeneratedFiles, TextDocumentStates<SourceGeneratedDocumentState>.Empty, generatorInfo.Driver);
}
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was running on the host side no matter what. we do not want that. that basically loads and caches the SourceGenerators info locally, which means (due to .net fx limitations) that it is effectively fixed. Note: i intend to get rid of ProjectState.SourceGenerators entirely as an api. But this will be a series of small refactorings.

This PR was just an easy example of how to make things better.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 30ccf05 into dotnet:main Apr 1, 2024
27 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the sgOnlyOop1 branch April 1, 2024 19:53
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 1, 2024
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants