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

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

Issue 695773003: move import combinator suggestions into a separate computer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 months 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/combinator_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/combinator_computer.dart b/pkg/analysis_server/lib/src/services/completion/combinator_computer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d2ae88659133bdeff7f12253246e6c01dc06a8f1
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/completion/combinator_computer.dart
@@ -0,0 +1,70 @@
+// 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.computer.dart.combinator;
+
+import 'dart:async';
+
+import 'package:analysis_server/src/protocol_server.dart' hide Element,
+ ElementKind;
+import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
+import 'package:analysis_server/src/services/completion/suggestion_builder.dart';
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/element.dart';
+
+/**
+ * A computer for calculating `completion.getSuggestions` request results
+ * for the import combinators show and hide.
+ */
+
+class CombinatorComputer extends DartCompletionComputer {
+
+ @override
+ bool computeFast(DartCompletionRequest request) {
+ return false;
+ }
+
+ @override
+ Future<bool> computeFull(DartCompletionRequest request) {
+ return request.node.accept(new _CombinatorAstVisitor(request));
+ }
+}
+
+/**
+ * A visitor for determining which imported classes and top level variables
+ * should be suggested and building those suggestions.
+ */
+class _CombinatorAstVisitor extends GeneralizingAstVisitor<Future<bool>> {
+ final DartCompletionRequest request;
+
+ _CombinatorAstVisitor(this.request);
+
+ @override
+ Future<bool> visitCombinator(Combinator node) {
+ return _addCombinatorSuggestions(node);
+ }
+
+ @override
+ Future<bool> visitNode(AstNode node) {
+ return new Future.value(false);
+ }
+
+ @override
+ Future<bool> visitSimpleIdentifier(SimpleIdentifier node) {
+ return node.parent.accept(this);
+ }
+
+ Future _addCombinatorSuggestions(Combinator node) {
+ var directive = node.getAncestor((parent) => parent is NamespaceDirective);
+ if (directive is NamespaceDirective) {
+ LibraryElement library = directive.uriElement;
+ LibraryElementSuggestionBuilder.suggestionsFor(
+ request,
+ CompletionSuggestionKind.IDENTIFIER,
+ library);
+ return new Future.value(true);
+ }
+ return new Future.value(false);
+ }
+}
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698