@@ -80,7 +80,32 @@ pub fn apply_all_fix_code_action<'a>(
8080 reports : impl Iterator < Item = & ' a DiagnosticReport > ,
8181 uri : & Uri ,
8282) -> Option < CodeAction > {
83- let mut quick_fixes: Vec < TextEdit > = vec ! [ ] ;
83+ let quick_fixes: Vec < TextEdit > = fix_all_text_edit ( reports) ;
84+
85+ if quick_fixes. is_empty ( ) {
86+ return None ;
87+ }
88+
89+ Some ( CodeAction {
90+ title : "quick fix" . to_string ( ) ,
91+ kind : Some ( CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC ) ,
92+ is_preferred : Some ( true ) ,
93+ edit : Some ( WorkspaceEdit {
94+ #[ expect( clippy:: disallowed_types) ]
95+ changes : Some ( std:: collections:: HashMap :: from ( [ ( uri. clone ( ) , quick_fixes) ] ) ) ,
96+ ..WorkspaceEdit :: default ( )
97+ } ) ,
98+ disabled : None ,
99+ data : None ,
100+ diagnostics : None ,
101+ command : None ,
102+ } )
103+ }
104+
105+ /// Collect all text edits from the provided diagnostic reports, which can be applied at once.
106+ /// This is useful for implementing a "fix all" code action / command that applies multiple fixes in one go.
107+ pub fn fix_all_text_edit < ' a > ( reports : impl Iterator < Item = & ' a DiagnosticReport > ) -> Vec < TextEdit > {
108+ let mut text_edits: Vec < TextEdit > = vec ! [ ] ;
84109
85110 for report in reports {
86111 let fix = match & report. fixed_content {
@@ -119,29 +144,12 @@ pub fn apply_all_fix_code_action<'a>(
119144 // and return them as one workspace edit.
120145 // it is possible that one fix will change the range for the next fix
121146 // see oxc-project/oxc#10422
122- quick_fixes . push ( TextEdit {
147+ text_edits . push ( TextEdit {
123148 range : fixed_content. range ,
124149 new_text : fixed_content. code . clone ( ) ,
125150 } ) ;
126151 }
127152 }
128153
129- if quick_fixes. is_empty ( ) {
130- return None ;
131- }
132-
133- Some ( CodeAction {
134- title : "quick fix" . to_string ( ) ,
135- kind : Some ( CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC ) ,
136- is_preferred : Some ( true ) ,
137- edit : Some ( WorkspaceEdit {
138- #[ expect( clippy:: disallowed_types) ]
139- changes : Some ( std:: collections:: HashMap :: from ( [ ( uri. clone ( ) , quick_fixes) ] ) ) ,
140- ..WorkspaceEdit :: default ( )
141- } ) ,
142- disabled : None ,
143- data : None ,
144- diagnostics : None ,
145- command : None ,
146- } )
154+ text_edits
147155}
0 commit comments