| 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 test.services.completion.dart.util; | 5 library test.services.completion.dart.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| 11 import 'package:analysis_server/plugin/protocol/protocol.dart' | 11 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 12 hide Element, ElementKind; | 12 hide Element, ElementKind; |
| 13 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 13 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
| 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
| 16 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 16 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
| 17 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' | 17 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' |
| 18 show DartCompletionRequestImpl, ReplacementRange; | 18 show DartCompletionRequestImpl, ReplacementRange; |
| 19 import 'package:analysis_server/src/services/index/index.dart'; | 19 import 'package:analysis_server/src/services/index/index.dart'; |
| 20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 21 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| 22 import 'package:analyzer/task/dart.dart'; | 23 import 'package:analyzer/task/dart.dart'; |
| 23 import 'package:test/test.dart'; | 24 import 'package:test/test.dart'; |
| 24 | 25 |
| 25 import '../../../abstract_context.dart'; | 26 import '../../../abstract_context.dart'; |
| 26 | 27 |
| 27 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { | 28 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { |
| 28 String c1 = s1.completion.toLowerCase(); | 29 String c1 = s1.completion.toLowerCase(); |
| 29 String c2 = s2.completion.toLowerCase(); | 30 String c2 = s2.completion.toLowerCase(); |
| 30 return c1.compareTo(c2); | 31 return c1.compareTo(c2); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 {bool isDeprecated: false}) { | 211 {bool isDeprecated: false}) { |
| 211 CompletionSuggestion suggestion = | 212 CompletionSuggestion suggestion = |
| 212 assertSuggest(completion, isDeprecated: isDeprecated); | 213 assertSuggest(completion, isDeprecated: isDeprecated); |
| 213 expect(suggestion.isDeprecated, isDeprecated); | 214 expect(suggestion.isDeprecated, isDeprecated); |
| 214 expect(suggestion.element.kind, protocol.ElementKind.ENUM); | 215 expect(suggestion.element.kind, protocol.ElementKind.ENUM); |
| 215 return suggestion; | 216 return suggestion; |
| 216 } | 217 } |
| 217 | 218 |
| 218 CompletionSuggestion assertSuggestEnumConst(String completion, | 219 CompletionSuggestion assertSuggestEnumConst(String completion, |
| 219 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 220 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
| 220 CompletionSuggestion suggestion = | 221 CompletionSuggestion suggestion = assertSuggest(completion, |
| 221 assertSuggest(completion, relevance: relevance, isDeprecated: isDeprecat
ed); | 222 relevance: relevance, isDeprecated: isDeprecated); |
| 222 expect(suggestion.completion, completion); | 223 expect(suggestion.completion, completion); |
| 223 expect(suggestion.isDeprecated, isDeprecated); | 224 expect(suggestion.isDeprecated, isDeprecated); |
| 224 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT); | 225 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT); |
| 225 return suggestion; | 226 return suggestion; |
| 226 } | 227 } |
| 227 | 228 |
| 228 CompletionSuggestion assertSuggestField(String name, String type, | 229 CompletionSuggestion assertSuggestField(String name, String type, |
| 229 {int relevance: DART_RELEVANCE_DEFAULT, | 230 {int relevance: DART_RELEVANCE_DEFAULT, |
| 230 String importUri, | 231 String importUri, |
| 231 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 232 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 context.performAnalysisTask(); | 446 context.performAnalysisTask(); |
| 446 // We use a delayed future to allow microtask events to finish. The | 447 // We use a delayed future to allow microtask events to finish. The |
| 447 // Future.value or Future() constructors use scheduleMicrotask themselves an
d | 448 // Future.value or Future() constructors use scheduleMicrotask themselves an
d |
| 448 // would therefore not wait for microtask callbacks that are scheduled after | 449 // would therefore not wait for microtask callbacks that are scheduled after |
| 449 // invoking this method. | 450 // invoking this method. |
| 450 return new Future.delayed( | 451 return new Future.delayed( |
| 451 Duration.ZERO, () => computeLibrariesContaining(times - 1)); | 452 Duration.ZERO, () => computeLibrariesContaining(times - 1)); |
| 452 } | 453 } |
| 453 | 454 |
| 454 Future computeSuggestions([int times = 200]) async { | 455 Future computeSuggestions([int times = 200]) async { |
| 455 context.analysisPriorityOrder = [testSource]; | 456 AnalysisResult analysisResult = null; |
| 457 if (enableNewAnalysisDriver) { |
| 458 analysisResult = await driver.getResult(testFile); |
| 459 testSource = analysisResult.unit.element.source; |
| 460 } else { |
| 461 context.analysisPriorityOrder = [testSource]; |
| 462 } |
| 456 CompletionRequestImpl baseRequest = new CompletionRequestImpl( | 463 CompletionRequestImpl baseRequest = new CompletionRequestImpl( |
| 457 null, | 464 analysisResult, |
| 458 context, | 465 enableNewAnalysisDriver ? null: context, |
| 459 provider, | 466 provider, |
| 460 searchEngine, | 467 searchEngine, |
| 461 testSource, | 468 testSource, |
| 462 completionOffset, | 469 completionOffset, |
| 463 new CompletionPerformance()); | 470 new CompletionPerformance()); |
| 464 | 471 |
| 465 // Build the request | 472 // Build the request |
| 466 Completer<DartCompletionRequest> requestCompleter = | 473 Completer<DartCompletionRequest> requestCompleter = |
| 467 new Completer<DartCompletionRequest>(); | 474 new Completer<DartCompletionRequest>(); |
| 468 DartCompletionRequestImpl | 475 DartCompletionRequestImpl |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 cs = s; | 537 cs = s; |
| 531 } else { | 538 } else { |
| 532 failedCompletion('expected exactly one $cs', | 539 failedCompletion('expected exactly one $cs', |
| 533 suggestions.where((s) => s.completion == completion)); | 540 suggestions.where((s) => s.completion == completion)); |
| 534 } | 541 } |
| 535 }); | 542 }); |
| 536 } | 543 } |
| 537 return cs; | 544 return cs; |
| 538 } | 545 } |
| 539 | 546 |
| 540 Future/*<E>*/ performAnalysis/*<E>*/(int times, Completer/*<E>*/ completer) { | 547 Future/*<E>*/ performAnalysis/*<E>*/(int times, Completer/*<E>*/ completer) as
ync { |
| 541 if (completer.isCompleted) { | 548 if (completer.isCompleted) { |
| 542 return completer.future; | 549 return completer.future; |
| 543 } | 550 } |
| 544 if (times == 0 || context == null) { | 551 if (enableNewAnalysisDriver) { |
| 545 return new Future.value(); | 552 // Just wait. |
| 553 } else { |
| 554 if (times == 0 || context == null) { |
| 555 return new Future.value(); |
| 556 } |
| 557 context.performAnalysisTask(); |
| 546 } | 558 } |
| 547 context.performAnalysisTask(); | |
| 548 // We use a delayed future to allow microtask events to finish. The | 559 // We use a delayed future to allow microtask events to finish. The |
| 549 // Future.value or Future() constructors use scheduleMicrotask themselves an
d | 560 // Future.value or Future() constructors use scheduleMicrotask themselves an
d |
| 550 // would therefore not wait for microtask callbacks that are scheduled after | 561 // would therefore not wait for microtask callbacks that are scheduled after |
| 551 // invoking this method. | 562 // invoking this method. |
| 552 return new Future.delayed( | 563 return new Future.delayed( |
| 553 Duration.ZERO, () => performAnalysis(times - 1, completer)); | 564 Duration.ZERO, () => performAnalysis(times - 1, completer)); |
| 554 } | 565 } |
| 555 | 566 |
| 556 void resolveSource(String path, String content) { | 567 void resolveSource(String path, String content) { |
| 557 Source libSource = addSource(path, content); | 568 Source libSource = addSource(path, content); |
| 558 var target = new LibrarySpecificUnit(libSource, libSource); | 569 var target = new LibrarySpecificUnit(libSource, libSource); |
| 559 context.computeResult(target, RESOLVED_UNIT); | 570 context.computeResult(target, RESOLVED_UNIT); |
| 560 } | 571 } |
| 561 | 572 |
| 562 @override | 573 @override |
| 563 void setUp() { | 574 void setUp() { |
| 564 super.setUp(); | 575 super.setUp(); |
| 565 index = createMemoryIndex(); | 576 index = createMemoryIndex(); |
| 566 searchEngine = new SearchEngineImpl(index); | 577 searchEngine = new SearchEngineImpl(index); |
| 567 contributor = createContributor(); | 578 contributor = createContributor(); |
| 568 } | 579 } |
| 569 } | 580 } |
| OLD | NEW |