mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
set code less generic
This commit is contained in:
parent
9c2177026f
commit
69edc10f35
1 changed files with 24 additions and 50 deletions
|
@ -5,6 +5,7 @@ use tools::{
|
||||||
generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
|
generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
|
||||||
Overwrite, Result, run_fuzzer,
|
Overwrite, Result, run_fuzzer,
|
||||||
};
|
};
|
||||||
|
use std::{path::{PathBuf}, env};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let matches = App::new("tasks")
|
let matches = App::new("tasks")
|
||||||
|
@ -18,7 +19,9 @@ fn main() -> Result<()> {
|
||||||
.get_matches();
|
.get_matches();
|
||||||
match matches.subcommand_name().expect("Subcommand must be specified") {
|
match matches.subcommand_name().expect("Subcommand must be specified") {
|
||||||
"install-code" => {
|
"install-code" => {
|
||||||
setup_environment()?;
|
if cfg!(target_os = "macos") {
|
||||||
|
fix_path_for_mac()?;
|
||||||
|
}
|
||||||
install_code_extension()?;
|
install_code_extension()?;
|
||||||
}
|
}
|
||||||
"gen-tests" => gen_tests(Overwrite)?,
|
"gen-tests" => gen_tests(Overwrite)?,
|
||||||
|
@ -31,14 +34,6 @@ fn main() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_environment() -> Result<()> {
|
|
||||||
if cfg!(target_os = "macos") {
|
|
||||||
vscode_path_helpers::append_vscode_path()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn install_code_extension() -> Result<()> {
|
fn install_code_extension() -> Result<()> {
|
||||||
run("cargo install --path crates/ra_lsp_server --force", ".")?;
|
run("cargo install --path crates/ra_lsp_server --force", ".")?;
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
|
@ -75,28 +70,8 @@ fn verify_installed_extensions() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
fn fix_path_for_mac() -> Result<()> {
|
||||||
mod vscode_path_helpers {
|
let mut vscode_path: Vec<PathBuf> = {
|
||||||
use super::Result;
|
|
||||||
use std::{path::{PathBuf}, env};
|
|
||||||
use failure::bail;
|
|
||||||
|
|
||||||
pub(crate) fn append_vscode_path() -> Result<()> {
|
|
||||||
let vars = match env::var_os("PATH") {
|
|
||||||
Some(path) => path,
|
|
||||||
None => bail!("Could not get PATH variable from env."),
|
|
||||||
};
|
|
||||||
|
|
||||||
let vscode_path = get_vscode_path()?;
|
|
||||||
let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
|
|
||||||
paths.push(vscode_path);
|
|
||||||
let new_paths = env::join_paths(paths)?;
|
|
||||||
env::set_var("PATH", &new_paths);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_vscode_path() -> Result<PathBuf> {
|
|
||||||
const COMMON_APP_PATH: &str =
|
const COMMON_APP_PATH: &str =
|
||||||
r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin";
|
r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin";
|
||||||
const ROOT_DIR: &str = "";
|
const ROOT_DIR: &str = "";
|
||||||
|
@ -105,26 +80,25 @@ mod vscode_path_helpers {
|
||||||
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
|
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
for dir in [ROOT_DIR, &home_dir].iter() {
|
[ROOT_DIR, &home_dir]
|
||||||
let path = String::from(dir.clone()) + COMMON_APP_PATH;
|
.iter()
|
||||||
let path = PathBuf::from(path);
|
.map(|dir| String::from(dir.clone()) + COMMON_APP_PATH)
|
||||||
if path.exists() {
|
.map(PathBuf::from)
|
||||||
return Ok(path);
|
.filter(|path| path.exists())
|
||||||
}
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
if !vscode_path.is_empty() {
|
||||||
|
let vars = match env::var_os("PATH") {
|
||||||
|
Some(path) => path,
|
||||||
|
None => bail!("Could not get PATH variable from env."),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
|
||||||
|
paths.append(&mut vscode_path);
|
||||||
|
let new_paths = env::join_paths(paths)?;
|
||||||
|
env::set_var("PATH", &new_paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
bail!(
|
|
||||||
"Could not find Visual Studio Code application. Please make sure you \
|
|
||||||
have Visual Studio Code installed and try again or install extension \
|
|
||||||
manually."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
mod vscode_path_helpers {
|
|
||||||
use super::Result;
|
|
||||||
pub(crate) fn append_vscode_path() -> Result<()> {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue