From 1e16ac031542b629d7997816592742dbf9f911f6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 Sep 2019 14:24:20 +0300 Subject: tweak installation process --- crates/ra_tools/src/lib.rs | 10 +++++----- crates/ra_tools/src/main.rs | 35 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'crates/ra_tools') diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs index d47660369..9ba23caaa 100644 --- a/crates/ra_tools/src/lib.rs +++ b/crates/ra_tools/src/lib.rs @@ -79,13 +79,13 @@ pub fn project_root() -> PathBuf { Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() } -pub struct Cmd { - pub unix: &'static str, - pub windows: &'static str, - pub work_dir: &'static str, +pub struct Cmd<'a> { + pub unix: &'a str, + pub windows: &'a str, + pub work_dir: &'a str, } -impl Cmd { +impl Cmd<'_> { pub fn run(self) -> Result<()> { if cfg!(windows) { run(self.windows, self.work_dir) diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs index f96f1875f..65d211b44 100644 --- a/crates/ra_tools/src/main.rs +++ b/crates/ra_tools/src/main.rs @@ -167,27 +167,34 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { } .run()?; - let code_in_path = Cmd { - unix: r"code --version", - windows: r"cmd.exe /c code.cmd --version", - work_dir: "./editors/code", - } - .run() - .is_ok(); - if !code_in_path { - Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?; - } + let code_binary = ["code", "code-insiders"].iter().find(|bin| { + Cmd { + unix: &format!("{} --version", bin), + windows: &format!("cmd.exe /c {}.cmd --version", bin), + work_dir: "./editors/code", + } + .run() + .is_ok() + }); + + let code_binary = match code_binary { + Some(it) => it, + None => Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?, + }; Cmd { - unix: r"code --install-extension ./ra-lsp-0.0.1.vsix --force", - windows: r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force", + unix: &format!(r"{} --install-extension ./ra-lsp-0.0.1.vsix --force", code_binary), + windows: &format!( + r"cmd.exe /c {}.cmd --install-extension ./ra-lsp-0.0.1.vsix --force", + code_binary + ), work_dir: "./editors/code", } .run()?; let output = Cmd { - unix: r"code --list-extensions", - windows: r"cmd.exe /c code.cmd --list-extensions", + unix: &format!(r"{} --list-extensions", code_binary), + windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), work_dir: ".", } .run_with_output()?; -- cgit v1.2.3