@@ -20,6 +20,7 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
20
20
String content, {
21
21
CodeActionKind ? kind,
22
22
String ? command,
23
+ List <Object >? commandArgs,
23
24
String ? title,
24
25
CodeActionTriggerKind ? triggerKind,
25
26
String ? filePath,
@@ -47,6 +48,7 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
47
48
codeActions,
48
49
kind: kind,
49
50
command: command,
51
+ commandArgs: commandArgs,
50
52
title: title,
51
53
);
52
54
if (action == null ) {
@@ -100,18 +102,23 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
100
102
101
103
/// Finds the single action matching [title] , [kind] and [command] .
102
104
///
105
+ /// If [command] and/or [commandArgs] are supplied, ensures the action has
106
+ /// a matching command/args.
107
+ ///
103
108
/// Throws if zero or more than one actions match.
104
109
CodeAction ? findAction (
105
110
List <Either2 <Command , CodeAction >> actions, {
106
111
String ? title,
107
112
CodeActionKind ? kind,
108
113
String ? command,
114
+ List <Object >? commandArgs,
109
115
}) {
110
116
return findActions (
111
117
actions,
112
118
title: title,
113
119
kind: kind,
114
120
command: command,
121
+ commandArgs: commandArgs,
115
122
).singleOrNull;
116
123
}
117
124
@@ -120,21 +127,38 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
120
127
String ? title,
121
128
CodeActionKind ? kind,
122
129
String ? command,
130
+ List <Object >? commandArgs,
123
131
}) {
124
132
return actions
125
133
.map ((action) => action.map ((cmd) => null , (action) => action))
126
134
.where ((action) => title == null || action? .title == title)
127
135
.where ((action) => kind == null || action? .kind == kind)
136
+ // Some tests filter by only supplying a command, so if there is no
137
+ // title given, filter by the command. If a title was given, don't
138
+ // filter by the command and assert it below. This results in a better
139
+ // failure message if the action existed by title but without the correct
140
+ // command.
128
141
.where (
129
- (action) => command == null || action? .command? .command == command,
142
+ (action) =>
143
+ title != null ||
144
+ command == null ||
145
+ action? .command? .command == command,
130
146
)
131
147
.map ((action) {
132
148
// Always expect a command (either to execute, or for logging)
133
- assert (action! .command != null );
134
- // Expect an edit if we weren't looking for a command-action.
135
- if (command == null ) {
136
- assert (action! .edit != null );
149
+ expect (action! .command, isNotNull);
150
+
151
+ if (command != null ) {
152
+ expect (action.command! .command, command);
153
+ } else {
154
+ // Expect an edit if we weren't looking for a command-action.
155
+ expect (action.edit, isNotNull);
137
156
}
157
+
158
+ if (commandArgs != null ) {
159
+ expect (action.command! .arguments, equals (commandArgs));
160
+ }
161
+
138
162
return action;
139
163
})
140
164
.nonNulls
@@ -183,6 +207,7 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
183
207
String ? filePath,
184
208
CodeActionKind ? kind,
185
209
String ? command,
210
+ List <Object >? commandArgs,
186
211
String ? title,
187
212
ProgressToken ? commandWorkDoneToken,
188
213
bool openTargetFile = false ,
@@ -202,13 +227,16 @@ $expected''';
202
227
content,
203
228
kind: kind,
204
229
command: command,
230
+ commandArgs: commandArgs,
205
231
title: title,
206
232
openTargetFile: openTargetFile,
207
233
);
208
234
209
235
// Verify the edits either by executing the command we expected, or
210
236
// the edits attached directly to the code action.
211
- if (command != null ) {
237
+ // Don't try to execute 'dart.logAction' because it will never produce
238
+ // edits.
239
+ if (command != null && command != 'dart.logAction' ) {
212
240
return await verifyCommandEdits (
213
241
action.command! ,
214
242
expected,
0 commit comments