| Index: pkg/analysis_server/lib/src/services/completion/dart/library_prefix_contributor.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/completion/dart/library_prefix_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/library_prefix_contributor.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..791c122d59ac09ab770e45ef575e42fe89cda917
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/library_prefix_contributor.dart
|
| @@ -0,0 +1,55 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library services.completion.contributor.dart.library_prefix;
|
| +
|
| +import 'dart:async';
|
| +
|
| +import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
| +import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
|
| +import 'package:analyzer/src/generated/ast.dart';
|
| +import 'package:analyzer/src/generated/element.dart';
|
| +
|
| +import '../../../protocol_server.dart'
|
| + show CompletionSuggestion, CompletionSuggestionKind;
|
| +
|
| +/**
|
| + * A contributor for calculating prefixed import library member suggestions
|
| + * `completion.getSuggestions` request results.
|
| + */
|
| +class LibraryPrefixContributor extends DartCompletionContributor {
|
| + @override
|
| + Future<List<CompletionSuggestion>> computeSuggestions(
|
| + DartCompletionRequest request) async {
|
| + if (!request.includeIdentifiers) {
|
| + return EMPTY_LIST;
|
| + }
|
| +
|
| + List<Directive> directives = await request.resolveDirectives();
|
| + if (directives == null) {
|
| + return EMPTY_LIST;
|
| + }
|
| +
|
| + List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
|
| + for (Directive directive in directives) {
|
| + if (directive is ImportDirective) {
|
| + SimpleIdentifier prefix = directive.prefix;
|
| + ImportElement element = directive.element;
|
| + if (prefix != null && element != null) {
|
| + String completion = prefix.name;
|
| + LibraryElement libElem = element.importedLibrary;
|
| + if (completion != null && completion.length > 0 && libElem != null) {
|
| + CompletionSuggestion suggestion = createSuggestion(libElem,
|
| + completion: completion,
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + if (suggestion != null) {
|
| + suggestions.add(suggestion);
|
| + }
|
| + }
|
| + }
|
| + }
|
| + }
|
| + return suggestions;
|
| + }
|
| +}
|
|
|