@@ -1244,8 +1244,7 @@ impl LanguageClient {
12441244 Ok ( result)
12451245 }
12461246
1247- #[ tracing:: instrument( level = "info" , skip( self ) ) ]
1248- pub fn text_document_code_action ( & self , params : & Value ) -> Result < Value > {
1247+ pub fn get_code_actions ( & self , params : & Value ) -> Result < Value > {
12491248 self . text_document_did_change ( params) ?;
12501249 let filename = self . vim ( ) ?. get_filename ( params) ?;
12511250 let language_id = self . vim ( ) ?. get_language_id ( & filename, params) ?;
@@ -1281,6 +1280,40 @@ impl LanguageClient {
12811280 } ,
12821281 ) ?;
12831282
1283+ Ok ( result)
1284+ }
1285+
1286+ #[ tracing:: instrument( level = "info" , skip( self ) ) ]
1287+ pub fn execute_code_action ( & self , params : & Value ) -> Result < Value > {
1288+ let result = self . get_code_actions ( params) ?;
1289+ let response = <Option < CodeActionResponse > >:: deserialize ( & result) ?;
1290+ let response: CodeActionResponse = response. unwrap_or_default ( ) ;
1291+ let kind: String =
1292+ try_get ( "kind" , params) ?. ok_or_else ( || anyhow ! ( "Missing kind parameter" ) ) ?;
1293+ let action_kind = CodeActionKind :: from ( kind. clone ( ) ) ;
1294+ let actions: Vec < CodeActionOrCommand > = response. into_iter ( ) . filter ( |a| matches ! ( a,
1295+ CodeActionOrCommand :: CodeAction ( action) if action. kind. is_some( ) && action. kind. as_ref( ) . unwrap( ) == & action_kind)
1296+ ) . collect ( ) ;
1297+ if actions. len ( ) > 1 {
1298+ return Err ( anyhow ! ( "Too many code actions found with kind {}" , kind) ) ;
1299+ }
1300+ if actions. len ( ) == 0 {
1301+ return Err ( anyhow ! ( "No code actions found with kind {}" , kind) ) ;
1302+ }
1303+
1304+ match actions. first ( ) . cloned ( ) {
1305+ Some ( CodeActionOrCommand :: CodeAction ( action) ) => {
1306+ self . handle_code_action_selection ( & [ action] , 0 ) ?
1307+ }
1308+ _ => return Err ( anyhow ! ( "No code actions found with kind {}" , kind) ) ,
1309+ }
1310+
1311+ Ok ( result)
1312+ }
1313+
1314+ #[ tracing:: instrument( level = "info" , skip( self ) ) ]
1315+ pub fn text_document_code_action ( & self , params : & Value ) -> Result < Value > {
1316+ let result = self . get_code_actions ( params) ?;
12841317 let response = <Option < CodeActionResponse > >:: deserialize ( & result) ?;
12851318 let response = response. unwrap_or_default ( ) ;
12861319
0 commit comments