Skip to content

Commit a6f6bed

Browse files
DanTupCommit Queue
authored andcommitted
[anaysis_server] Switch completion tests from element offsets to line numbers
The element offsets here are used only to differentiate elements (to check for correct shadowing) so exact positions are not necessary and line numbers will do. This removes offsets that would change if the tests are run with different line endings based on the current platform. Only one test had two elements on the same line, so I've wrapped the code to keep the test valid. See #60234 Change-Id: I64fc4b28c34873429f554861e530630b3aedc26b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453500 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 05f2c44 commit a6f6bed

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
lines changed

pkg/analysis_server/test/services/completion/dart/completion_printer.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,12 @@ class CompletionResponsePrinter {
261261
}
262262
}
263263

264-
void _writeElementOffset(CompletionSuggestion suggestion) {
265-
if (configuration.withElementOffset) {
264+
void _writeElementLocation(CompletionSuggestion suggestion) {
265+
if (configuration.withElementLocation) {
266266
var element = suggestion.element;
267267
if (element != null) {
268-
_writelnWithIndent('offset: ${element.location?.offset}');
268+
_writelnWithIndent('line: ${element.location?.startLine}');
269+
_writelnWithIndent('column: ${element.location?.startColumn}');
269270
}
270271
}
271272
}
@@ -355,7 +356,7 @@ class CompletionResponsePrinter {
355356
_writeCompletion(suggestion);
356357
_withIndent(() {
357358
_writeSuggestionKind(suggestion);
358-
_writeElementOffset(suggestion);
359+
_writeElementLocation(suggestion);
359360
_writeDeclaringType(suggestion);
360361
_writeDeprecated(suggestion);
361362
_writeDefaultArgumentList(suggestion);
@@ -400,7 +401,7 @@ class Configuration {
400401
bool withDisplayText;
401402
bool withDocumentation;
402403
bool withElement;
403-
bool withElementOffset;
404+
bool withElementLocation;
404405
bool withIsNotImported;
405406
bool withKind;
406407
bool withLibraryUri;
@@ -419,7 +420,7 @@ class Configuration {
419420
this.withDisplayText = false,
420421
this.withDocumentation = false,
421422
this.withElement = false,
422-
this.withElementOffset = false,
423+
this.withElementLocation = false,
423424
this.withIsNotImported = false,
424425
this.withKind = true,
425426
this.withLibraryUri = false,

pkg/analysis_server/test/services/completion/dart/shadowing_test.dart

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mixin ShadowingTestCases on AbstractCompletionDriverTest {
3737
@override
3838
Future<void> setUp() async {
3939
await super.setUp();
40-
printerConfiguration.withElementOffset = true;
40+
printerConfiguration.withElementLocation = true;
4141
}
4242

4343
Future<void> test_field_class() async {
@@ -55,7 +55,8 @@ class f0 {}
5555
suggestions
5656
f0
5757
kind: field
58-
offset: 19
58+
line: 2
59+
column: 10
5960
''');
6061
}
6162

@@ -74,7 +75,8 @@ class C {
7475
suggestions
7576
f0
7677
kind: field
77-
offset: 39
78+
line: 4
79+
column: 10
7880
''');
7981
}
8082

@@ -93,7 +95,8 @@ class C {
9395
suggestions
9496
f0
9597
kind: field
96-
offset: 36
98+
line: 4
99+
column: 10
97100
''');
98101
}
99102

@@ -111,7 +114,8 @@ void f() {
111114
suggestions
112115
f0
113116
kind: functionInvocation
114-
offset: 49
117+
line: 4
118+
column: 10
115119
''');
116120
}
117121

@@ -129,7 +133,8 @@ void f() {
129133
suggestions
130134
v0
131135
kind: functionInvocation
132-
offset: 48
136+
line: 4
137+
column: 10
133138
''');
134139
}
135140

@@ -144,7 +149,8 @@ void f(int v0) {
144149
suggestions
145150
v0
146151
kind: functionInvocation
147-
offset: 24
152+
line: 2
153+
column: 8
148154
''');
149155
}
150156

@@ -162,7 +168,8 @@ void f() {
162168
suggestions
163169
v0
164170
kind: localVariable
165-
offset: 48
171+
line: 4
172+
column: 9
166173
''');
167174
}
168175

@@ -180,7 +187,8 @@ void f() {
180187
suggestions
181188
v0
182189
kind: localVariable
183-
offset: 47
190+
line: 4
191+
column: 9
184192
''');
185193
}
186194

@@ -195,7 +203,8 @@ void f(int v0) {
195203
suggestions
196204
v0
197205
kind: localVariable
198-
offset: 23
206+
line: 2
207+
column: 7
199208
''');
200209
}
201210

@@ -210,7 +219,8 @@ void f<v0>() {
210219
suggestions
211220
v0
212221
kind: localVariable
213-
offset: 21
222+
line: 2
223+
column: 7
214224
''');
215225
}
216226

@@ -228,7 +238,8 @@ class m0 {}
228238
suggestions
229239
m0
230240
kind: methodInvocation
231-
offset: 17
241+
line: 2
242+
column: 8
232243
''');
233244
}
234245

@@ -246,7 +257,8 @@ class C {
246257
suggestions
247258
m0
248259
kind: methodInvocation
249-
offset: 31
260+
line: 4
261+
column: 8
250262
''');
251263
}
252264

@@ -264,7 +276,8 @@ class C {
264276
suggestions
265277
m0
266278
kind: methodInvocation
267-
offset: 30
279+
line: 4
280+
column: 8
268281
''');
269282
}
270283

@@ -280,7 +293,8 @@ class c0 {
280293
suggestions
281294
c0
282295
kind: parameter
283-
offset: 24
296+
line: 2
297+
column: 14
284298
''');
285299
}
286300

@@ -297,7 +311,8 @@ class C {
297311
suggestions
298312
f0
299313
kind: parameter
300-
offset: 41
314+
line: 3
315+
column: 14
301316
''');
302317
}
303318

@@ -314,7 +329,8 @@ class C {
314329
suggestions
315330
m0
316331
kind: parameter
317-
offset: 44
332+
line: 3
333+
column: 14
318334
''');
319335
}
320336

@@ -329,7 +345,8 @@ void f(int f0) {
329345
suggestions
330346
f0
331347
kind: parameter
332-
offset: 30
348+
line: 2
349+
column: 12
333350
''');
334351
}
335352

@@ -344,7 +361,8 @@ void f(int f0) {
344361
suggestions
345362
f0
346363
kind: parameter
347-
offset: 27
364+
line: 2
365+
column: 12
348366
''');
349367
}
350368

@@ -358,7 +376,8 @@ void f<p0>(int p0) {
358376
suggestions
359377
p0
360378
kind: parameter
361-
offset: 15
379+
line: 1
380+
column: 16
362381
''');
363382
}
364383

@@ -375,7 +394,8 @@ void f() {
375394
suggestions
376395
v0
377396
kind: typeParameter
378-
offset: 34
397+
line: 3
398+
column: 10
379399
''');
380400
}
381401

@@ -391,7 +411,8 @@ void f(int p0) {
391411
suggestions
392412
p0
393413
kind: typeParameter
394-
offset: 26
414+
line: 2
415+
column: 10
395416
''');
396417
}
397418

@@ -407,7 +428,8 @@ void f<p0>() {
407428
suggestions
408429
p0
409430
kind: typeParameter
410-
offset: 24
431+
line: 2
432+
column: 10
411433
''');
412434
}
413435
}

0 commit comments

Comments
 (0)