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

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

Issue 633153002: cascade target fix and common test (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/test/services/completion/completion_test_util.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/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 1094cee2a5ff376e242c1356fd9aaca98a00c435..3c0ffeaaef7049768491d13316317e759a5635e6 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_server.dart' hide Element, ElementKind;
+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:analysis_server/src/services/search/search_engine.dart';
@@ -51,27 +52,52 @@ class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> {
}
@override
+ Future<bool> visitCombinator(Combinator node) {
+ return _addCombinatorSuggestions(node);
+ }
+
+ @override
+ Future<bool> visitExpressionStatement(ExpressionStatement node) {
+ Expression expression = node.expression;
+ // A pre-variable declaration (e.g. C ^) is parsed as an expression
+ // statement. Do not make suggestions for the variable name.
+ if (expression is SimpleIdentifier && request.offset <= expression.end) {
+ return _addImportedElementSuggestions();
+ }
+ return new Future.value(false);
+ }
+
+ @override
Future<bool> visitNode(AstNode node) {
return new Future.value(false);
}
@override
- Future<bool> visitSimpleIdentifier(SimpleIdentifier node) {
- AstNode parent = node.parent;
- if (parent is Combinator) {
- return _addCombinatorSuggestions(parent);
- }
- if (parent is ExpressionStatement) {
+ Future<bool> visitPrefixedIdentifier(PrefixedIdentifier node) {
+ // Make suggestions for the prefix, but not for the selector
+ // InvocationComputer makes selector suggestions
+ if (request.offset <= node.prefix.end) {
return _addImportedElementSuggestions();
}
- if (parent is PrefixedIdentifier) {
- if (request.offset <= parent.prefix.end) {
- return _addImportedElementSuggestions();
- }
+ return new Future.value(false);
+ }
+
+ @override
+ Future<bool> visitCascadeExpression(CascadeExpression node) {
+ // Make suggestions for the target, but not for the selector
+ // InvocationComputer makes selector suggestions
+ Expression target = node.target;
+ if (target != null && request.offset <= target.end) {
+ return _addImportedElementSuggestions();
}
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) {
@@ -83,6 +109,40 @@ class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> {
return new Future.value(false);
}
+ void _addElementSuggestion(Element element, CompletionRelevance relevance) {
+ CompletionSuggestionKind kind =
+ newCompletionSuggestionKind_fromElementKind(element.kind);
+
+ String completion = element.displayName;
+ CompletionSuggestion suggestion = new CompletionSuggestion(
+ kind,
+ relevance,
+ completion,
+ completion.length,
+ 0,
+ element.isDeprecated,
+ false);
+
+ suggestion.element = newElement_fromEngine(element);
+
+ DartType type;
+ if (element is FunctionElement) {
+ type = element.returnType;
+ } else if (element is PropertyAccessorElement && element.isGetter) {
+ type = element.returnType;
+ } else if (element is TopLevelVariableElement) {
+ type = element.type;
+ }
+ if (type != null) {
+ String name = type.displayName;
+ if (name != null && name.length > 0 && name != 'dynamic') {
+ suggestion.returnType = name;
+ }
+ }
+
+ request.suggestions.add(suggestion);
+ }
+
Future<bool> _addImportedElementSuggestions() {
// Exclude elements from local library
@@ -141,40 +201,6 @@ class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> {
});
}
- void _addElementSuggestion(Element element, CompletionRelevance relevance) {
- CompletionSuggestionKind kind =
- newCompletionSuggestionKind_fromElementKind(element.kind);
-
- String completion = element.displayName;
- CompletionSuggestion suggestion = new CompletionSuggestion(
- kind,
- relevance,
- completion,
- completion.length,
- 0,
- element.isDeprecated,
- false);
-
- suggestion.element = newElement_fromEngine(element);
-
- DartType type;
- if (element is FunctionElement) {
- type = element.returnType;
- } else if (element is PropertyAccessorElement && element.isGetter) {
- type = element.returnType;
- } else if (element is TopLevelVariableElement) {
- type = element.type;
- }
- if (type != null) {
- String name = type.displayName;
- if (name != null && name.length > 0 && name != 'dynamic') {
- suggestion.returnType = name;
- }
- }
-
- request.suggestions.add(suggestion);
- }
-
void _addLibraryPrefixSuggestion(ImportElement importElem) {
String completion = importElem.prefix.displayName;
if (completion != null && completion.length > 0) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/completion_test_util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698