@@ -57,6 +57,20 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
57
57
response. push ( organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
58
58
}
59
59
60
+ if snapshot. client_settings ( ) . fix_all ( )
61
+ && supported_code_actions. contains ( & SupportedCodeAction :: NotebookSourceFixAll )
62
+ {
63
+ response. push ( notebook_fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
64
+ }
65
+
66
+ if snapshot. client_settings ( ) . organize_imports ( )
67
+ && supported_code_actions. contains ( & SupportedCodeAction :: NotebookSourceOrganizeImports )
68
+ {
69
+ response. push (
70
+ notebook_organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?,
71
+ ) ;
72
+ }
73
+
60
74
Ok ( Some ( response) )
61
75
}
62
76
}
@@ -161,6 +175,42 @@ fn fix_all(snapshot: &DocumentSnapshot) -> crate::Result<CodeActionOrCommand> {
161
175
} ) )
162
176
}
163
177
178
+ fn notebook_fix_all ( snapshot : & DocumentSnapshot ) -> crate :: Result < CodeActionOrCommand > {
179
+ let document = snapshot. query ( ) ;
180
+
181
+ let ( edit, data) = if snapshot
182
+ . resolved_client_capabilities ( )
183
+ . code_action_deferred_edit_resolution
184
+ {
185
+ // The editor will request the edit in a `CodeActionsResolve` request
186
+ (
187
+ None ,
188
+ Some (
189
+ serde_json:: to_value ( snapshot. query ( ) . make_key ( ) . into_url ( ) )
190
+ . expect ( "document url should serialize" ) ,
191
+ ) ,
192
+ )
193
+ } else {
194
+ (
195
+ Some ( resolve_edit_for_fix_all (
196
+ document,
197
+ snapshot. resolved_client_capabilities ( ) ,
198
+ snapshot. query ( ) . settings ( ) . linter ( ) ,
199
+ snapshot. encoding ( ) ,
200
+ ) ?) ,
201
+ None ,
202
+ )
203
+ } ;
204
+
205
+ Ok ( CodeActionOrCommand :: CodeAction ( types:: CodeAction {
206
+ title : format ! ( "{DIAGNOSTIC_NAME}: Fix all auto-fixable problems" ) ,
207
+ kind : Some ( crate :: NOTEBOOK_SOURCE_FIX_ALL_RUFF ) ,
208
+ edit,
209
+ data,
210
+ ..Default :: default ( )
211
+ } ) )
212
+ }
213
+
164
214
fn organize_imports ( snapshot : & DocumentSnapshot ) -> crate :: Result < CodeActionOrCommand > {
165
215
let document = snapshot. query ( ) ;
166
216
@@ -197,6 +247,42 @@ fn organize_imports(snapshot: &DocumentSnapshot) -> crate::Result<CodeActionOrCo
197
247
} ) )
198
248
}
199
249
250
+ fn notebook_organize_imports ( snapshot : & DocumentSnapshot ) -> crate :: Result < CodeActionOrCommand > {
251
+ let document = snapshot. query ( ) ;
252
+
253
+ let ( edit, data) = if snapshot
254
+ . resolved_client_capabilities ( )
255
+ . code_action_deferred_edit_resolution
256
+ {
257
+ // The edit will be resolved later in the `CodeActionsResolve` request
258
+ (
259
+ None ,
260
+ Some (
261
+ serde_json:: to_value ( snapshot. query ( ) . make_key ( ) . into_url ( ) )
262
+ . expect ( "document url should serialize" ) ,
263
+ ) ,
264
+ )
265
+ } else {
266
+ (
267
+ Some ( resolve_edit_for_organize_imports (
268
+ document,
269
+ snapshot. resolved_client_capabilities ( ) ,
270
+ snapshot. query ( ) . settings ( ) . linter ( ) ,
271
+ snapshot. encoding ( ) ,
272
+ ) ?) ,
273
+ None ,
274
+ )
275
+ } ;
276
+
277
+ Ok ( CodeActionOrCommand :: CodeAction ( types:: CodeAction {
278
+ title : format ! ( "{DIAGNOSTIC_NAME}: Organize imports" ) ,
279
+ kind : Some ( crate :: NOTEBOOK_SOURCE_ORGANIZE_IMPORTS_RUFF ) ,
280
+ edit,
281
+ data,
282
+ ..Default :: default ( )
283
+ } ) )
284
+ }
285
+
200
286
/// If `action_filter` is `None`, this returns [`SupportedCodeActionKind::all()`]. Otherwise,
201
287
/// the list is filtered.
202
288
fn supported_code_actions (
0 commit comments