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

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

Issue 1503463002: move combinator contributor to new task model (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: remove old code 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/combinator_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/combinator_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/combinator_contributor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cba3bd4c44181273c0bcfd17b120dae68e542435
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/completion/dart/combinator_contributor.dart
@@ -0,0 +1,57 @@
+// 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.combinator;
+
+import 'dart:async';
+
+import 'package:analysis_server/src/protocol_server.dart'
+ hide Element, ElementKind;
+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';
+
+/**
+ * A contributor for calculating `completion.getSuggestions` request results
+ * for the import combinators show and hide.
+ */
+class CombinatorContributor extends DartCompletionContributor {
+ @override
+ Future<List<CompletionSuggestion>> computeSuggestions(
+ DartCompletionRequest request) async {
+ AstNode node = request.target.containingNode;
+ if (node is! Combinator) {
+ return EMPTY_LIST;
+ }
+
+ // Partially resolve the compilation unit
+ CompilationUnit unit = await request.resolveDeclarationsInScope();
scheglov 2015/12/04 17:43:26 It seems too wide. It would be enough to get LIBRA
danrubel 2015/12/04 20:46:22 Thanks for the info. I'll address this in the next
+ // Gracefully degrade if the compilation unit could not be resolved
+ // e.g. detached part file or source change
+ if (unit == null) {
+ return EMPTY_LIST;
+ }
+
+ // Check the target since resolution may have changed it
+ node = request.target.containingNode;
+ if (node is! Combinator) {
+ return EMPTY_LIST;
+ }
+
+ // Build list of suggestions
+ var directive = node.getAncestor((parent) => parent is NamespaceDirective);
+ if (directive is NamespaceDirective) {
+ LibraryElement library = directive.uriElement;
+ if (library != null) {
+ LibraryElementSuggestionBuilder builder =
+ new LibraryElementSuggestionBuilder(
+ request, CompletionSuggestionKind.IDENTIFIER, false, false);
+ library.visitChildren(builder);
+ return builder.suggestions;
+ }
+ }
+ return EMPTY_LIST;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698