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

Side by Side Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 2478963002: Completion with the new analysis driver. (Closed)
Patch Set: Fixes for review comments. Created 4 years, 1 month 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 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/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/domain_completion.dart'; 10 import 'package:analysis_server/src/domain_completion.dart';
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 assertNoResult('test'); 116 assertNoResult('test');
117 }); 117 });
118 } 118 }
119 119
120 test_imports_aborted_new_request() async { 120 test_imports_aborted_new_request() async {
121 addTestFile(''' 121 addTestFile('''
122 class foo { } 122 class foo { }
123 c^'''); 123 c^''');
124 124
125 // Make a request for suggestions 125 // Make a request for suggestions
126 Request request = 126 Request request1 =
127 new CompletionGetSuggestionsParams(testFile, completionOffset) 127 new CompletionGetSuggestionsParams(testFile, completionOffset)
128 .toRequest('7'); 128 .toRequest('7');
129 Response response = handleSuccessfulRequest(request); 129 Response response1 = await waitResponse(request1);
130 var result1 = new CompletionGetSuggestionsResult.fromResponse(response); 130 var result1 = new CompletionGetSuggestionsResult.fromResponse(response1);
131 var completionId1 = result1.id; 131 var completionId1 = result1.id;
132 assertValidId(response.id); 132 assertValidId(completionId1);
133 133
134 // Perform some analysis but assert that no suggestions have yet been made 134 // Perform some analysis but assert that no suggestions have yet been made
135 completionId = completionId1; 135 completionId = completionId1;
136 await pumpEventQueue(25); 136 await pumpEventQueue(25);
137 expect(suggestionsDone, isFalse); 137 expect(suggestionsDone, isFalse);
138 expect(suggestions, hasLength(0)); 138 expect(suggestions, hasLength(0));
139 139
140 // Make another request before the first request completes 140 // Make another request before the first request completes
141 Request request2 = 141 Request request2 =
142 new CompletionGetSuggestionsParams(testFile, completionOffset) 142 new CompletionGetSuggestionsParams(testFile, completionOffset)
143 .toRequest('8'); 143 .toRequest('8');
144 Response response2 = handleSuccessfulRequest(request2); 144 Response response2 = await waitResponse(request2);
145 var result2 = new CompletionGetSuggestionsResult.fromResponse(response2); 145 var result2 = new CompletionGetSuggestionsResult.fromResponse(response2);
146 var completionId2 = result2.id; 146 var completionId2 = result2.id;
147 assertValidId(completionId2); 147 assertValidId(completionId2);
148 148
149 // Wait for both sets of suggestions 149 // Wait for both sets of suggestions
150 completionId = completionId2; 150 completionId = completionId2;
151 await pumpEventQueue(); 151 await pumpEventQueue();
152 expect(allSuggestions[completionId1], hasLength(0)); 152 expect(allSuggestions[completionId1], hasLength(0));
153 expect(allSuggestions[completionId2], same(suggestions)); 153 expect(allSuggestions[completionId2], same(suggestions));
154 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class', 154 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class',
155 relevance: DART_RELEVANCE_HIGH); 155 relevance: DART_RELEVANCE_HIGH);
156 } 156 }
157 157
158 test_imports_aborted_source_changed() async { 158 test_imports_aborted_source_changed() async {
159 addTestFile(''' 159 addTestFile('''
160 class foo { } 160 class foo { }
161 c^'''); 161 c^''');
162 162
163 // Make a request for suggestions 163 // Make a request for suggestions
164 Request request = 164 Request request =
165 new CompletionGetSuggestionsParams(testFile, completionOffset) 165 new CompletionGetSuggestionsParams(testFile, completionOffset)
166 .toRequest('0'); 166 .toRequest('0');
167 Response response = handleSuccessfulRequest(request); 167 Response response = await waitResponse(request);
168 completionId = response.id; 168 completionId = response.id;
169 assertValidId(completionId); 169 assertValidId(completionId);
170 170
171 // Perform some analysis but assert that no suggestions have yet been made 171 // Perform some analysis but assert that no suggestions have yet been made
172 await pumpEventQueue(25); 172 await pumpEventQueue(25);
173 expect(suggestionsDone, isFalse); 173 expect(suggestionsDone, isFalse);
174 expect(suggestions, hasLength(0)); 174 expect(suggestions, hasLength(0));
175 175
176 // Simulate user deleting text after request but before suggestions returned 176 // Simulate user deleting text after request but before suggestions returned
177 server.updateContent('uc1', {testFile: new AddContentOverlay(testCode)}); 177 server.updateContent('uc1', {testFile: new AddContentOverlay(testCode)});
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // Wait for analysis then edit the content 220 // Wait for analysis then edit the content
221 await waitForTasksFinished(); 221 await waitForTasksFinished();
222 String revisedContent = testCode.substring(0, completionOffset) + 222 String revisedContent = testCode.substring(0, completionOffset) +
223 'i' + 223 'i' +
224 testCode.substring(completionOffset); 224 testCode.substring(completionOffset);
225 ++completionOffset; 225 ++completionOffset;
226 server.handleRequest(new AnalysisUpdateContentParams( 226 server.handleRequest(new AnalysisUpdateContentParams(
227 {testFile: new AddContentOverlay(revisedContent)}).toRequest('add1')); 227 {testFile: new AddContentOverlay(revisedContent)}).toRequest('add1'));
228 228
229 // Request code completion immediately after edit 229 // Request code completion immediately after edit
230 Response response = handleSuccessfulRequest( 230 Response response = await waitResponse(
231 new CompletionGetSuggestionsParams(testFile, completionOffset) 231 new CompletionGetSuggestionsParams(testFile, completionOffset)
232 .toRequest('0')); 232 .toRequest('0'));
233 completionId = response.id; 233 completionId = response.id;
234 assertValidId(completionId); 234 assertValidId(completionId);
235 await waitForTasksFinished(); 235 await waitForTasksFinished();
236 expect(replacementOffset, completionOffset - 1); 236 expect(replacementOffset, completionOffset - 1);
237 expect(replacementLength, 1); 237 expect(replacementLength, 1);
238 assertHasResult(CompletionSuggestionKind.KEYWORD, 'library', 238 assertHasResult(CompletionSuggestionKind.KEYWORD, 'library',
239 relevance: DART_RELEVANCE_HIGH); 239 relevance: DART_RELEVANCE_HIGH);
240 assertHasResult(CompletionSuggestionKind.KEYWORD, 'import \'\';', 240 assertHasResult(CompletionSuggestionKind.KEYWORD, 'import \'\';',
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 assertHasResult(CompletionSuggestionKind.INVOCATION, 'a', 459 assertHasResult(CompletionSuggestionKind.INVOCATION, 'a',
460 relevance: DART_RELEVANCE_LOCAL_FIELD); 460 relevance: DART_RELEVANCE_LOCAL_FIELD);
461 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b', 461 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b',
462 relevance: DART_RELEVANCE_LOCAL_VARIABLE); 462 relevance: DART_RELEVANCE_LOCAL_VARIABLE);
463 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x', 463 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x',
464 relevance: DART_RELEVANCE_LOCAL_METHOD); 464 relevance: DART_RELEVANCE_LOCAL_METHOD);
465 assertHasResult(CompletionSuggestionKind.INVOCATION, 'DateTime'); 465 assertHasResult(CompletionSuggestionKind.INVOCATION, 'DateTime');
466 }); 466 });
467 } 467 }
468 468
469 test_offset_past_eof() { 469 test_offset_past_eof() async {
470 addTestFile('main() { }', offset: 300); 470 addTestFile('main() { }', offset: 300);
471 Request request = 471 Request request =
472 new CompletionGetSuggestionsParams(testFile, completionOffset) 472 new CompletionGetSuggestionsParams(testFile, completionOffset)
473 .toRequest('0'); 473 .toRequest('0');
474 Response response = handler.handleRequest(request); 474 Response response = await waitResponse(request);
475 expect(response.id, '0'); 475 expect(response.id, '0');
476 expect(response.error.code, RequestErrorCode.INVALID_PARAMETER); 476 expect(response.error.code, RequestErrorCode.INVALID_PARAMETER);
477 } 477 }
478 478
479 test_overrides() { 479 test_overrides() {
480 addFile('/libA.dart', 'class A {m() {}}'); 480 addFile('/libA.dart', 'class A {m() {}}');
481 addTestFile(''' 481 addTestFile('''
482 import '/libA.dart'; 482 import '/libA.dart';
483 class B extends A {m() {^}} 483 class B extends A {m() {^}}
484 '''); 484 ''');
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 606 }
607 '''); 607 ''');
608 await waitForTasksFinished(); 608 await waitForTasksFinished();
609 Request request = 609 Request request =
610 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); 610 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0');
611 Response response = handler.handleRequest(request); 611 Response response = handler.handleRequest(request);
612 expect(response.error, isNotNull); 612 expect(response.error, isNotNull);
613 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); 613 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED);
614 } 614 }
615 } 615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698