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

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

Issue 1113063005: improve import suggestion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/domain_completion_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.services.completion.dart.keyword; 5 library test.services.completion.dart.keyword;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart '; 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 Keyword.TRUE, 172 Keyword.TRUE,
173 ]; 173 ];
174 174
175 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, 175 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords,
176 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS, 176 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS,
177 int relevance: DART_RELEVANCE_KEYWORD}) { 177 int relevance: DART_RELEVANCE_KEYWORD}) {
178 Set<String> expectedCompletions = new Set<String>(); 178 Set<String> expectedCompletions = new Set<String>();
179 Set<String> actualCompletions = new Set<String>(); 179 Set<String> actualCompletions = new Set<String>();
180 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax)); 180 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax));
181 expectedCompletions.addAll(pseudoKeywords); 181 expectedCompletions.addAll(pseudoKeywords);
182 if (expectedCompletions.contains(Keyword.IMPORT.syntax)) {
183 expectedCompletions.remove(Keyword.IMPORT.syntax);
184 expectedCompletions.add("import '';");
185 expectedCompletions.add("import '' as ;");
186 expectedCompletions.add("import '' hide ;");
187 expectedCompletions.add("import '' show ;");
188 }
182 for (CompletionSuggestion s in request.suggestions) { 189 for (CompletionSuggestion s in request.suggestions) {
183 if (s.kind == CompletionSuggestionKind.KEYWORD) { 190 if (s.kind == CompletionSuggestionKind.KEYWORD) {
184 Keyword k = Keyword.keywords[s.completion]; 191 Keyword k = Keyword.keywords[s.completion];
185 if (k == null && !pseudoKeywords.contains(s.completion)) { 192 if (k == null && !expectedCompletions.contains(s.completion)) {
186 fail('Invalid keyword suggested: ${s.completion}'); 193 fail('Invalid keyword suggested: ${s.completion}');
187 } else { 194 } else {
188 if (!actualCompletions.add(s.completion)) { 195 if (!actualCompletions.add(s.completion)) {
189 fail('Duplicate keyword suggested: ${s.completion}'); 196 fail('Duplicate keyword suggested: ${s.completion}');
190 } 197 }
191 } 198 }
192 } 199 }
193 } 200 }
194 if (!_equalSets(expectedCompletions, actualCompletions)) { 201 if (!_equalSets(expectedCompletions, actualCompletions)) {
195 StringBuffer msg = new StringBuffer(); 202 StringBuffer msg = new StringBuffer();
196 msg.writeln('Expected:'); 203 msg.writeln('Expected:');
197 _appendCompletions(msg, expectedCompletions, actualCompletions); 204 _appendCompletions(msg, expectedCompletions, actualCompletions);
198 msg.writeln('but found:'); 205 msg.writeln('but found:');
199 _appendCompletions(msg, actualCompletions, expectedCompletions); 206 _appendCompletions(msg, actualCompletions, expectedCompletions);
200 fail(msg.toString()); 207 fail(msg.toString());
201 } 208 }
202 for (CompletionSuggestion s in request.suggestions) { 209 for (CompletionSuggestion s in request.suggestions) {
203 if (s.kind == CompletionSuggestionKind.KEYWORD) { 210 if (s.kind == CompletionSuggestionKind.KEYWORD) {
204 expect(s.relevance, equals(relevance), reason: s.completion); 211 if (s.completion.startsWith(Keyword.IMPORT.syntax)) {
205 expect(s.selectionOffset, equals(s.completion.length)); 212 int importRelevance = relevance;
213 if (importRelevance == DART_RELEVANCE_HIGH &&
214 s.completion == "import '';") {
215 ++importRelevance;
216 }
217 expect(s.relevance, equals(importRelevance), reason: s.completion);
218 expect(s.selectionOffset, equals(Keyword.IMPORT.syntax.length + 2));
219 } else {
220 expect(s.relevance, equals(relevance), reason: s.completion);
221 expect(s.selectionOffset, equals(s.completion.length));
222 }
206 expect(s.selectionLength, equals(0)); 223 expect(s.selectionLength, equals(0));
207 expect(s.isDeprecated, equals(false)); 224 expect(s.isDeprecated, equals(false));
208 expect(s.isPotential, equals(false)); 225 expect(s.isPotential, equals(false));
209 } 226 }
210 } 227 }
211 } 228 }
212 229
213 @override 230 @override
214 void setUpContributor() { 231 void setUpContributor() {
215 contributor = new KeywordContributor(); 232 contributor = new KeywordContributor();
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); 985 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}'));
969 } 986 }
970 987
971 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { 988 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) {
972 if (iter1.length != iter2.length) return false; 989 if (iter1.length != iter2.length) return false;
973 if (iter1.any((c) => !iter2.contains(c))) return false; 990 if (iter1.any((c) => !iter2.contains(c))) return false;
974 if (iter2.any((c) => !iter1.contains(c))) return false; 991 if (iter2.any((c) => !iter1.contains(c))) return false;
975 return true; 992 return true;
976 } 993 }
977 } 994 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_completion_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698