Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/library_prefix_contributor.dart

Issue 1517693004: extract LibraryPrefixContributor from imported reference contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698