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

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

Issue 787663004: cache suggestions on change in priority sources (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years 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 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 bool shouldWaitForLowPrioritySuggestions;
25 _ImportedSuggestionBuilder builder; 25 _ImportedSuggestionBuilder builder;
26 26
27 ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false}); 27 ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false});
28 28
29 @override 29 @override
30 bool computeFast(DartCompletionRequest request) { 30 bool computeFast(DartCompletionRequest request) {
31 builder = request.node.accept(new _ImportedAstVisitor(request)); 31 builder = request.node.accept(new _ImportedAstVisitor(request));
32 if (builder != null) { 32 if (builder != null) {
33 builder.shouldWaitForLowPrioritySuggestions = shouldWaitForLowPrioritySugg estions; 33 builder.shouldWaitForLowPrioritySuggestions =
34 shouldWaitForLowPrioritySuggestions;
34 return builder.computeFast(request.node); 35 return builder.computeFast(request.node);
35 } 36 }
36 return true; 37 return true;
37 } 38 }
38 39
39 @override 40 @override
40 Future<bool> computeFull(DartCompletionRequest request) { 41 Future<bool> computeFull(DartCompletionRequest request) {
41 if (builder != null) { 42 if (builder != null) {
42 return builder.computeFull(request.node); 43 return builder.computeFull(request.node);
43 } 44 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 * Compute suggested based upon imported elements. 245 * Compute suggested based upon imported elements.
245 */ 246 */
246 Future<bool> computeFull(AstNode node) { 247 Future<bool> computeFull(AstNode node) {
247 248
248 Future<bool> addSuggestions(_) { 249 Future<bool> addSuggestions(_) {
249 _addInheritedSuggestions(node); 250 _addInheritedSuggestions(node);
250 _addTopLevelSuggestions(); 251 _addTopLevelSuggestions();
251 return new Future.value(true); 252 return new Future.value(true);
252 } 253 }
253 254
254 Future future = cache.computeImportInfo(request.unit, request.searchEngine); 255 Future future = null;
255 if (shouldWaitForLowPrioritySuggestions) { 256 if (!cache.isImportInfoCached(request.unit)) {
257 future = cache.computeImportInfo(request.unit, request.searchEngine);
258 }
259 if (future != null && shouldWaitForLowPrioritySuggestions) {
256 return future.then(addSuggestions); 260 return future.then(addSuggestions);
257 } else {
258 return addSuggestions(true);
259 } 261 }
262 return addSuggestions(true);
260 } 263 }
261 264
262 /** 265 /**
263 * Add imported element suggestions. 266 * Add imported element suggestions.
264 */ 267 */
265 void _addElementSuggestions(List<Element> elements) { 268 void _addElementSuggestions(List<Element> elements) {
266 elements.forEach((Element elem) { 269 elements.forEach((Element elem) {
267 if (elem is! ClassElement) { 270 if (elem is! ClassElement) {
268 if (typesOnly) { 271 if (typesOnly) {
269 return; 272 return;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ..addAll(cache.importedTypeSuggestions) 326 ..addAll(cache.importedTypeSuggestions)
324 ..addAll(cache.libraryPrefixSuggestions); 327 ..addAll(cache.libraryPrefixSuggestions);
325 if (!typesOnly) { 328 if (!typesOnly) {
326 request.suggestions.addAll(cache.otherImportedSuggestions); 329 request.suggestions.addAll(cache.otherImportedSuggestions);
327 if (!excludeVoidReturn) { 330 if (!excludeVoidReturn) {
328 request.suggestions.addAll(cache.importedVoidReturnSuggestions); 331 request.suggestions.addAll(cache.importedVoidReturnSuggestions);
329 } 332 }
330 } 333 }
331 } 334 }
332 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698