22
33use std:: { env, path:: PathBuf , str} ;
44
5- use anyhow:: { Context , Result } ;
5+ use anyhow:: { bail , format_err , Context , Result } ;
66
77use crate :: cmd:: { run, run_with_output, Cmd } ;
88
@@ -55,7 +55,7 @@ fn fix_path_for_mac() -> Result<()> {
5555 const ROOT_DIR : & str = "" ;
5656 let home_dir = match env:: var ( "HOME" ) {
5757 Ok ( home) => home,
58- Err ( e) => anyhow :: bail!( "Failed getting HOME from environment with error: {}." , e) ,
58+ Err ( e) => bail ! ( "Failed getting HOME from environment with error: {}." , e) ,
5959 } ;
6060
6161 [ ROOT_DIR , & home_dir]
@@ -69,7 +69,7 @@ fn fix_path_for_mac() -> Result<()> {
6969 if !vscode_path. is_empty ( ) {
7070 let vars = match env:: var_os ( "PATH" ) {
7171 Some ( path) => path,
72- None => anyhow :: bail!( "Could not get PATH variable from env." ) ,
72+ None => bail ! ( "Could not get PATH variable from env." ) ,
7373 } ;
7474
7575 let mut paths = env:: split_paths ( & vars) . collect :: < Vec < _ > > ( ) ;
@@ -90,7 +90,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
9090 . run ( ) ;
9191
9292 if npm_version. is_err ( ) {
93- eprintln ! ( "\n ERROR: `npm --version` failed, `npm` is required to build the VS Code plugin" )
93+ bail ! ( "`npm --version` failed, `npm` is required to build the VS Code plugin" )
9494 }
9595
9696 Cmd { unix : r"npm install" , windows : r"cmd.exe /c npm install" , work_dir : "./editors/code" }
@@ -102,20 +102,20 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
102102 }
103103 . run ( ) ?;
104104
105- let code_binary = [ "code" , "code-insiders" , "codium" , "code-oss" ] . iter ( ) . find ( |bin| {
106- Cmd {
107- unix : & format ! ( "{} --version" , bin) ,
108- windows : & format ! ( "cmd.exe /c {}.cmd --version" , bin ) ,
109- work_dir : "./editors/code" ,
110- }
111- . run ( )
112- . is_ok ( )
113- } ) ;
114-
115- let code_binary = match code_binary {
116- Some ( it ) => it ,
117- None => anyhow :: bail !( "Can't execute `code --version`. Perhaps it is not in $PATH?" ) ,
118- } ;
105+ let code_binary = [ "code" , "code-insiders" , "codium" , "code-oss" ]
106+ . iter ( )
107+ . find ( | bin| {
108+ Cmd {
109+ unix : & format ! ( "{} --version" , bin ) ,
110+ windows : & format ! ( "cmd.exe /c {}.cmd --version" , bin ) ,
111+ work_dir : "./editors/code" ,
112+ }
113+ . run ( )
114+ . is_ok ( )
115+ } )
116+ . ok_or_else ( || {
117+ format_err ! ( "Can't execute `code --version`. Perhaps it is not in $PATH?" )
118+ } ) ? ;
119119
120120 Cmd {
121121 unix : & format ! ( r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force" , code_binary) ,
@@ -135,24 +135,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
135135 . run_with_output ( ) ?;
136136
137137 if !installed_extensions. contains ( "rust-analyzer" ) {
138- anyhow :: bail!(
138+ bail ! (
139139 "Could not install the Visual Studio Code extension. \
140140 Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again."
141141 ) ;
142142 }
143143
144- if installed_extensions. contains ( "ra-lsp" ) {
145- Cmd {
146- unix : & format ! ( r"{} --uninstall-extension matklad.ra-lsp" , code_binary) ,
147- windows : & format ! (
148- r"cmd.exe /c {}.cmd --uninstall-extension matklad.ra-lsp" ,
149- code_binary
150- ) ,
151- work_dir : "./editors/code" ,
152- }
153- . run ( ) ?;
154- }
155-
156144 Ok ( ( ) )
157145}
158146
0 commit comments