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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/imported_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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.completion.computer.dart.toplevel; 5 library services.completion.computer.dart.toplevel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' hide Element, 9 import 'package:analysis_server/src/protocol_server.dart' hide Element,
10 ElementKind; 10 ElementKind;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 Future<bool> visitClassDeclaration(ClassDeclaration node) { 72 Future<bool> visitClassDeclaration(ClassDeclaration node) {
73 // Make suggestions in the body of the class declaration 73 // Make suggestions in the body of the class declaration
74 Token leftBracket = node.leftBracket; 74 Token leftBracket = node.leftBracket;
75 if (leftBracket != null && request.offset >= leftBracket.end) { 75 if (leftBracket != null && request.offset >= leftBracket.end) {
76 return _addImportedElementSuggestions(node); 76 return _addImportedElementSuggestions(node);
77 } 77 }
78 return new Future.value(false); 78 return new Future.value(false);
79 } 79 }
80 80
81 @override 81 @override
82 Future<bool> visitCombinator(Combinator node) {
83 return _addCombinatorSuggestions(node);
84 }
85
86 @override
87 Future<bool> visitExpression(Expression node) { 82 Future<bool> visitExpression(Expression node) {
88 return _addImportedElementSuggestions(node, excludeVoidReturn: true); 83 return _addImportedElementSuggestions(node, excludeVoidReturn: true);
89 } 84 }
90 85
91 @override 86 @override
92 Future<bool> visitExpressionStatement(ExpressionStatement node) { 87 Future<bool> visitExpressionStatement(ExpressionStatement node) {
93 Expression expression = node.expression; 88 Expression expression = node.expression;
94 // A pre-variable declaration (e.g. C ^) is parsed as an expression 89 // A pre-variable declaration (e.g. C ^) is parsed as an expression
95 // statement. Do not make suggestions for the variable name. 90 // statement. Do not make suggestions for the variable name.
96 if (expression is SimpleIdentifier && request.offset <= expression.end) { 91 if (expression is SimpleIdentifier && request.offset <= expression.end) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 @override 190 @override
196 visitVariableDeclaration(VariableDeclaration node) { 191 visitVariableDeclaration(VariableDeclaration node) {
197 Token equals = node.equals; 192 Token equals = node.equals;
198 // Make suggestions for the RHS of a variable declaration 193 // Make suggestions for the RHS of a variable declaration
199 if (equals != null && request.offset >= equals.end) { 194 if (equals != null && request.offset >= equals.end) {
200 return _addImportedElementSuggestions(node, excludeVoidReturn: true); 195 return _addImportedElementSuggestions(node, excludeVoidReturn: true);
201 } 196 }
202 return new Future.value(false); 197 return new Future.value(false);
203 } 198 }
204 199
205 Future _addCombinatorSuggestions(Combinator node) {
206 var directive = node.getAncestor((parent) => parent is NamespaceDirective);
207 if (directive is NamespaceDirective) {
208 LibraryElement library = directive.uriElement;
209 LibraryElementSuggestionBuilder.suggestionsFor(
210 request,
211 CompletionSuggestionKind.IDENTIFIER,
212 library);
213 return new Future.value(true);
214 }
215 return new Future.value(false);
216 }
217
218 void _addElementSuggestion(Element element, bool typesOnly, 200 void _addElementSuggestion(Element element, bool typesOnly,
219 bool excludeVoidReturn, CompletionRelevance relevance) { 201 bool excludeVoidReturn, CompletionRelevance relevance) {
220 202
221 if (element is ExecutableElement) { 203 if (element is ExecutableElement) {
222 if (element.isOperator) { 204 if (element.isOperator) {
223 return; 205 return;
224 } 206 }
225 if (excludeVoidReturn) { 207 if (excludeVoidReturn) {
226 DartType returnType = element.returnType; 208 DartType returnType = element.returnType;
227 if (returnType != null && returnType.isVoid) { 209 if (returnType != null && returnType.isVoid) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 importElem.isDeprecated, 382 importElem.isDeprecated,
401 false); 383 false);
402 LibraryElement lib = importElem.importedLibrary; 384 LibraryElement lib = importElem.importedLibrary;
403 if (lib != null) { 385 if (lib != null) {
404 suggestion.element = newElement_fromEngine(lib); 386 suggestion.element = newElement_fromEngine(lib);
405 } 387 }
406 request.suggestions.add(suggestion); 388 request.suggestions.add(suggestion);
407 } 389 }
408 } 390 }
409 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698