| 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/ast_provider_context.dart'; |
| 21 import 'package:analyzer/src/dart/analysis/driver.dart'; | 22 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
| 24 import 'package:test/test.dart'; | 25 import 'package:test/test.dart'; |
| 25 | 26 |
| 26 import '../../../abstract_context.dart'; | 27 import '../../../abstract_context.dart'; |
| 27 | 28 |
| 28 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { | 29 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { |
| 29 String c1 = s1.completion.toLowerCase(); | 30 String c1 = s1.completion.toLowerCase(); |
| 30 String c2 = s2.completion.toLowerCase(); | 31 String c2 = s2.completion.toLowerCase(); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 Future computeSuggestions([int times = 200]) async { | 459 Future computeSuggestions([int times = 200]) async { |
| 459 AnalysisResult analysisResult = null; | 460 AnalysisResult analysisResult = null; |
| 460 if (enableNewAnalysisDriver) { | 461 if (enableNewAnalysisDriver) { |
| 461 analysisResult = await driver.getResult(testFile); | 462 analysisResult = await driver.getResult(testFile); |
| 462 testSource = analysisResult.unit.element.source; | 463 testSource = analysisResult.unit.element.source; |
| 463 } else { | 464 } else { |
| 464 context.analysisPriorityOrder = [testSource]; | 465 context.analysisPriorityOrder = [testSource]; |
| 465 } | 466 } |
| 466 CompletionRequestImpl baseRequest = new CompletionRequestImpl( | 467 CompletionRequestImpl baseRequest = new CompletionRequestImpl( |
| 467 analysisResult, | 468 analysisResult, |
| 468 enableNewAnalysisDriver ? null: context, | 469 enableNewAnalysisDriver ? null : context, |
| 469 provider, | 470 provider, |
| 470 searchEngine, | 471 searchEngine, |
| 471 testSource, | 472 testSource, |
| 472 completionOffset, | 473 completionOffset, |
| 473 new CompletionPerformance()); | 474 new CompletionPerformance()); |
| 474 | 475 |
| 475 // Build the request | 476 // Build the request |
| 476 Completer<DartCompletionRequest> requestCompleter = | 477 Completer<DartCompletionRequest> requestCompleter = |
| 477 new Completer<DartCompletionRequest>(); | 478 new Completer<DartCompletionRequest>(); |
| 478 DartCompletionRequestImpl | 479 DartCompletionRequestImpl |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 cs = s; | 541 cs = s; |
| 541 } else { | 542 } else { |
| 542 failedCompletion('expected exactly one $cs', | 543 failedCompletion('expected exactly one $cs', |
| 543 suggestions.where((s) => s.completion == completion)); | 544 suggestions.where((s) => s.completion == completion)); |
| 544 } | 545 } |
| 545 }); | 546 }); |
| 546 } | 547 } |
| 547 return cs; | 548 return cs; |
| 548 } | 549 } |
| 549 | 550 |
| 550 Future/*<E>*/ performAnalysis/*<E>*/(int times, Completer/*<E>*/ completer) as
ync { | 551 Future/*<E>*/ performAnalysis/*<E>*/( |
| 552 int times, Completer/*<E>*/ completer) async { |
| 551 if (completer.isCompleted) { | 553 if (completer.isCompleted) { |
| 552 return completer.future; | 554 return completer.future; |
| 553 } | 555 } |
| 554 if (enableNewAnalysisDriver) { | 556 if (enableNewAnalysisDriver) { |
| 555 // Just wait. | 557 // Just wait. |
| 556 } else { | 558 } else { |
| 557 if (times == 0 || context == null) { | 559 if (times == 0 || context == null) { |
| 558 return new Future.value(); | 560 return new Future.value(); |
| 559 } | 561 } |
| 560 context.performAnalysisTask(); | 562 context.performAnalysisTask(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 572 if (!enableNewAnalysisDriver) { | 574 if (!enableNewAnalysisDriver) { |
| 573 var target = new LibrarySpecificUnit(libSource, libSource); | 575 var target = new LibrarySpecificUnit(libSource, libSource); |
| 574 context.computeResult(target, RESOLVED_UNIT); | 576 context.computeResult(target, RESOLVED_UNIT); |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 | 579 |
| 578 @override | 580 @override |
| 579 void setUp() { | 581 void setUp() { |
| 580 super.setUp(); | 582 super.setUp(); |
| 581 index = createMemoryIndex(); | 583 index = createMemoryIndex(); |
| 582 searchEngine = new SearchEngineImpl(index); | 584 searchEngine = |
| 585 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); |
| 583 contributor = createContributor(); | 586 contributor = createContributor(); |
| 584 } | 587 } |
| 585 } | 588 } |
| OLD | NEW |