mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
allow xtask install --client-code[=CLIENT] to specify client
This commit is contained in:
parent
59483c2176
commit
d0bb051ef7
2 changed files with 49 additions and 15 deletions
|
@ -13,8 +13,43 @@ pub struct InstallCmd {
|
||||||
pub server: Option<ServerOpt>,
|
pub server: Option<ServerOpt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub enum ClientOpt {
|
pub enum ClientOpt {
|
||||||
VsCode,
|
VsCode,
|
||||||
|
VsCodeInsiders,
|
||||||
|
VsCodium,
|
||||||
|
VsCodeOss,
|
||||||
|
Any,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClientOpt {
|
||||||
|
pub const fn as_cmds(&self) -> &'static [&'static str] {
|
||||||
|
match self {
|
||||||
|
ClientOpt::VsCode => &["code"],
|
||||||
|
ClientOpt::VsCodeInsiders => &["code-insiders"],
|
||||||
|
ClientOpt::VsCodium => &["codium"],
|
||||||
|
ClientOpt::VsCodeOss => &["code-oss"],
|
||||||
|
ClientOpt::Any => &["code", "code-insiders", "codium", "code-oss"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ClientOpt {
|
||||||
|
fn default() -> Self {
|
||||||
|
ClientOpt::Any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for ClientOpt {
|
||||||
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
[ClientOpt::VsCode, ClientOpt::VsCodeInsiders, ClientOpt::VsCodium, ClientOpt::VsCodeOss]
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.find(|c| [s] == c.as_cmds())
|
||||||
|
.ok_or_else(|| anyhow::format_err!("no such client"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServerOpt {
|
pub struct ServerOpt {
|
||||||
|
@ -74,17 +109,13 @@ fn fix_path_for_mac() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
fn install_client(client_opt: ClientOpt) -> Result<()> {
|
||||||
let _dir = pushd("./editors/code")?;
|
let _dir = pushd("./editors/code");
|
||||||
|
|
||||||
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
|
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
|
||||||
["code", "code-insiders", "codium", "code-oss"]
|
client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| {
|
||||||
.iter()
|
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
|
||||||
.copied()
|
})
|
||||||
.find(|bin| f(bin))
|
|
||||||
.ok_or_else(|| {
|
|
||||||
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let installed_extensions = if cfg!(unix) {
|
let installed_extensions = if cfg!(unix) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use xshell::pushd;
|
||||||
use xtask::{
|
use xtask::{
|
||||||
codegen::{self, Mode},
|
codegen::{self, Mode},
|
||||||
dist::DistCmd,
|
dist::DistCmd,
|
||||||
install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
|
install::{InstallCmd, Malloc, ServerOpt},
|
||||||
metrics::MetricsCmd,
|
metrics::MetricsCmd,
|
||||||
pre_cache::PreCacheCmd,
|
pre_cache::PreCacheCmd,
|
||||||
pre_commit, project_root,
|
pre_commit, project_root,
|
||||||
|
@ -46,10 +46,11 @@ USAGE:
|
||||||
cargo xtask install [FLAGS]
|
cargo xtask install [FLAGS]
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
--client-code Install only VS Code plugin
|
--client-code[=CLIENT] Install only VS Code plugin.
|
||||||
--server Install only the language server
|
CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss'
|
||||||
--mimalloc Use mimalloc for server
|
--server Install only the language server
|
||||||
-h, --help Prints help information
|
--mimalloc Use mimalloc for server
|
||||||
|
-h, --help Prints help information
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -67,10 +68,12 @@ FLAGS:
|
||||||
let malloc =
|
let malloc =
|
||||||
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
|
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
|
||||||
|
|
||||||
|
let client_opt = args.opt_value_from_str("--client-code")?;
|
||||||
|
|
||||||
args.finish()?;
|
args.finish()?;
|
||||||
|
|
||||||
InstallCmd {
|
InstallCmd {
|
||||||
client: if server { None } else { Some(ClientOpt::VsCode) },
|
client: if server { None } else { Some(client_opt.unwrap_or_default()) },
|
||||||
server: if client_code { None } else { Some(ServerOpt { malloc }) },
|
server: if client_code { None } else { Some(ServerOpt { malloc }) },
|
||||||
}
|
}
|
||||||
.run()
|
.run()
|
||||||
|
|
Loading…
Reference in a new issue