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

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

Issue 617153004: narrow imported element suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix failing test 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/imported_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
index ceed8ff882ddb58d92e920122ac9767b08a5626e..bd1fd8bc4d193a2bdd4f6c2683b8d6e7ebceab9f 100644
--- a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
@@ -6,7 +6,8 @@ library services.completion.computer.dart.toplevel;
import 'dart:async';
-import 'package:analysis_server/src/protocol.dart' as protocol show Element, ElementKind;
+import 'package:analysis_server/src/protocol.dart' as protocol show Element,
+ ElementKind;
import 'package:analysis_server/src/protocol.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';
@@ -45,52 +46,38 @@ class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> {
_ImportedVisitor(this.request);
@override
- Future<bool> visitCombinator(Combinator node) {
- NamespaceDirective directive =
- node.getAncestor((parent) => parent is NamespaceDirective);
- if (directive != null) {
- LibraryElement library = directive.uriElement;
- LibraryElementSuggestionBuilder.suggestionsFor(request, library);
- return new Future.value(true);
- }
- return new Future.value(false);
- }
-
- @override
- Future<bool> visitExpressionStatement(ExpressionStatement node) {
- Expression expression = node.expression;
- if (expression is SimpleIdentifier) {
- if (expression.end < request.offset) {
- // Don't suggest imported elements for local var name
- return new Future.value(false);
- }
- }
- return visitNode(node);
+ Future<bool> visitBlock(Block node) {
+ return _addImportedElementSuggestions();
}
@override
Future<bool> visitNode(AstNode node) {
- return _addImportedElements();
+ return new Future.value(false);
}
@override
Future<bool> visitSimpleIdentifier(SimpleIdentifier node) {
- return node.parent.accept(this);
+ AstNode parent = node.parent;
+ if (parent is Combinator) {
+ return _addCombinatorSuggestions(parent);
+ }
+ if (parent is ExpressionStatement) {
+ return _addImportedElementSuggestions();
+ }
+ return new Future.value(false);
}
- @override
- Future<bool> visitVariableDeclaration(VariableDeclaration node) {
- // Do not add suggestions if editing the name in a var declaration
- SimpleIdentifier name = node.name;
- if (name == null ||
- name.offset < request.offset ||
- request.offset > name.end) {
- return visitNode(node);
+ Future _addCombinatorSuggestions(Combinator node) {
+ var directive = node.getAncestor((parent) => parent is NamespaceDirective);
+ if (directive is NamespaceDirective) {
+ LibraryElement library = directive.uriElement;
+ LibraryElementSuggestionBuilder.suggestionsFor(request, library);
+ return new Future.value(true);
}
return new Future.value(false);
}
- Future<bool> _addImportedElements() {
+ Future<bool> _addImportedElementSuggestions() {
var future = request.searchEngine.searchTopLevelDeclarations('');
return future.then((List<SearchMatch> matches) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698