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

Side by Side Diff: pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart

Issue 2875223003: convert completion tests to use new analysis driver (Closed)
Patch Set: Created 3 years, 7 months 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
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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/protocol/protocol_generated.dart'; 7 import 'package:analysis_server/protocol/protocol_generated.dart';
8 import 'package:analysis_server/src/ide_options.dart'; 8 import 'package:analysis_server/src/ide_options.dart';
9 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; 9 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
10 import 'package:analysis_server/src/services/completion/completion_core.dart'; 10 import 'package:analysis_server/src/services/completion/completion_core.dart';
11 import 'package:analysis_server/src/services/completion/completion_performance.d art'; 11 import 'package:analysis_server/src/services/completion/completion_performance.d art';
12 import 'package:analysis_server/src/services/completion/dart/completion_manager. dart' 12 import 'package:analysis_server/src/services/completion/dart/completion_manager. dart'
13 show DartCompletionRequestImpl, ReplacementRange; 13 show DartCompletionRequestImpl, ReplacementRange;
14 import 'package:analyzer/file_system/file_system.dart'; 14 import 'package:analyzer/file_system/file_system.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/dart/analysis/driver.dart'; 16 import 'package:analyzer/src/dart/analysis/driver.dart';
17 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:analyzer/task/dart.dart';
19 import 'package:test/test.dart'; 18 import 'package:test/test.dart';
20 19
21 import '../../../abstract_context.dart'; 20 import '../../../abstract_context.dart';
22 import '../../correction/flutter_util.dart'; 21 import '../../correction/flutter_util.dart';
23 22
24 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { 23 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) {
25 String c1 = s1.completion.toLowerCase(); 24 String c1 = s1.completion.toLowerCase();
26 String c2 = s2.completion.toLowerCase(); 25 String c2 = s2.completion.toLowerCase();
27 return c1.compareTo(c2); 26 return c1.compareTo(c2);
28 } 27 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 446 }
448 assertHasNoParameterInfo(cs); 447 assertHasNoParameterInfo(cs);
449 return cs; 448 return cs;
450 } 449 }
451 450
452 /** 451 /**
453 * Return a [Future] that completes with the containing library information 452 * Return a [Future] that completes with the containing library information
454 * after it is accessible via [context.getLibrariesContaining]. 453 * after it is accessible via [context.getLibrariesContaining].
455 */ 454 */
456 Future<Null> computeLibrariesContaining([int times = 200]) { 455 Future<Null> computeLibrariesContaining([int times = 200]) {
457 if (enableNewAnalysisDriver) { 456 return driver.getResult(testFile).then((result) => null);
458 return driver.getResult(testFile).then((result) => null);
459 }
460 List<Source> libraries = context.getLibrariesContaining(testSource);
461 if (libraries.isNotEmpty) {
462 return new Future.value(null);
463 }
464 if (times == 0) {
465 fail('failed to determine libraries containing $testSource');
466 }
467 context.performAnalysisTask();
468 // We use a delayed future to allow microtask events to finish. The
469 // Future.value or Future() constructors use scheduleMicrotask themselves an d
470 // would therefore not wait for microtask callbacks that are scheduled after
471 // invoking this method.
472 return new Future.delayed(
473 Duration.ZERO, () => computeLibrariesContaining(times - 1));
474 } 457 }
475 458
476 Future computeSuggestions({int times = 200, IdeOptions options}) async { 459 Future computeSuggestions({int times = 200, IdeOptions options}) async {
477 AnalysisResult analysisResult = await driver.getResult(testFile); 460 AnalysisResult analysisResult = await driver.getResult(testFile);
478 testSource = analysisResult.unit.element.source; 461 testSource = analysisResult.unit.element.source;
479 CompletionRequestImpl baseRequest = new CompletionRequestImpl( 462 CompletionRequestImpl baseRequest = new CompletionRequestImpl(
480 analysisResult, 463 analysisResult,
481 provider, 464 provider,
482 testSource, 465 testSource,
483 completionOffset, 466 completionOffset,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 pathToCode.forEach((path, code) { 504 pathToCode.forEach((path, code) {
522 provider.newFile('$flutterPkgLibPath/$path', code); 505 provider.newFile('$flutterPkgLibPath/$path', code);
523 }); 506 });
524 // configure SourceFactory 507 // configure SourceFactory
525 Folder myPkgFolder = provider.getResource(flutterPkgLibPath); 508 Folder myPkgFolder = provider.getResource(flutterPkgLibPath);
526 UriResolver pkgResolver = new PackageMapUriResolver(provider, { 509 UriResolver pkgResolver = new PackageMapUriResolver(provider, {
527 'flutter': [myPkgFolder] 510 'flutter': [myPkgFolder]
528 }); 511 });
529 SourceFactory sourceFactory = new SourceFactory( 512 SourceFactory sourceFactory = new SourceFactory(
530 [new DartUriResolver(sdk), pkgResolver, resourceResolver]); 513 [new DartUriResolver(sdk), pkgResolver, resourceResolver]);
531 if (enableNewAnalysisDriver) { 514 driver.configure(sourceFactory: sourceFactory);
532 driver.configure(sourceFactory: sourceFactory);
533 } else {
534 context.sourceFactory = sourceFactory;
535 }
536 // force 'flutter' resolution 515 // force 'flutter' resolution
537 addSource( 516 addSource(
538 '/tmp/other.dart', 517 '/tmp/other.dart',
539 pathToCode.keys 518 pathToCode.keys
540 .map((path) => "import 'package:flutter/$path';") 519 .map((path) => "import 'package:flutter/$path';")
541 .join('\n')); 520 .join('\n'));
542 } 521 }
543 522
544 DartCompletionContributor createContributor(); 523 DartCompletionContributor createContributor();
545 524
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 }); 564 });
586 } 565 }
587 return cs; 566 return cs;
588 } 567 }
589 568
590 Future/*<E>*/ performAnalysis/*<E>*/( 569 Future/*<E>*/ performAnalysis/*<E>*/(
591 int times, Completer/*<E>*/ completer) async { 570 int times, Completer/*<E>*/ completer) async {
592 if (completer.isCompleted) { 571 if (completer.isCompleted) {
593 return completer.future; 572 return completer.future;
594 } 573 }
595 if (enableNewAnalysisDriver) {
596 // Just wait.
597 } else {
598 if (times == 0 || context == null) {
599 return new Future.value();
600 }
601 context.performAnalysisTask();
602 }
603 // We use a delayed future to allow microtask events to finish. The 574 // We use a delayed future to allow microtask events to finish. The
604 // Future.value or Future() constructors use scheduleMicrotask themselves an d 575 // Future.value or Future() constructors use scheduleMicrotask themselves an d
605 // would therefore not wait for microtask callbacks that are scheduled after 576 // would therefore not wait for microtask callbacks that are scheduled after
606 // invoking this method. 577 // invoking this method.
607 return new Future.delayed( 578 return new Future.delayed(
608 Duration.ZERO, () => performAnalysis(times - 1, completer)); 579 Duration.ZERO, () => performAnalysis(times - 1, completer));
609 } 580 }
610 581
611 void resolveSource(String path, String content) { 582 void resolveSource(String path, String content) {
612 Source libSource = addSource(path, content); 583 Source libSource = addSource(path, content);
613 if (!enableNewAnalysisDriver) {
614 var target = new LibrarySpecificUnit(libSource, libSource);
615 context.computeResult(target, RESOLVED_UNIT);
616 }
617 } 584 }
618 585
619 @override 586 @override
620 void setUp() { 587 void setUp() {
621 super.setUp(); 588 super.setUp();
622 contributor = createContributor(); 589 contributor = createContributor();
623 } 590 }
624 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698