Skip to content
Merged

Minor #3134

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editors/code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"preview": true,
"private": true,
"icon": "icon.png",
"version": "0.1.0",
"//": "The real version is in release.yaml, this one just needs to be bigger",
"version": "0.2.0-dev",
"publisher": "matklad",
"repository": {
"url": "https://github.com/rust-analyzer/rust-analyzer.git",
Expand Down
75 changes: 40 additions & 35 deletions xtask/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Installs rust-analyzer language server and/or editor plugin.

use std::{env, path::PathBuf, str};
use std::{env, fs, path::PathBuf, str};

use anyhow::{Context, Result};
use anyhow::{bail, format_err, Context, Result};
use walkdir::WalkDir;

use crate::cmd::{run, run_with_output, Cmd};

Expand Down Expand Up @@ -55,7 +56,7 @@ fn fix_path_for_mac() -> Result<()> {
const ROOT_DIR: &str = "";
let home_dir = match env::var("HOME") {
Ok(home) => home,
Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e),
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
};

[ROOT_DIR, &home_dir]
Expand All @@ -69,7 +70,7 @@ fn fix_path_for_mac() -> Result<()> {
if !vscode_path.is_empty() {
let vars = match env::var_os("PATH") {
Some(path) => path,
None => anyhow::bail!("Could not get PATH variable from env."),
None => bail!("Could not get PATH variable from env."),
};

let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
Expand All @@ -90,38 +91,54 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
.run();

if npm_version.is_err() {
eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin")
bail!("`npm --version` failed, `npm` is required to build the VS Code plugin")
}

Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" }
.run()?;

let vsixes = || {
WalkDir::new("./editors/code")
.max_depth(1)
.into_iter()
.map(|it| it.unwrap())
.map(|it| it.path().to_owned())
.filter(|it| it.file_name().unwrap_or_default().to_string_lossy().ends_with(".vsix"))
};

for path in vsixes() {
fs::remove_file(path)?
}

Cmd {
unix: r"npm run package --scripts-prepend-node-path",
windows: r"cmd.exe /c npm run package",
work_dir: "./editors/code",
}
.run()?;

let code_binary = ["code", "code-insiders", "codium", "code-oss"].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 => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"),
};
let extension = vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string();

let code_binary = ["code", "code-insiders", "codium", "code-oss"]
.iter()
.find(|bin| {
Cmd {
unix: &format!("{} --version", bin),
windows: &format!("cmd.exe /c {}.cmd --version", bin),
work_dir: "./editors/code",
}
.run()
.is_ok()
})
.ok_or_else(|| {
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
})?;

Cmd {
unix: &format!(r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force", code_binary),
unix: &format!(r"{} --install-extension ./{} --force", code_binary, extension),
windows: &format!(
r"cmd.exe /c {}.cmd --install-extension ./rust-analyzer-0.1.0.vsix --force",
code_binary
r"cmd.exe /c {}.cmd --install-extension ./{} --force",
code_binary, extension
),
work_dir: "./editors/code",
}
Expand All @@ -135,24 +152,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
.run_with_output()?;

if !installed_extensions.contains("rust-analyzer") {
anyhow::bail!(
bail!(
"Could not install the Visual Studio Code extension. \
Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12?

);
}

if installed_extensions.contains("ra-lsp") {
Cmd {
unix: &format!(r"{} --uninstall-extension matklad.ra-lsp", code_binary),
windows: &format!(
r"cmd.exe /c {}.cmd --uninstall-extension matklad.ra-lsp",
code_binary
),
work_dir: "./editors/code",
}
.run()?;
}

Ok(())
}

Expand Down