-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix source-generator reload when in 'balanced' mode #75831
Conversation
/// will have their source generator versions updated. If the solution is specified, then all projects will have | ||
/// their versions updated. | ||
/// </summary> | ||
public static SourceGeneratorExecutionVersionMap GetUpdatedSourceGeneratorVersions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a move.
@@ -846,7 +846,7 @@ public ProjectState WithMetadataReferences(IReadOnlyList<MetadataReference> meta | |||
return With(projectInfo: ProjectInfo.With(metadataReferences: metadataReferences).WithVersion(Version.GetNewerVersion())); | |||
} | |||
|
|||
public ProjectState WithAnalyzerReferences(IEnumerable<AnalyzerReference> analyzerReferences) | |||
public ProjectState WithAnalyzerReferences(IReadOnlyList<AnalyzerReference> analyzerReferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stronger typing, and this ensures we're not lazily producing these values every time.
} | ||
|
||
return WithCompilationState(CompilationState.AddAnalyzerReferences(this.SolutionState.AddAnalyzerReferences(projectId, collection), collection)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only expose Add/Remove at the top level. internally, these all boil down to 'With' calls. this makes it so we have a single chokepoint to add some new logic.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs
Outdated
Show resolved
Hide resolved
@@ -713,17 +713,6 @@ public SolutionCompilationState WithProjectMetadataReferences( | |||
forkTracker: true); | |||
} | |||
|
|||
/// <inheritdoc cref="SolutionState.AddAnalyzerReferences(ProjectId, ImmutableArray{AnalyzerReference})"/> | |||
public SolutionCompilationState AddAnalyzerReferences(StateChange stateChange, ImmutableArray<AnalyzerReference> analyzerReferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed. This all goes through WithProjectAnalyzerReferences now
@@ -748,22 +737,11 @@ public SolutionCompilationState WithAnalyzerReferences(IReadOnlyList<AnalyzerRef | |||
return Branch(this.SolutionState.WithAnalyzerReferences(analyzerReferences)); | |||
} | |||
|
|||
/// <inheritdoc cref="SolutionState.RemoveAnalyzerReference(ProjectId, AnalyzerReference)"/> | |||
public SolutionCompilationState RemoveAnalyzerReference(ProjectId projectId, AnalyzerReference analyzerReference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed. This all goes through WithProjectAnalyzerReferences now
/// Create a new solution instance with the project specified updated to include the | ||
/// specified analyzer references. | ||
/// </summary> | ||
public StateChange AddAnalyzerReferences(ProjectId projectId, ImmutableArray<AnalyzerReference> analyzerReferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed. This all goes through WithProjectAnalyzerReferences now
@@ -56,72 +56,5 @@ await this.SetCurrentSolutionAsync( | |||
cancellationToken).ConfigureAwait(false); | |||
|
|||
return; | |||
|
|||
static SourceGeneratorExecutionVersionMap GetUpdatedSourceGeneratorVersions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to helper used both here (when we hear about saves/builds), and by the compilation-state instance wqhen it is told that analyzer references changed.
|
||
[Theory, CombinatorialData] | ||
internal async Task UpdatingAnalyzerReferenceReloadsGenerators( | ||
SourceGeneratorExecutionPreference executionPreference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test that validates that boht automatic and balanced works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable
|
||
// As we're changing the references for a project we want to force generators to rerun for it. This way the | ||
// user automatically sees the new generators values without having to take any more explicit steps. | ||
var updatedMap = GetUpdatedSourceGeneratorVersions(this, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible that there are not actually any changed references here, and we end up force re-generation needlessly? Or does the caller guarantee that there are definitely changed references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind - seems like the callers are guaranteeing that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup. callers guarantee
// As we're changing the references for a project we want to force generators to rerun for it. This way the | ||
// user automatically sees the new generators values without having to take any more explicit steps. | ||
var updatedMap = GetUpdatedSourceGeneratorVersions(this, | ||
ImmutableSegmentedList<(ProjectId? projectId, bool forceRegeneration)>.Empty.Add((projectId, true))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is faster than just [(projectId, true)]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, that type doesn't expose collection initializer support yet. @sharwell for segmented list support.
…roslyn into sgReloadBalanced
/// their versions updated. | ||
/// </summary> | ||
public static SourceGeneratorExecutionVersionMap GetUpdatedSourceGeneratorVersions( | ||
SolutionCompilationState solution, ImmutableSegmentedList<(ProjectId? projectId, bool forceRegeneration)> projectIds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
/// <summary> | ||
/// Given the current state of a <paramref name="solution"/>, produced an updated version of the source generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs
Outdated
Show resolved
Hide resolved
Pull request was converted to draft
42121dc
to
c138fc2
Compare
Previously, if a source generator changed on disk, and hte user was in "balanced" mode, we wouldn't reload it until the next save/build point. This isn't a great experience, especially as changing on disk is a rare occurrence, and we want users to see those updates happen immediately to know that the new SG was picked up.