| OLD | NEW |
| 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 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' hide Element, | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| 11 ElementKind; | 11 ElementKind; |
| 12 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 12 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; | 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 15 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
| 16 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
| 17 import 'package:analyzer/src/generated/scanner.dart'; | 17 import 'package:analyzer/src/generated/scanner.dart'; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * A computer for calculating imported class and top level variable | 20 * A computer for calculating imported class and top level variable |
| 21 * `completion.getSuggestions` request results. | 21 * `completion.getSuggestions` request results. |
| 22 */ | 22 */ |
| 23 class ImportedComputer extends DartCompletionComputer { | 23 class ImportedComputer extends DartCompletionComputer { |
| 24 final bool shouldWaitForLowPrioritySuggestions; |
| 24 _ImportedSuggestionBuilder builder; | 25 _ImportedSuggestionBuilder builder; |
| 25 | 26 |
| 27 ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false}); |
| 28 |
| 26 @override | 29 @override |
| 27 bool computeFast(DartCompletionRequest request) { | 30 bool computeFast(DartCompletionRequest request) { |
| 28 builder = request.node.accept(new _ImportedAstVisitor(request)); | 31 builder = request.node.accept(new _ImportedAstVisitor(request)); |
| 29 if (builder != null) { | 32 if (builder != null) { |
| 33 builder.shouldWaitForLowPrioritySuggestions = shouldWaitForLowPrioritySugg
estions; |
| 30 return builder.computeFast(request.node); | 34 return builder.computeFast(request.node); |
| 31 } | 35 } |
| 32 return true; | 36 return true; |
| 33 } | 37 } |
| 34 | 38 |
| 35 @override | 39 @override |
| 36 Future<bool> computeFull(DartCompletionRequest request) { | 40 Future<bool> computeFull(DartCompletionRequest request) { |
| 37 if (builder != null) { | 41 if (builder != null) { |
| 38 return builder.computeFull(request.node); | 42 return builder.computeFull(request.node); |
| 39 } | 43 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 208 } |
| 205 return null; | 209 return null; |
| 206 } | 210 } |
| 207 } | 211 } |
| 208 | 212 |
| 209 /** | 213 /** |
| 210 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions | 214 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions |
| 211 * based upon imported elements. | 215 * based upon imported elements. |
| 212 */ | 216 */ |
| 213 class _ImportedSuggestionBuilder implements SuggestionBuilder { | 217 class _ImportedSuggestionBuilder implements SuggestionBuilder { |
| 218 bool shouldWaitForLowPrioritySuggestions; |
| 214 final DartCompletionRequest request; | 219 final DartCompletionRequest request; |
| 215 final bool typesOnly; | 220 final bool typesOnly; |
| 216 final bool excludeVoidReturn; | 221 final bool excludeVoidReturn; |
| 217 DartCompletionCache cache; | 222 DartCompletionCache cache; |
| 218 | 223 |
| 219 _ImportedSuggestionBuilder(this.request, {this.typesOnly: false, | 224 _ImportedSuggestionBuilder(this.request, {this.typesOnly: false, |
| 220 this.excludeVoidReturn: false}) { | 225 this.excludeVoidReturn: false}) { |
| 221 cache = request.cache; | 226 cache = request.cache; |
| 222 } | 227 } |
| 223 | 228 |
| 224 /** | 229 /** |
| 225 * If the needed information is cached, then add suggestions and return `true` | 230 * If the needed information is cached, then add suggestions and return `true` |
| 226 * else return `false` indicating that additional work is necessary. | 231 * else return `false` indicating that additional work is necessary. |
| 227 */ | 232 */ |
| 228 bool computeFast(AstNode node) { | 233 bool computeFast(AstNode node) { |
| 229 CompilationUnit unit = request.unit; | 234 CompilationUnit unit = request.unit; |
| 230 if (cache.isImportInfoCached(unit)) { | 235 if (cache.isImportInfoCached(unit)) { |
| 231 _addInheritedSuggestions(node); | 236 _addInheritedSuggestions(node); |
| 232 _addTopLevelSuggestions(); | 237 _addTopLevelSuggestions(); |
| 233 return true; | 238 return true; |
| 234 } | 239 } |
| 235 return false; | 240 return false; |
| 236 } | 241 } |
| 237 | 242 |
| 238 /** | 243 /** |
| 239 * Compute suggested based upon imported elements. | 244 * Compute suggested based upon imported elements. |
| 240 */ | 245 */ |
| 241 Future<bool> computeFull(AstNode node) { | 246 Future<bool> computeFull(AstNode node) { |
| 242 return cache.computeImportInfo( | 247 |
| 243 request.unit, | 248 Future<bool> addSuggestions(_) { |
| 244 request.searchEngine).then((_) { | |
| 245 _addInheritedSuggestions(node); | 249 _addInheritedSuggestions(node); |
| 246 _addTopLevelSuggestions(); | 250 _addTopLevelSuggestions(); |
| 247 return true; | 251 return new Future.value(true); |
| 248 }); | 252 } |
| 253 |
| 254 Future future = cache.computeImportInfo(request.unit, request.searchEngine); |
| 255 if (shouldWaitForLowPrioritySuggestions) { |
| 256 return future.then(addSuggestions); |
| 257 } else { |
| 258 return addSuggestions(true); |
| 259 } |
| 249 } | 260 } |
| 250 | 261 |
| 251 /** | 262 /** |
| 252 * Add imported element suggestions. | 263 * Add imported element suggestions. |
| 253 */ | 264 */ |
| 254 void _addElementSuggestions(List<Element> elements) { | 265 void _addElementSuggestions(List<Element> elements) { |
| 255 elements.forEach((Element elem) { | 266 elements.forEach((Element elem) { |
| 256 if (elem is! ClassElement) { | 267 if (elem is! ClassElement) { |
| 257 if (typesOnly) { | 268 if (typesOnly) { |
| 258 return; | 269 return; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 ..addAll(cache.importedTypeSuggestions) | 323 ..addAll(cache.importedTypeSuggestions) |
| 313 ..addAll(cache.libraryPrefixSuggestions); | 324 ..addAll(cache.libraryPrefixSuggestions); |
| 314 if (!typesOnly) { | 325 if (!typesOnly) { |
| 315 request.suggestions.addAll(cache.otherImportedSuggestions); | 326 request.suggestions.addAll(cache.otherImportedSuggestions); |
| 316 if (!excludeVoidReturn) { | 327 if (!excludeVoidReturn) { |
| 317 request.suggestions.addAll(cache.importedVoidReturnSuggestions); | 328 request.suggestions.addAll(cache.importedVoidReturnSuggestions); |
| 318 } | 329 } |
| 319 } | 330 } |
| 320 } | 331 } |
| 321 } | 332 } |
| OLD | NEW |