mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 00:45:16 +00:00
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>
This commit is contained in:
parent
2707880f1b
commit
39e0e75fcf
|
@ -196,7 +196,7 @@ class CiderCompletionComputer {
|
|||
for (var definedElement in exportMap.values) {
|
||||
definedElement.accept(visitor);
|
||||
}
|
||||
return visitor.suggestions..addAll(suggestionBuilder.suggestions);
|
||||
return suggestionBuilder.suggestions.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/src/protocol_server.dart'
|
||||
show CompletionSuggestion;
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/local_library_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'
|
||||
show SuggestionBuilder;
|
||||
import 'package:analyzer/src/generated/resolver.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart' as protocol;
|
||||
|
||||
import '../../../protocol_server.dart' show CompletionSuggestion;
|
||||
|
||||
/// A contributor for calculating suggestions for imported top level members.
|
||||
class ImportedReferenceContributor extends DartCompletionContributor {
|
||||
|
@ -27,37 +26,23 @@ class ImportedReferenceContributor extends DartCompletionContributor {
|
|||
return const <CompletionSuggestion>[];
|
||||
}
|
||||
|
||||
var suggestions = <CompletionSuggestion>[];
|
||||
|
||||
var seenElements = <protocol.Element>{};
|
||||
|
||||
// Traverse imports including dart:core
|
||||
for (var importElement in imports) {
|
||||
var libraryElement = importElement.importedLibrary;
|
||||
if (libraryElement != null) {
|
||||
final newSuggestions = _buildSuggestions(
|
||||
request, builder, importElement.namespace,
|
||||
_buildSuggestions(request, builder, importElement.namespace,
|
||||
prefix: importElement.prefix?.name);
|
||||
// TODO(brianwilkerson) Remove this filtering after every suggestion is
|
||||
// being generated via SuggestionBuilder.
|
||||
for (var suggestion in newSuggestions) {
|
||||
// Filter out multiply-exported elements (like Future and Stream).
|
||||
if (seenElements.add(suggestion.element)) {
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
return const <CompletionSuggestion>[];
|
||||
}
|
||||
|
||||
List<CompletionSuggestion> _buildSuggestions(DartCompletionRequest request,
|
||||
void _buildSuggestions(DartCompletionRequest request,
|
||||
SuggestionBuilder builder, Namespace namespace,
|
||||
{String prefix}) {
|
||||
var visitor = LibraryElementSuggestionBuilder(request, builder, prefix);
|
||||
for (var elem in namespace.definedNames.values) {
|
||||
elem.accept(visitor);
|
||||
}
|
||||
return visitor.suggestions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'package:analysis_server/src/protocol_server.dart'
|
|||
show CompletionSuggestion, CompletionSuggestionKind;
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'
|
||||
show ElementSuggestionBuilder, SuggestionBuilder;
|
||||
show SuggestionBuilder;
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/dart/element/visitor.dart';
|
||||
|
@ -17,9 +17,7 @@ import 'package:analyzer_plugin/src/utilities/completion/optype.dart';
|
|||
/// A visitor for building suggestions based upon the elements defined by
|
||||
/// a source file contained in the same library but not the same as
|
||||
/// the source in which the completions are being requested.
|
||||
class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
|
||||
with ElementSuggestionBuilder {
|
||||
@override
|
||||
class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
|
||||
final DartCompletionRequest request;
|
||||
|
||||
final SuggestionBuilder builder;
|
||||
|
@ -28,7 +26,6 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
|
|||
|
||||
DartType contextType;
|
||||
|
||||
@override
|
||||
CompletionSuggestionKind kind;
|
||||
|
||||
final String prefix;
|
||||
|
@ -45,9 +42,6 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor
|
|||
: opType.suggestKind;
|
||||
}
|
||||
|
||||
@override
|
||||
LibraryElement get containingLibrary => request.libraryElement;
|
||||
|
||||
@override
|
||||
void visitClassElement(ClassElement element) {
|
||||
if (opType.includeTypeNameSuggestions) {
|
||||
|
@ -176,6 +170,6 @@ class LocalLibraryContributor extends DartCompletionContributor {
|
|||
unit.accept(visitor);
|
||||
}
|
||||
}
|
||||
return visitor.suggestions;
|
||||
return const <CompletionSuggestion>[];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,92 +96,6 @@ CompletionSuggestion createSuggestion(
|
|||
return suggestion;
|
||||
}
|
||||
|
||||
/// Common mixin for sharing behavior.
|
||||
mixin ElementSuggestionBuilder {
|
||||
/// A collection of completion suggestions.
|
||||
final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
|
||||
|
||||
/// A set of existing completions used to prevent duplicate suggestions.
|
||||
final Set<String> _completions = <String>{};
|
||||
|
||||
/// A map of element names to suggestions for synthetic getters and setters.
|
||||
final Map<String, CompletionSuggestion> _syntheticMap =
|
||||
<String, CompletionSuggestion>{};
|
||||
|
||||
/// Return the library in which the completion is requested.
|
||||
LibraryElement get containingLibrary;
|
||||
|
||||
/// Return the kind of suggestions that should be built.
|
||||
CompletionSuggestionKind get kind;
|
||||
|
||||
/// Return the completion request for which suggestions are being built.
|
||||
DartCompletionRequest get request;
|
||||
|
||||
/// Add a suggestion based upon the given element.
|
||||
CompletionSuggestion addSuggestion(Element element,
|
||||
{String prefix,
|
||||
int relevance = DART_RELEVANCE_DEFAULT,
|
||||
String elementCompletion}) {
|
||||
if (element.isPrivate) {
|
||||
if (element.library != containingLibrary) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var completion = elementCompletion ?? element.displayName;
|
||||
if (prefix != null && prefix.isNotEmpty) {
|
||||
if (completion == null || completion.isEmpty) {
|
||||
completion = prefix;
|
||||
} else {
|
||||
completion = '$prefix.$completion';
|
||||
}
|
||||
}
|
||||
if (completion == null || completion.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
var suggestion = createSuggestion(request, element,
|
||||
completion: completion, kind: kind, relevance: relevance);
|
||||
if (suggestion != null) {
|
||||
if (element.isSynthetic && element is PropertyAccessorElement) {
|
||||
String cacheKey;
|
||||
if (element.isGetter) {
|
||||
cacheKey = element.name;
|
||||
}
|
||||
if (element.isSetter) {
|
||||
cacheKey = element.name;
|
||||
cacheKey = cacheKey.substring(0, cacheKey.length - 1);
|
||||
}
|
||||
if (cacheKey != null) {
|
||||
var existingSuggestion = _syntheticMap[cacheKey];
|
||||
|
||||
// Pair getter/setter by updating the existing suggestion
|
||||
if (existingSuggestion != null) {
|
||||
var getter = element.isGetter ? suggestion : existingSuggestion;
|
||||
var elemKind = element.enclosingElement is ClassElement
|
||||
? protocol.ElementKind.FIELD
|
||||
: protocol.ElementKind.TOP_LEVEL_VARIABLE;
|
||||
existingSuggestion.element = protocol.Element(
|
||||
elemKind,
|
||||
existingSuggestion.element.name,
|
||||
existingSuggestion.element.flags,
|
||||
location: getter.element.location,
|
||||
typeParameters: getter.element.typeParameters,
|
||||
parameters: null,
|
||||
returnType: getter.returnType);
|
||||
return existingSuggestion;
|
||||
}
|
||||
|
||||
// Cache lone getter/setter so that it can be paired
|
||||
_syntheticMap[cacheKey] = suggestion;
|
||||
}
|
||||
}
|
||||
if (_completions.add(suggestion.completion)) {
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
}
|
||||
return suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
/// This class provides suggestions based upon the visible instance members in
|
||||
/// an interface type.
|
||||
class MemberSuggestionBuilder {
|
||||
|
|
Loading…
Reference in a new issue