@@ -20,6 +20,7 @@ use itertools::Itertools;
2020use paths:: { Utf8Component , Utf8Prefix } ;
2121use semver:: VersionReq ;
2222use serde_json:: to_value;
23+ use syntax:: SmolStr ;
2324use vfs:: AbsPath ;
2425
2526use crate :: {
@@ -1567,6 +1568,7 @@ pub(crate) fn code_lens(
15671568 let line_index = snap. file_line_index ( run. nav . file_id ) ?;
15681569 let annotation_range = range ( & line_index, annotation. range ) ;
15691570
1571+ let update_test = run. update_test ;
15701572 let title = run. title ( ) ;
15711573 let can_debug = match run. kind {
15721574 ide:: RunnableKind :: DocTest { .. } => false ,
@@ -1602,6 +1604,17 @@ pub(crate) fn code_lens(
16021604 data : None ,
16031605 } )
16041606 }
1607+ if lens_config. update_test && client_commands_config. run_single {
1608+ let label = update_test. label ( ) ;
1609+ if let Some ( r) = make_update_runnable ( & r, & label) {
1610+ let command = command:: run_single ( & r, label. unwrap ( ) . as_str ( ) ) ;
1611+ acc. push ( lsp_types:: CodeLens {
1612+ range : annotation_range,
1613+ command : Some ( command) ,
1614+ data : None ,
1615+ } )
1616+ }
1617+ }
16051618 }
16061619
16071620 if lens_config. interpret {
@@ -1786,7 +1799,7 @@ pub(crate) mod command {
17861799
17871800 pub ( crate ) fn debug_single ( runnable : & lsp_ext:: Runnable ) -> lsp_types:: Command {
17881801 lsp_types:: Command {
1789- title : "Debug" . into ( ) ,
1802+ title : "⚙ \u{fe0e} Debug" . into ( ) ,
17901803 command : "rust-analyzer.debugSingle" . into ( ) ,
17911804 arguments : Some ( vec ! [ to_value( runnable) . unwrap( ) ] ) ,
17921805 }
@@ -1838,6 +1851,29 @@ pub(crate) mod command {
18381851 }
18391852}
18401853
1854+ fn make_update_runnable (
1855+ runnable : & lsp_ext:: Runnable ,
1856+ label : & Option < SmolStr > ,
1857+ ) -> Option < lsp_ext:: Runnable > {
1858+ if !matches ! ( runnable. args, lsp_ext:: RunnableArgs :: Cargo ( _) ) {
1859+ return None ;
1860+ }
1861+ let label = label. as_ref ( ) ?;
1862+
1863+ let mut runnable = runnable. clone ( ) ;
1864+ runnable. label = format ! ( "{} + {}" , runnable. label, label) ;
1865+
1866+ let lsp_ext:: RunnableArgs :: Cargo ( r) = & mut runnable. args else {
1867+ unreachable ! ( ) ;
1868+ } ;
1869+
1870+ let environment_vars =
1871+ [ ( "UPDATE_EXPECT" , "1" ) , ( "INSTA_UPDATE" , "always" ) , ( "SNAPSHOTS" , "overwrite" ) ] ;
1872+ r. environment . extend ( environment_vars. into_iter ( ) . map ( |( k, v) | ( k. to_owned ( ) , v. to_owned ( ) ) ) ) ;
1873+
1874+ Some ( runnable)
1875+ }
1876+
18411877pub ( crate ) fn implementation_title ( count : usize ) -> String {
18421878 if count == 1 {
18431879 "1 implementation" . into ( )
0 commit comments