| 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.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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 Keyword.TRUE, | 166 Keyword.TRUE, |
| 167 ]; | 167 ]; |
| 168 | 168 |
| 169 static const List<Keyword> EXPRESSION_START_NO_INSTANCE = const [ | 169 static const List<Keyword> EXPRESSION_START_NO_INSTANCE = const [ |
| 170 Keyword.FALSE, | 170 Keyword.FALSE, |
| 171 Keyword.NEW, | 171 Keyword.NEW, |
| 172 Keyword.NULL, | 172 Keyword.NULL, |
| 173 Keyword.TRUE, | 173 Keyword.TRUE, |
| 174 ]; | 174 ]; |
| 175 | 175 |
| 176 static final Map<String, List<String>> keywordTemplates = | |
| 177 <String, List<String>>{ | |
| 178 Keyword.IMPORT.syntax: [ | |
| 179 "import '^';", | |
| 180 "import '^' as ;", | |
| 181 "import '^' hide ;", | |
| 182 "import '^' show ;" | |
| 183 ], | |
| 184 Keyword.FOR.syntax: ['for (^)'] | |
| 185 }; | |
| 186 | |
| 187 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, | 176 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, |
| 188 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS, | 177 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS, |
| 189 int relevance: DART_RELEVANCE_KEYWORD}) { | 178 int relevance: DART_RELEVANCE_KEYWORD}) { |
| 190 Set<String> expectedCompletions = new Set<String>(); | 179 Set<String> expectedCompletions = new Set<String>(); |
| 191 Map<String, int> expectedOffsets = <String, int>{}; | 180 Map<String, int> expectedOffsets = <String, int>{}; |
| 192 Set<String> actualCompletions = new Set<String>(); | 181 Set<String> actualCompletions = new Set<String>(); |
| 193 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax)); | 182 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax)); |
| 194 expectedCompletions.addAll(pseudoKeywords); | 183 expectedCompletions.addAll(pseudoKeywords); |
| 195 keywordTemplates.forEach((String key, List<String> templates) { | |
| 196 if (expectedCompletions.remove(key)) { | |
| 197 for (String t in templates) { | |
| 198 int offset = t.indexOf('^'); | |
| 199 if (offset != -1) { | |
| 200 t = '${t.substring(0, offset)}${t.substring(offset + 1)}'; | |
| 201 expectedOffsets[t] = offset; | |
| 202 } | |
| 203 expectedCompletions.add(t); | |
| 204 } | |
| 205 } | |
| 206 }); | |
| 207 for (CompletionSuggestion s in request.suggestions) { | 184 for (CompletionSuggestion s in request.suggestions) { |
| 208 if (s.kind == CompletionSuggestionKind.KEYWORD) { | 185 if (s.kind == CompletionSuggestionKind.KEYWORD) { |
| 209 Keyword k = Keyword.keywords[s.completion]; | 186 Keyword k = Keyword.keywords[s.completion]; |
| 210 if (k == null && !expectedCompletions.contains(s.completion)) { | 187 if (k == null && !expectedCompletions.contains(s.completion)) { |
| 211 fail('Invalid keyword suggested: ${s.completion}'); | 188 fail('Invalid keyword suggested: ${s.completion}'); |
| 212 } else { | 189 } else { |
| 213 if (!actualCompletions.add(s.completion)) { | 190 if (!actualCompletions.add(s.completion)) { |
| 214 fail('Duplicate keyword suggested: ${s.completion}'); | 191 fail('Duplicate keyword suggested: ${s.completion}'); |
| 215 } | 192 } |
| 216 } | 193 } |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); | 1168 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); |
| 1192 } | 1169 } |
| 1193 | 1170 |
| 1194 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { | 1171 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { |
| 1195 if (iter1.length != iter2.length) return false; | 1172 if (iter1.length != iter2.length) return false; |
| 1196 if (iter1.any((c) => !iter2.contains(c))) return false; | 1173 if (iter1.any((c) => !iter2.contains(c))) return false; |
| 1197 if (iter2.any((c) => !iter1.contains(c))) return false; | 1174 if (iter2.any((c) => !iter1.contains(c))) return false; |
| 1198 return true; | 1175 return true; |
| 1199 } | 1176 } |
| 1200 } | 1177 } |
| OLD | NEW |