Skip to content

Commit 39e0e75

Browse files
bwilkersoncommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Remove ElementSuggestionBuilder
Change-Id: I60d32ff61953ff6b87420c4fd2b38dbd327c24ec Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147241 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent 2707880 commit 39e0e75

File tree

4 files changed

+9
-116
lines changed

4 files changed

+9
-116
lines changed

pkg/analysis_server/lib/src/cider/completion.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class CiderCompletionComputer {
196196
for (var definedElement in exportMap.values) {
197197
definedElement.accept(visitor);
198198
}
199-
return visitor.suggestions..addAll(suggestionBuilder.suggestions);
199+
return suggestionBuilder.suggestions.toList();
200200
}
201201
}
202202

pkg/analysis_server/lib/src/services/completion/dart/imported_reference_contributor.dart

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
import 'dart:async';
66

7+
import 'package:analysis_server/src/protocol_server.dart'
8+
show CompletionSuggestion;
79
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
810
import 'package:analysis_server/src/services/completion/dart/local_library_contributor.dart';
911
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'
1012
show SuggestionBuilder;
1113
import 'package:analyzer/src/generated/resolver.dart';
12-
import 'package:analyzer_plugin/protocol/protocol_common.dart' as protocol;
13-
14-
import '../../../protocol_server.dart' show CompletionSuggestion;
1514

1615
/// A contributor for calculating suggestions for imported top level members.
1716
class ImportedReferenceContributor extends DartCompletionContributor {
@@ -27,37 +26,23 @@ class ImportedReferenceContributor extends DartCompletionContributor {
2726
return const <CompletionSuggestion>[];
2827
}
2928

30-
var suggestions = <CompletionSuggestion>[];
31-
32-
var seenElements = <protocol.Element>{};
33-
3429
// Traverse imports including dart:core
3530
for (var importElement in imports) {
3631
var libraryElement = importElement.importedLibrary;
3732
if (libraryElement != null) {
38-
final newSuggestions = _buildSuggestions(
39-
request, builder, importElement.namespace,
33+
_buildSuggestions(request, builder, importElement.namespace,
4034
prefix: importElement.prefix?.name);
41-
// TODO(brianwilkerson) Remove this filtering after every suggestion is
42-
// being generated via SuggestionBuilder.
43-
for (var suggestion in newSuggestions) {
44-
// Filter out multiply-exported elements (like Future and Stream).
45-
if (seenElements.add(suggestion.element)) {
46-
suggestions.add(suggestion);
47-
}
48-
}
4935
}
5036
}
51-
return suggestions;
37+
return const <CompletionSuggestion>[];
5238
}
5339

54-
List<CompletionSuggestion> _buildSuggestions(DartCompletionRequest request,
40+
void _buildSuggestions(DartCompletionRequest request,
5541
SuggestionBuilder builder, Namespace namespace,
5642
{String prefix}) {
5743
var visitor = LibraryElementSuggestionBuilder(request, builder, prefix);
5844
for (var elem in namespace.definedNames.values) {
5945
elem.accept(visitor);
6046
}
61-
return visitor.suggestions;
6247
}
6348
}

pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:analysis_server/src/protocol_server.dart'
88
show CompletionSuggestion, CompletionSuggestionKind;
99
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
1010
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'
11-
show ElementSuggestionBuilder, SuggestionBuilder;
11+
show SuggestionBuilder;
1212
import 'package:analyzer/dart/element/element.dart';
1313
import 'package:analyzer/dart/element/type.dart';
1414
import 'package:analyzer/dart/element/visitor.dart';
@@ -17,9 +17,7 @@ import 'package:analyzer_plugin/src/utilities/completion/optype.dart';
1717
/// A visitor for building suggestions based upon the elements defined by
1818
/// a source file contained in the same library but not the same as
1919
/// the source in which the completions are being requested.
20-
class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
21-
with ElementSuggestionBuilder {
22-
@override
20+
class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
2321
final DartCompletionRequest request;
2422

2523
final SuggestionBuilder builder;
@@ -28,7 +26,6 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
2826

2927
DartType contextType;
3028

31-
@override
3229
CompletionSuggestionKind kind;
3330

3431
final String prefix;
@@ -45,9 +42,6 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
4542
: opType.suggestKind;
4643
}
4744

48-
@override
49-
LibraryElement get containingLibrary => request.libraryElement;
50-
5145
@override
5246
void visitClassElement(ClassElement element) {
5347
if (opType.includeTypeNameSuggestions) {
@@ -176,6 +170,6 @@ class LocalLibraryContributor extends DartCompletionContributor {
176170
unit.accept(visitor);
177171
}
178172
}
179-
return visitor.suggestions;
173+
return const <CompletionSuggestion>[];
180174
}
181175
}

pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -96,92 +96,6 @@ CompletionSuggestion createSuggestion(
9696
return suggestion;
9797
}
9898

99-
/// Common mixin for sharing behavior.
100-
mixin ElementSuggestionBuilder {
101-
/// A collection of completion suggestions.
102-
final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
103-
104-
/// A set of existing completions used to prevent duplicate suggestions.
105-
final Set<String> _completions = <String>{};
106-
107-
/// A map of element names to suggestions for synthetic getters and setters.
108-
final Map<String, CompletionSuggestion> _syntheticMap =
109-
<String, CompletionSuggestion>{};
110-
111-
/// Return the library in which the completion is requested.
112-
LibraryElement get containingLibrary;
113-
114-
/// Return the kind of suggestions that should be built.
115-
CompletionSuggestionKind get kind;
116-
117-
/// Return the completion request for which suggestions are being built.
118-
DartCompletionRequest get request;
119-
120-
/// Add a suggestion based upon the given element.
121-
CompletionSuggestion addSuggestion(Element element,
122-
{String prefix,
123-
int relevance = DART_RELEVANCE_DEFAULT,
124-
String elementCompletion}) {
125-
if (element.isPrivate) {
126-
if (element.library != containingLibrary) {
127-
return null;
128-
}
129-
}
130-
var completion = elementCompletion ?? element.displayName;
131-
if (prefix != null && prefix.isNotEmpty) {
132-
if (completion == null || completion.isEmpty) {
133-
completion = prefix;
134-
} else {
135-
completion = '$prefix.$completion';
136-
}
137-
}
138-
if (completion == null || completion.isEmpty) {
139-
return null;
140-
}
141-
var suggestion = createSuggestion(request, element,
142-
completion: completion, kind: kind, relevance: relevance);
143-
if (suggestion != null) {
144-
if (element.isSynthetic && element is PropertyAccessorElement) {
145-
String cacheKey;
146-
if (element.isGetter) {
147-
cacheKey = element.name;
148-
}
149-
if (element.isSetter) {
150-
cacheKey = element.name;
151-
cacheKey = cacheKey.substring(0, cacheKey.length - 1);
152-
}
153-
if (cacheKey != null) {
154-
var existingSuggestion = _syntheticMap[cacheKey];
155-
156-
// Pair getter/setter by updating the existing suggestion
157-
if (existingSuggestion != null) {
158-
var getter = element.isGetter ? suggestion : existingSuggestion;
159-
var elemKind = element.enclosingElement is ClassElement
160-
? protocol.ElementKind.FIELD
161-
: protocol.ElementKind.TOP_LEVEL_VARIABLE;
162-
existingSuggestion.element = protocol.Element(
163-
elemKind,
164-
existingSuggestion.element.name,
165-
existingSuggestion.element.flags,
166-
location: getter.element.location,
167-
typeParameters: getter.element.typeParameters,
168-
parameters: null,
169-
returnType: getter.returnType);
170-
return existingSuggestion;
171-
}
172-
173-
// Cache lone getter/setter so that it can be paired
174-
_syntheticMap[cacheKey] = suggestion;
175-
}
176-
}
177-
if (_completions.add(suggestion.completion)) {
178-
suggestions.add(suggestion);
179-
}
180-
}
181-
return suggestion;
182-
}
183-
}
184-
18599
/// This class provides suggestions based upon the visible instance members in
186100
/// an interface type.
187101
class MemberSuggestionBuilder {

0 commit comments

Comments
 (0)