Skip to content

Commit c1d7ffd

Browse files
srawlinsCommit Queue
authored andcommitted
Refactor sync* methods in analysis options completions
sync* is still slow. At each of the call sites for these methods, all suggestions are iterated (the iterator is never short-circuited). So better to not use sync*. Change-Id: Icffefa799a1a31eed3208d5130c1f0d4c01364f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390920 Auto-Submit: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 3f74be8 commit c1d7ffd

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ class _ErrorProducer extends KeyValueProducer {
7171
Producer? producerForKey(String key) => enumProducer;
7272

7373
@override
74-
Iterable<CompletionSuggestion> suggestions(
75-
YamlCompletionRequest request) sync* {
76-
for (var error in errorCodeValues) {
77-
yield identifier('${error.name.toLowerCase()}: ');
78-
}
79-
for (var rule in Registry.ruleRegistry.rules) {
80-
yield identifier('${rule.name}: ');
81-
}
74+
Iterable<CompletionSuggestion> suggestions(YamlCompletionRequest request) {
75+
return [
76+
for (var error in errorCodeValues)
77+
identifier('${error.name.toLowerCase()}: '),
78+
for (var rule in Registry.ruleRegistry.rules)
79+
identifier('${rule.name}: '),
80+
];
8281
}
8382
}
8483

@@ -88,13 +87,11 @@ class _ExperimentProducer extends Producer {
8887
const _ExperimentProducer();
8988

9089
@override
91-
Iterable<CompletionSuggestion> suggestions(
92-
YamlCompletionRequest request) sync* {
93-
for (var feature in ExperimentStatus.knownFeatures.values) {
94-
if (!feature.isEnabledByDefault) {
95-
yield identifier(feature.enableString);
96-
}
97-
}
90+
Iterable<CompletionSuggestion> suggestions(YamlCompletionRequest request) {
91+
return [
92+
for (var feature in ExperimentStatus.knownFeatures.values)
93+
if (!feature.isEnabledByDefault) identifier(feature.enableString),
94+
];
9895
}
9996
}
10097

@@ -104,13 +101,13 @@ class _LintRuleProducer extends Producer {
104101
const _LintRuleProducer();
105102

106103
@override
107-
Iterable<CompletionSuggestion> suggestions(
108-
YamlCompletionRequest request) sync* {
109-
for (var rule in Registry.ruleRegistry.rules) {
110-
// TODO(pq): consider suggesting internal lints if editing an SDK options file
111-
if (!rule.state.isInternal && !rule.state.isRemoved) {
112-
yield identifier(rule.name, docComplete: rule.description);
113-
}
114-
}
104+
Iterable<CompletionSuggestion> suggestions(YamlCompletionRequest request) {
105+
return [
106+
for (var rule in Registry.ruleRegistry.rules)
107+
// TODO(pq): consider suggesting internal lints if editing an SDK
108+
// options file.
109+
if (!rule.state.isInternal && !rule.state.isRemoved)
110+
identifier(rule.name, docComplete: rule.description),
111+
];
115112
}
116113
}

0 commit comments

Comments
 (0)