@@ -20,6 +20,7 @@ use itertools::Itertools;
20
20
use paths:: { Utf8Component , Utf8Prefix } ;
21
21
use semver:: VersionReq ;
22
22
use serde_json:: to_value;
23
+ use syntax:: SmolStr ;
23
24
use vfs:: AbsPath ;
24
25
25
26
use crate :: {
@@ -1567,6 +1568,7 @@ pub(crate) fn code_lens(
1567
1568
let line_index = snap. file_line_index ( run. nav . file_id ) ?;
1568
1569
let annotation_range = range ( & line_index, annotation. range ) ;
1569
1570
1571
+ let update_test = run. update_test ;
1570
1572
let title = run. title ( ) ;
1571
1573
let can_debug = match run. kind {
1572
1574
ide:: RunnableKind :: DocTest { .. } => false ,
@@ -1602,6 +1604,17 @@ pub(crate) fn code_lens(
1602
1604
data : None ,
1603
1605
} )
1604
1606
}
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
+ }
1605
1618
}
1606
1619
1607
1620
if lens_config. interpret {
@@ -1786,7 +1799,7 @@ pub(crate) mod command {
1786
1799
1787
1800
pub ( crate ) fn debug_single ( runnable : & lsp_ext:: Runnable ) -> lsp_types:: Command {
1788
1801
lsp_types:: Command {
1789
- title : "Debug" . into ( ) ,
1802
+ title : "⚙ \u{fe0e} Debug" . into ( ) ,
1790
1803
command : "rust-analyzer.debugSingle" . into ( ) ,
1791
1804
arguments : Some ( vec ! [ to_value( runnable) . unwrap( ) ] ) ,
1792
1805
}
@@ -1838,6 +1851,29 @@ pub(crate) mod command {
1838
1851
}
1839
1852
}
1840
1853
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
+
1841
1877
pub ( crate ) fn implementation_title ( count : usize ) -> String {
1842
1878
if count == 1 {
1843
1879
"1 implementation" . into ( )
0 commit comments