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

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

Issue 1267203002: add location to suggestions from local file (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 library test.services.completion.util; 5 library test.services.completion.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/protocol.dart' as protocol 10 import 'package:analysis_server/src/protocol.dart' as protocol
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (suggestion != null) { 108 if (suggestion != null) {
109 failedCompletion('did not expect completion: $completion\n $suggestion'); 109 failedCompletion('did not expect completion: $completion\n $suggestion');
110 } 110 }
111 return null; 111 return null;
112 } 112 }
113 113
114 CompletionSuggestion assertSuggest(String completion, 114 CompletionSuggestion assertSuggest(String completion,
115 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, 115 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION,
116 int relevance: DART_RELEVANCE_DEFAULT, String importUri, 116 int relevance: DART_RELEVANCE_DEFAULT, String importUri,
117 protocol.ElementKind elemKind: null, bool isDeprecated: false, 117 protocol.ElementKind elemKind: null, bool isDeprecated: false,
118 bool isPotential: false}) { 118 bool isPotential: false, String elemFile, int elemOffset}) {
119 CompletionSuggestion cs = 119 CompletionSuggestion cs =
120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); 120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind);
121 if (cs == null) { 121 if (cs == null) {
122 failedCompletion( 122 failedCompletion(
123 'expected $completion $csKind $elemKind', request.suggestions); 123 'expected $completion $csKind $elemKind', request.suggestions);
124 } 124 }
125 expect(cs.kind, equals(csKind)); 125 expect(cs.kind, equals(csKind));
126 if (isDeprecated) { 126 if (isDeprecated) {
127 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); 127 expect(cs.relevance, equals(DART_RELEVANCE_LOW));
128 } else { 128 } else {
129 expect(cs.relevance, equals(relevance)); 129 expect(cs.relevance, equals(relevance));
130 } 130 }
131 expect(cs.importUri, importUri); 131 expect(cs.importUri, importUri);
132 expect(cs.selectionOffset, equals(completion.length)); 132 expect(cs.selectionOffset, equals(completion.length));
133 expect(cs.selectionLength, equals(0)); 133 expect(cs.selectionLength, equals(0));
134 expect(cs.isDeprecated, equals(isDeprecated)); 134 expect(cs.isDeprecated, equals(isDeprecated));
135 expect(cs.isPotential, equals(isPotential)); 135 expect(cs.isPotential, equals(isPotential));
136 if (cs.element != null) {
137 expect(cs.element.location, isNotNull);
138 expect(cs.element.location.file, isNotNull);
139 expect(cs.element.location.offset, isNotNull);
140 expect(cs.element.location.length, isNotNull);
141 expect(cs.element.location.startColumn, isNotNull);
142 expect(cs.element.location.startLine, isNotNull);
143 }
144 if (elemFile != null) {
145 expect(cs.element.location.file, elemFile);
146 }
147 if (elemOffset != null) {
148 expect(cs.element.location.offset, elemOffset);
149 }
136 return cs; 150 return cs;
137 } 151 }
138 152
139 CompletionSuggestion assertSuggestClass(String name, 153 CompletionSuggestion assertSuggestClass(String name,
140 {int relevance: DART_RELEVANCE_DEFAULT, String importUri, 154 {int relevance: DART_RELEVANCE_DEFAULT, String importUri,
141 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 155 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
142 bool isDeprecated: false}) { 156 bool isDeprecated: false, String elemFile, int elemOffset}) {
143 CompletionSuggestion cs = assertSuggest(name, 157 CompletionSuggestion cs = assertSuggest(name,
144 csKind: kind, 158 csKind: kind,
145 relevance: relevance, 159 relevance: relevance,
146 importUri: importUri, 160 importUri: importUri,
147 isDeprecated: isDeprecated); 161 isDeprecated: isDeprecated,
162 elemFile: elemFile,
163 elemOffset: elemOffset);
148 protocol.Element element = cs.element; 164 protocol.Element element = cs.element;
149 expect(element, isNotNull); 165 expect(element, isNotNull);
150 expect(element.kind, equals(protocol.ElementKind.CLASS)); 166 expect(element.kind, equals(protocol.ElementKind.CLASS));
151 expect(element.name, equals(name)); 167 expect(element.name, equals(name));
152 expect(element.parameters, isNull); 168 expect(element.parameters, isNull);
153 expect(element.returnType, isNull); 169 expect(element.returnType, isNull);
154 assertHasNoParameterInfo(cs); 170 assertHasNoParameterInfo(cs);
155 return cs; 171 return cs;
156 } 172 }
157 173
158 CompletionSuggestion assertSuggestClassTypeAlias(String name, 174 CompletionSuggestion assertSuggestClassTypeAlias(String name,
159 [int relevance = DART_RELEVANCE_DEFAULT, 175 [int relevance = DART_RELEVANCE_DEFAULT,
160 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { 176 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
161 CompletionSuggestion cs = 177 CompletionSuggestion cs =
162 assertSuggest(name, csKind: kind, relevance: relevance); 178 assertSuggest(name, csKind: kind, relevance: relevance);
163 protocol.Element element = cs.element; 179 protocol.Element element = cs.element;
164 expect(element, isNotNull); 180 expect(element, isNotNull);
165 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); 181 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS));
166 expect(element.name, equals(name)); 182 expect(element.name, equals(name));
167 expect(element.parameters, isNull); 183 expect(element.parameters, isNull);
168 expect(element.returnType, isNull); 184 expect(element.returnType, isNull);
169 assertHasNoParameterInfo(cs); 185 assertHasNoParameterInfo(cs);
170 return cs; 186 return cs;
171 } 187 }
172 188
173 CompletionSuggestion assertSuggestConstructor(String name, 189 CompletionSuggestion assertSuggestConstructor(String name,
174 {int relevance: DART_RELEVANCE_DEFAULT, String importUri}) { 190 {int relevance: DART_RELEVANCE_DEFAULT, String importUri,
175 CompletionSuggestion cs = 191 int elemOffset}) {
176 assertSuggest(name, relevance: relevance, importUri: importUri); 192 CompletionSuggestion cs = assertSuggest(name,
193 relevance: relevance, importUri: importUri, elemOffset: elemOffset);
177 protocol.Element element = cs.element; 194 protocol.Element element = cs.element;
178 expect(element, isNotNull); 195 expect(element, isNotNull);
179 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); 196 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR));
180 int index = name.indexOf('.'); 197 int index = name.indexOf('.');
181 expect(element.name, index >= 0 ? name.substring(index + 1) : ''); 198 expect(element.name, index >= 0 ? name.substring(index + 1) : '');
182 return cs; 199 return cs;
183 } 200 }
184 201
185 CompletionSuggestion assertSuggestField(String name, String type, 202 CompletionSuggestion assertSuggestField(String name, String type,
186 {int relevance: DART_RELEVANCE_DEFAULT, String importUri, 203 {int relevance: DART_RELEVANCE_DEFAULT, String importUri,
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 {bool isDeprecated: false}) { 583 {bool isDeprecated: false}) {
567 CompletionSuggestion suggestion = 584 CompletionSuggestion suggestion =
568 assertSuggest(completion, isDeprecated: isDeprecated); 585 assertSuggest(completion, isDeprecated: isDeprecated);
569 expect(suggestion.isDeprecated, isDeprecated); 586 expect(suggestion.isDeprecated, isDeprecated);
570 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT); 587 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT);
571 return suggestion; 588 return suggestion;
572 } 589 }
573 590
574 CompletionSuggestion assertSuggestImportedClass(String name, 591 CompletionSuggestion assertSuggestImportedClass(String name,
575 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 592 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
576 int relevance: DART_RELEVANCE_DEFAULT, String importUri}) { 593 int relevance: DART_RELEVANCE_DEFAULT, String importUri,
594 String elemFile}) {
577 return assertNotSuggested(name); 595 return assertNotSuggested(name);
578 } 596 }
579 597
580 CompletionSuggestion assertSuggestImportedConstructor(String name, 598 CompletionSuggestion assertSuggestImportedConstructor(String name,
581 {int relevance: DART_RELEVANCE_DEFAULT, String importUri}) { 599 {int relevance: DART_RELEVANCE_DEFAULT, String importUri}) {
582 return assertNotSuggested(name); 600 return assertNotSuggested(name);
583 } 601 }
584 602
585 CompletionSuggestion assertSuggestImportedField(String name, String type, 603 CompletionSuggestion assertSuggestImportedField(String name, String type,
586 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) { 604 {int relevance: DART_RELEVANCE_INHERITED_FIELD}) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 [int relevance = DART_RELEVANCE_DEFAULT]) { 694 [int relevance = DART_RELEVANCE_DEFAULT]) {
677 if (contributor is PrefixedElementContributor) { 695 if (contributor is PrefixedElementContributor) {
678 return assertSuggestTopLevelVar(name, returnType, relevance); 696 return assertSuggestTopLevelVar(name, returnType, relevance);
679 } else { 697 } else {
680 return assertNotSuggested(name); 698 return assertNotSuggested(name);
681 } 699 }
682 } 700 }
683 701
684 CompletionSuggestion assertSuggestLocalClass(String name, 702 CompletionSuggestion assertSuggestLocalClass(String name,
685 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 703 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
686 int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { 704 int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false,
705 String elemFile, int elemOffset}) {
687 return assertNotSuggested(name); 706 return assertNotSuggested(name);
688 } 707 }
689 708
690 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, 709 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name,
691 {int relevance: DART_RELEVANCE_DEFAULT}) { 710 {int relevance: DART_RELEVANCE_DEFAULT}) {
692 return assertNotSuggested(name); 711 return assertNotSuggested(name);
693 } 712 }
694 713
695 CompletionSuggestion assertSuggestLocalConstructor(String name) { 714 CompletionSuggestion assertSuggestLocalConstructor(String name,
715 {int elemOffset}) {
696 return assertNotSuggested(name); 716 return assertNotSuggested(name);
697 } 717 }
698 718
699 CompletionSuggestion assertSuggestLocalField(String name, String type, 719 CompletionSuggestion assertSuggestLocalField(String name, String type,
700 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { 720 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) {
701 return assertNotSuggested(name); 721 return assertNotSuggested(name);
702 } 722 }
703 723
704 CompletionSuggestion assertSuggestLocalFunction( 724 CompletionSuggestion assertSuggestLocalFunction(
705 String name, String returnType, {bool deprecated: false, 725 String name, String returnType, {bool deprecated: false,
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 {var x;} 1262 {var x;}
1243 ^ var r; 1263 ^ var r;
1244 } 1264 }
1245 void b() { }} 1265 void b() { }}
1246 class Z { }'''); 1266 class Z { }''');
1247 computeFast(); 1267 computeFast();
1248 return computeFull((bool result) { 1268 return computeFull((bool result) {
1249 expect(request.replacementOffset, completionOffset); 1269 expect(request.replacementOffset, completionOffset);
1250 expect(request.replacementLength, 0); 1270 expect(request.replacementLength, 0);
1251 1271
1252 assertSuggestLocalClass('X'); 1272 assertSuggestLocalClass('X', elemFile: testFile);
1253 assertSuggestLocalClass('Z'); 1273 assertSuggestLocalClass('Z');
1254 assertSuggestLocalMethod('a', 'X', null); 1274 assertSuggestLocalMethod('a', 'X', null);
1255 assertSuggestLocalMethod('b', 'X', 'void'); 1275 assertSuggestLocalMethod('b', 'X', 'void');
1256 assertSuggestLocalFunction('localF', null); 1276 assertSuggestLocalFunction('localF', null);
1257 assertSuggestLocalVariable('f', null); 1277 assertSuggestLocalVariable('f', null);
1258 // Don't suggest locals out of scope 1278 // Don't suggest locals out of scope
1259 assertNotSuggested('r'); 1279 assertNotSuggested('r');
1260 assertNotSuggested('x'); 1280 assertNotSuggested('x');
1261 assertNotSuggested('partT8'); 1281 assertNotSuggested('partT8');
1262 1282
1263 assertSuggestImportedClass('A'); 1283 assertSuggestImportedClass('A', elemFile: '/testAB.dart');
1264 assertNotSuggested('_B'); 1284 assertNotSuggested('_B');
1265 assertSuggestImportedClass('C'); 1285 assertSuggestImportedClass('C');
1266 assertNotSuggested('partBoo'); 1286 assertNotSuggested('partBoo');
1267 // hidden element suggested as low relevance 1287 // hidden element suggested as low relevance
1268 // but imported results are partially filtered 1288 // but imported results are partially filtered
1269 //assertSuggestImportedClass('D', COMPLETION_RELEVANCE_LOW); 1289 //assertSuggestImportedClass('D', COMPLETION_RELEVANCE_LOW);
1270 //assertSuggestImportedFunction( 1290 //assertSuggestImportedFunction(
1271 // 'D1', null, true, COMPLETION_RELEVANCE_LOW); 1291 // 'D1', null, true, COMPLETION_RELEVANCE_LOW);
1272 assertSuggestLocalFunction('D2', 'Z'); 1292 assertSuggestLocalFunction('D2', 'Z');
1273 assertSuggestImportedClass('EE'); 1293 assertSuggestImportedClass('EE');
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 }); 1958 });
1939 } 1959 }
1940 1960
1941 test_CatchClause_onType_noBrackets() { 1961 test_CatchClause_onType_noBrackets() {
1942 // TypeName CatchClause TryStatement 1962 // TypeName CatchClause TryStatement
1943 addTestSource('class A {a() {try{var x;} on ^}}'); 1963 addTestSource('class A {a() {try{var x;} on ^}}');
1944 computeFast(); 1964 computeFast();
1945 return computeFull((bool result) { 1965 return computeFull((bool result) {
1946 expect(request.replacementOffset, completionOffset); 1966 expect(request.replacementOffset, completionOffset);
1947 expect(request.replacementLength, 0); 1967 expect(request.replacementLength, 0);
1948 assertSuggestLocalClass('A'); 1968 assertSuggestLocalClass('A', elemOffset: 6);
1949 assertSuggestImportedClass('Object'); 1969 assertSuggestImportedClass('Object');
1950 assertNotSuggested('x'); 1970 assertNotSuggested('x');
1951 }); 1971 });
1952 } 1972 }
1953 1973
1954 test_CatchClause_typed() { 1974 test_CatchClause_typed() {
1955 // Block CatchClause TryStatement 1975 // Block CatchClause TryStatement
1956 addTestSource('class A {a() {try{var x;} on E catch (e) {^}}}'); 1976 addTestSource('class A {a() {try{var x;} on E catch (e) {^}}}');
1957 computeFast(); 1977 computeFast();
1958 return computeFull((bool result) { 1978 return computeFull((bool result) {
(...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after
4394 assertNotSuggested('bar2'); 4414 assertNotSuggested('bar2');
4395 assertNotSuggested('_B'); 4415 assertNotSuggested('_B');
4396 assertSuggestLocalClass('Y'); 4416 assertSuggestLocalClass('Y');
4397 assertSuggestLocalClass('C'); 4417 assertSuggestLocalClass('C');
4398 assertSuggestLocalVariable('f', null); 4418 assertSuggestLocalVariable('f', null);
4399 assertNotSuggested('x'); 4419 assertNotSuggested('x');
4400 assertNotSuggested('e'); 4420 assertNotSuggested('e');
4401 }); 4421 });
4402 } 4422 }
4403 } 4423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698