Skip to content

Commit 3fb52b7

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Un-cache the assist lint rule map when registering new generators
This fixes running `dart --enable-asserts pkg/analysis_server/test/test_all.dart`. Change-Id: I50aef9e2d2f073ac8917b3f97dcfc0cddc0290c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415720 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent b310567 commit 3fb52b7

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

pkg/analysis_server/lib/src/services/correction/assist_generators.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,29 @@ class _RegisteredAssistGenerators {
1919
/// assists.
2020
final Set<MultiProducerGenerator> multiProducerGenerators = {};
2121

22+
Map<ProducerGenerator, Set<LintCode>>? _lintRuleMap;
23+
2224
/// A mapping from registered _assist_ producer generators to the [LintCode]s
2325
/// for which they may also act as a _fix_ producer generator.
24-
late Map<ProducerGenerator, Set<LintCode>> lintRuleMap = {
25-
for (var generator in producerGenerators)
26-
generator: {
27-
for (var MapEntry(key: lintName, value: generators)
28-
in registeredFixGenerators.lintProducers.entries)
29-
if (generators.contains(generator)) lintName,
30-
},
31-
};
26+
Map<ProducerGenerator, Set<LintCode>> get lintRuleMap =>
27+
_lintRuleMap ??= {
28+
for (var generator in producerGenerators)
29+
generator: {
30+
for (var MapEntry(key: lintName, value: generators)
31+
in registeredFixGenerators.lintProducers.entries)
32+
if (generators.contains(generator)) lintName,
33+
},
34+
};
3235

3336
void registerGenerator(ProducerGenerator generator) {
3437
producerGenerators.add(generator);
38+
// Reset the lint rule map, to account for the new generator.
39+
_lintRuleMap = null;
3540
}
3641

3742
void registerMultiGenerator(MultiProducerGenerator generator) {
3843
multiProducerGenerators.add(generator);
44+
// Reset the lint rule map, to account for the new generator.
45+
_lintRuleMap = null;
3946
}
4047
}

pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ void registerBuiltInAssistGenerators() {
179179
// This function can be called many times during test runs so these statements
180180
// should not result in duplicate producers (i.e. they should only add to maps
181181
// or sets or otherwise ensure producers that already exist are not added).
182-
registeredAssistGenerators.producerGenerators.addAll(_builtInGenerators);
183-
registeredAssistGenerators.multiProducerGenerators.addAll(
184-
_builtInMultiGenerators,
182+
_builtInGenerators.forEach(registeredAssistGenerators.registerGenerator);
183+
_builtInMultiGenerators.forEach(
184+
registeredAssistGenerators.registerMultiGenerator,
185185
);
186186
}
187187

0 commit comments

Comments
 (0)