| 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.domain.completion; | 5 library test.domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/completion/completion_core.dart' | 9 import 'package:analysis_server/completion/completion_core.dart' |
| 10 show CompletionRequest, CompletionResult; | 10 show CompletionRequest, CompletionResult; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 AnalysisDomainHandler analysisDomain; | 48 AnalysisDomainHandler analysisDomain; |
| 49 Test_CompletionDomainHandler completionDomain; | 49 Test_CompletionDomainHandler completionDomain; |
| 50 Request request; | 50 Request request; |
| 51 int requestCount = 0; | 51 int requestCount = 0; |
| 52 String testFile2 = '/project/bin/test2.dart'; | 52 String testFile2 = '/project/bin/test2.dart'; |
| 53 | 53 |
| 54 AnalysisServer createAnalysisServer(Index index) { | 54 AnalysisServer createAnalysisServer(Index index) { |
| 55 ExtensionManager manager = new ExtensionManager(); | 55 ExtensionManager manager = new ExtensionManager(); |
| 56 ServerPlugin serverPlugin = new ServerPlugin(); | 56 ServerPlugin serverPlugin = new ServerPlugin(); |
| 57 manager.processPlugins([serverPlugin]); | 57 manager.processPlugins([serverPlugin]); |
| 58 return new Test_AnalysisServer(super.serverChannel, super.resourceProvider, | 58 return new Test_AnalysisServer( |
| 59 super.packageMapProvider, index, serverPlugin, | 59 super.serverChannel, |
| 60 new AnalysisServerOptions(), new MockSdk(), | 60 super.resourceProvider, |
| 61 super.packageMapProvider, |
| 62 index, |
| 63 serverPlugin, |
| 64 new AnalysisServerOptions(), |
| 65 new MockSdk(), |
| 61 InstrumentationService.NULL_SERVICE); | 66 InstrumentationService.NULL_SERVICE); |
| 62 } | 67 } |
| 63 | 68 |
| 64 @override | 69 @override |
| 65 Index createIndex() { | 70 Index createIndex() { |
| 66 return createLocalMemoryIndex(); | 71 return createLocalMemoryIndex(); |
| 67 } | 72 } |
| 68 | 73 |
| 69 void sendRequest(String path) { | 74 void sendRequest(String path) { |
| 70 String id = (++requestCount).toString(); | 75 String id = (++requestCount).toString(); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // Wait for analysis then edit the content | 420 // Wait for analysis then edit the content |
| 416 await waitForTasksFinished(); | 421 await waitForTasksFinished(); |
| 417 String revisedContent = testCode.substring(0, completionOffset) + | 422 String revisedContent = testCode.substring(0, completionOffset) + |
| 418 'i' + | 423 'i' + |
| 419 testCode.substring(completionOffset); | 424 testCode.substring(completionOffset); |
| 420 ++completionOffset; | 425 ++completionOffset; |
| 421 server.handleRequest(new AnalysisUpdateContentParams( | 426 server.handleRequest(new AnalysisUpdateContentParams( |
| 422 {testFile: new AddContentOverlay(revisedContent)}).toRequest('add1')); | 427 {testFile: new AddContentOverlay(revisedContent)}).toRequest('add1')); |
| 423 | 428 |
| 424 // Request code completion immediately after edit | 429 // Request code completion immediately after edit |
| 425 Response response = handleSuccessfulRequest(new CompletionGetSuggestionsPara
ms( | 430 Response response = handleSuccessfulRequest( |
| 426 testFile, completionOffset).toRequest('0')); | 431 new CompletionGetSuggestionsParams(testFile, completionOffset) |
| 432 .toRequest('0')); |
| 427 completionId = response.id; | 433 completionId = response.id; |
| 428 assertValidId(completionId); | 434 assertValidId(completionId); |
| 429 await waitForTasksFinished(); | 435 await waitForTasksFinished(); |
| 430 expect(replacementOffset, completionOffset - 1); | 436 expect(replacementOffset, completionOffset - 1); |
| 431 expect(replacementLength, 1); | 437 expect(replacementLength, 1); |
| 432 assertHasResult(CompletionSuggestionKind.KEYWORD, 'library', | 438 assertHasResult(CompletionSuggestionKind.KEYWORD, 'library', |
| 433 relevance: DART_RELEVANCE_HIGH); | 439 relevance: DART_RELEVANCE_HIGH); |
| 434 assertHasResult(CompletionSuggestionKind.KEYWORD, 'import', | 440 assertHasResult(CompletionSuggestionKind.KEYWORD, 'import', |
| 435 relevance: DART_RELEVANCE_HIGH); | 441 relevance: DART_RELEVANCE_HIGH); |
| 436 assertHasResult(CompletionSuggestionKind.KEYWORD, 'export', | 442 assertHasResult(CompletionSuggestionKind.KEYWORD, 'export', |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 '''); | 535 '''); |
| 530 return getSuggestions().then((_) { | 536 return getSuggestions().then((_) { |
| 531 expect(replacementOffset, equals(completionOffset)); | 537 expect(replacementOffset, equals(completionOffset)); |
| 532 expect(replacementLength, equals(0)); | 538 expect(replacementLength, equals(0)); |
| 533 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm', | 539 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm', |
| 534 relevance: DART_RELEVANCE_LOCAL_METHOD); | 540 relevance: DART_RELEVANCE_LOCAL_METHOD); |
| 535 }); | 541 }); |
| 536 } | 542 } |
| 537 | 543 |
| 538 test_partFile() { | 544 test_partFile() { |
| 539 addFile('/project/bin/testA.dart', ''' | 545 addFile( |
| 546 '/project/bin/testA.dart', |
| 547 ''' |
| 540 library libA; | 548 library libA; |
| 541 part "$testFile"; | 549 part "$testFile"; |
| 542 import 'dart:html'; | 550 import 'dart:html'; |
| 543 class A { } | 551 class A { } |
| 544 '''); | 552 '''); |
| 545 addTestFile(''' | 553 addTestFile(''' |
| 546 part of libA; | 554 part of libA; |
| 547 main() {^}'''); | 555 main() {^}'''); |
| 548 return getSuggestions().then((_) { | 556 return getSuggestions().then((_) { |
| 549 expect(replacementOffset, equals(completionOffset)); | 557 expect(replacementOffset, equals(completionOffset)); |
| 550 expect(replacementLength, equals(0)); | 558 expect(replacementLength, equals(0)); |
| 551 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); | 559 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 552 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); | 560 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 553 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); | 561 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); |
| 554 assertNoResult('test'); | 562 assertNoResult('test'); |
| 555 }); | 563 }); |
| 556 } | 564 } |
| 557 | 565 |
| 558 test_partFile2() { | 566 test_partFile2() { |
| 559 addFile('/testA.dart', ''' | 567 addFile( |
| 568 '/testA.dart', |
| 569 ''' |
| 560 part of libA; | 570 part of libA; |
| 561 class A { }'''); | 571 class A { }'''); |
| 562 addTestFile(''' | 572 addTestFile(''' |
| 563 library libA; | 573 library libA; |
| 564 part "/testA.dart"; | 574 part "/testA.dart"; |
| 565 import 'dart:html'; | 575 import 'dart:html'; |
| 566 main() {^} | 576 main() {^} |
| 567 '''); | 577 '''); |
| 568 return getSuggestions().then((_) { | 578 return getSuggestions().then((_) { |
| 569 expect(replacementOffset, equals(completionOffset)); | 579 expect(replacementOffset, equals(completionOffset)); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 ++cancelCount; | 719 ++cancelCount; |
| 710 return new Future.value(true); | 720 return new Future.value(true); |
| 711 } | 721 } |
| 712 | 722 |
| 713 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 723 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 714 } | 724 } |
| 715 | 725 |
| 716 class Test_AnalysisServer extends AnalysisServer { | 726 class Test_AnalysisServer extends AnalysisServer { |
| 717 final MockContext mockContext = new MockContext(); | 727 final MockContext mockContext = new MockContext(); |
| 718 | 728 |
| 719 Test_AnalysisServer(ServerCommunicationChannel channel, | 729 Test_AnalysisServer( |
| 730 ServerCommunicationChannel channel, |
| 720 ResourceProvider resourceProvider, | 731 ResourceProvider resourceProvider, |
| 721 PubPackageMapProvider packageMapProvider, Index index, | 732 PubPackageMapProvider packageMapProvider, |
| 722 ServerPlugin serverPlugin, AnalysisServerOptions analysisServerOptions, | 733 Index index, |
| 723 DartSdk defaultSdk, InstrumentationService instrumentationService) | 734 ServerPlugin serverPlugin, |
| 724 : super(channel, resourceProvider, packageMapProvider, index, | 735 AnalysisServerOptions analysisServerOptions, |
| 725 serverPlugin, analysisServerOptions, defaultSdk, | 736 DartSdk defaultSdk, |
| 726 instrumentationService); | 737 InstrumentationService instrumentationService) |
| 738 : super( |
| 739 channel, |
| 740 resourceProvider, |
| 741 packageMapProvider, |
| 742 index, |
| 743 serverPlugin, |
| 744 analysisServerOptions, |
| 745 defaultSdk, |
| 746 instrumentationService); |
| 727 | 747 |
| 728 @override | 748 @override |
| 729 AnalysisContext getAnalysisContext(String path) { | 749 AnalysisContext getAnalysisContext(String path) { |
| 730 return mockContext; | 750 return mockContext; |
| 731 } | 751 } |
| 732 | 752 |
| 733 @override | 753 @override |
| 734 ContextSourcePair getContextSourcePair(String path) { | 754 ContextSourcePair getContextSourcePair(String path) { |
| 735 ContextSourcePair pair = super.getContextSourcePair(path); | 755 ContextSourcePair pair = super.getContextSourcePair(path); |
| 736 return new ContextSourcePair(mockContext, pair.source); | 756 return new ContextSourcePair(mockContext, pair.source); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 } | 801 } |
| 782 '''); | 802 '''); |
| 783 await waitForTasksFinished(); | 803 await waitForTasksFinished(); |
| 784 Request request = | 804 Request request = |
| 785 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 805 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 786 Response response = handler.handleRequest(request); | 806 Response response = handler.handleRequest(request); |
| 787 expect(response.error, isNotNull); | 807 expect(response.error, isNotNull); |
| 788 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 808 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 789 } | 809 } |
| 790 } | 810 } |
| OLD | NEW |