Skip to content

Commit ce9a293

Browse files
committed
Explicity track changes, so they continue across multiple mutations.
1 parent 92a950f commit ce9a293

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,6 +3082,10 @@ public void Post_Init_Trees_Are_Reparsed_When_ParseOptions_Change()
30823082
parseOptions = parseOptions.WithLanguageVersion(LanguageVersion.CSharp1);
30833083
compilation = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: parseOptions);
30843084
driver = driver.WithUpdatedParseOptions(parseOptions);
3085+
3086+
// change some other options to ensure the parseOption change tracking flows correctly
3087+
driver = driver.AddAdditionalTexts(ImmutableArray<AdditionalText>.Empty);
3088+
30853089
driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out compilation, out diagnostics);
30863090
diagnostics.Verify();
30873091

src/Compilers/Core/Portable/SourceGeneration/GeneratorDriver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public GeneratorDriver ReplaceAdditionalText(AdditionalText oldText, AdditionalT
123123
public GeneratorDriver ReplaceAdditionalTexts(ImmutableArray<AdditionalText> newTexts) => FromState(_state.With(additionalTexts: newTexts));
124124

125125
public GeneratorDriver WithUpdatedParseOptions(ParseOptions newOptions) => newOptions is object
126-
? FromState(_state.With(parseOptions: newOptions))
126+
? FromState(_state.With(parseOptions: newOptions, parseOptionsChanged: true))
127127
: throw new ArgumentNullException(nameof(newOptions));
128128

129129
public GeneratorDriver WithUpdatedAnalyzerConfigOptions(AnalyzerConfigOptionsProvider newOptions) => newOptions is object
@@ -282,7 +282,7 @@ internal GeneratorDriverState RunGeneratorsCore(Compilation compilation, Diagnos
282282
}
283283
}
284284

285-
state = state.With(stateTable: driverStateBuilder.ToImmutable(), syntaxStore: syntaxStoreBuilder.ToImmutable(), generatorStates: stateBuilder.ToImmutableAndFree(), runTime: timer.Elapsed);
285+
state = state.With(stateTable: driverStateBuilder.ToImmutable(), syntaxStore: syntaxStoreBuilder.ToImmutable(), generatorStates: stateBuilder.ToImmutableAndFree(), runTime: timer.Elapsed, parseOptionsChanged: false);
286286
return state;
287287
}
288288

src/Compilers/Core/Portable/SourceGeneration/GeneratorDriverState.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ internal GeneratorDriverState(ParseOptions parseOptions,
9595

9696
internal readonly bool TrackIncrementalSteps;
9797

98+
/// <summary>
99+
/// Tracks if the <see cref="ParseOptions"/> have been changed meaning post init trees will need to be re-parsed.
100+
/// </summary>
98101
internal readonly bool ParseOptionsChanged;
99102

100103
internal GeneratorDriverState With(
@@ -107,7 +110,8 @@ internal GeneratorDriverState With(
107110
ParseOptions? parseOptions = null,
108111
AnalyzerConfigOptionsProvider? optionsProvider = null,
109112
IncrementalGeneratorOutputKind? disabledOutputs = null,
110-
TimeSpan? runTime = null)
113+
TimeSpan? runTime = null,
114+
bool? parseOptionsChanged = null)
111115
{
112116
return new GeneratorDriverState(
113117
parseOptions ?? this.ParseOptions,
@@ -121,7 +125,7 @@ internal GeneratorDriverState With(
121125
disabledOutputs ?? this.DisabledOutputs,
122126
runTime ?? this.RunTime,
123127
this.TrackIncrementalSteps,
124-
parseOptions is not null
128+
parseOptionsChanged ?? this.ParseOptionsChanged
125129
);
126130
}
127131
}

0 commit comments

Comments
 (0)