Skip to content

Commit 07ae3d6

Browse files
bwilkersonCommit Queue
authored andcommitted
[cq] Remove the last uses of a comment-based cursor position
Change-Id: Ie5e9c81a6e35cd5da411620dacdbea5429ca454c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414460 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 727fc8f commit 07ae3d6

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

pkg/analysis_server/doc/implementation/quick_assist.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ The test can then be written in a method that looks something like this:
173173
```dart
174174
Future<void> test_positive() async {
175175
await resolveTestCode('''
176-
var c = /*caret*/42;
176+
var c = ^42;
177177
''');
178178
await assertHasAssist('''
179179
var c = 0x2a;
180180
''');
181181
}
182182
```
183183

184-
The test framework will look for the marker `/*caret*/`, remember it's offset,
184+
The test framework will look for the marker `^`, remember it's offset,
185185
create a file containing the first piece of code with the marker removed, run
186186
the assist over the code, use our correction producer to build an edit, apply
187187
the edit to the file, and textually compare the results with the second piece of

pkg/analysis_server/test/edit/statement_completion_test.dart

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/protocol/protocol_generated.dart';
6+
import 'package:analyzer/src/test_utilities/test_code_format.dart';
67
import 'package:analyzer_plugin/protocol/protocol_common.dart';
78
import 'package:test/test.dart';
89
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -62,7 +63,7 @@ void f() {
6263
_assertHasChange('Insert a newline at the end of the current line', '''
6364
void f() {
6465
int v = 1;
65-
/*caret*/
66+
^
6667
}
6768
''');
6869
}
@@ -78,7 +79,7 @@ void f() {
7879
_assertHasChange('Insert a newline at the end of the current line', '''
7980
void f() {
8081
int v = 1;
81-
/*caret*/
82+
^
8283
}
8384
''');
8485
}
@@ -92,38 +93,25 @@ void f() {
9293
await waitForTasksFinished();
9394
var match = 'v =';
9495
await _prepareCompletion(match, atEnd: true);
95-
_assertHasChange(
96-
'Insert a newline at the end of the current line',
97-
'''
96+
_assertHasChange('Insert a newline at the end of the current line', '''
9897
void f() {
99-
int v =
98+
int v =^
10099
x
101100
}
102-
''',
103-
(s) => s.indexOf(match) + match.length,
104-
); // Ensure cursor after '='.
101+
''');
105102
}
106103

107-
void _assertHasChange(
108-
String message,
109-
String expectedCode, [
110-
int Function(String)? cmp,
111-
]) {
104+
void _assertHasChange(String message, String expectedCode) {
112105
if (change.message == message) {
113106
if (change.edits.isNotEmpty) {
114107
var resultCode = SourceEdit.applySequence(
115108
testFileContent,
116109
change.edits[0].edits,
117110
);
118-
expect(resultCode, expectedCode.replaceAll('/*caret*/', ''));
119-
if (cmp != null) {
120-
var offset = cmp(resultCode);
121-
expect(change.selection!.offset, offset);
122-
}
123-
} else {
124-
if (cmp != null) {
125-
var offset = cmp(testFileContent);
126-
expect(change.selection!.offset, offset);
111+
var parsedExpected = TestCode.parse(expectedCode);
112+
expect(resultCode, parsedExpected.code);
113+
if (parsedExpected.positions.isNotEmpty) {
114+
expect(change.selection!.offset, parsedExpected.position.offset);
127115
}
128116
}
129117
return;

0 commit comments

Comments
 (0)