11//! Installs rust-analyzer language server and/or editor plugin.
22
3- use std:: { env, path:: PathBuf , str} ;
3+ use std:: { env, fs , path:: PathBuf , str} ;
44
55use anyhow:: { bail, format_err, Context , Result } ;
6+ use walkdir:: WalkDir ;
67
78use crate :: cmd:: { run, run_with_output, Cmd } ;
89
@@ -95,13 +96,29 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
9596
9697 Cmd { unix : r"npm install" , windows : r"cmd.exe /c npm install" , work_dir : "./editors/code" }
9798 . run ( ) ?;
99+
100+ let vsixes = || {
101+ WalkDir :: new ( "./editors/code" )
102+ . max_depth ( 1 )
103+ . into_iter ( )
104+ . map ( |it| it. unwrap ( ) )
105+ . map ( |it| it. path ( ) . to_owned ( ) )
106+ . filter ( |it| it. file_name ( ) . unwrap_or_default ( ) . to_string_lossy ( ) . ends_with ( ".vsix" ) )
107+ } ;
108+
109+ for path in vsixes ( ) {
110+ fs:: remove_file ( path) ?
111+ }
112+
98113 Cmd {
99114 unix : r"npm run package --scripts-prepend-node-path" ,
100115 windows : r"cmd.exe /c npm run package" ,
101116 work_dir : "./editors/code" ,
102117 }
103118 . run ( ) ?;
104119
120+ let extension = vsixes ( ) . next ( ) . unwrap ( ) . file_name ( ) . unwrap ( ) . to_string_lossy ( ) . to_string ( ) ;
121+
105122 let code_binary = [ "code" , "code-insiders" , "codium" , "code-oss" ]
106123 . iter ( )
107124 . find ( |bin| {
@@ -118,10 +135,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
118135 } ) ?;
119136
120137 Cmd {
121- unix : & format ! ( r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force" , code_binary) ,
138+ unix : & format ! ( r"{} --install-extension ./{} --force" , code_binary, extension ) ,
122139 windows : & format ! (
123- r"cmd.exe /c {}.cmd --install-extension ./rust-analyzer-0.1.0.vsix --force" ,
124- code_binary
140+ r"cmd.exe /c {}.cmd --install-extension ./{} --force" ,
141+ code_binary, extension
125142 ) ,
126143 work_dir : "./editors/code" ,
127144 }
0 commit comments