mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Overhaul installation process
The new commands are $ cargo install-ra --client-code $ cargo install-ra --server --jemalloc
This commit is contained in:
parent
d23a755870
commit
ecb1327fed
6 changed files with 128 additions and 58 deletions
|
@ -1,23 +1,23 @@
|
|||
[alias]
|
||||
# Automatically generates the ast and syntax kinds files
|
||||
gen-syntax = "run --package ra_tools --bin ra_tools -- gen-syntax"
|
||||
|
||||
# Extracts the tests from
|
||||
gen-tests = "run --package ra_tools --bin ra_tools -- gen-tests"
|
||||
# Installs ra_lsp_server
|
||||
install-lsp = "install --path crates/ra_lsp_server --force"
|
||||
# Installs ra_lsp_server with the jemalloc feature
|
||||
jinstall-lsp = "install --path crates/ra_lsp_server --force --features jemalloc"
|
||||
|
||||
# Installs the visual studio code extension
|
||||
install-code = "run --package ra_tools --bin ra_tools -- install-code"
|
||||
install-ra = "run --package ra_tools --bin ra_tools -- install-ra"
|
||||
install-code = "run --package ra_tools --bin ra_tools -- install-ra" # just an alias
|
||||
|
||||
# Formats the full repository or installs the git hook to do it automatically.
|
||||
format = "run --package ra_tools --bin ra_tools -- format"
|
||||
format-hook = "run --package ra_tools --bin ra_tools -- format-hook"
|
||||
|
||||
# Run clippy
|
||||
lint = "run --package ra_tools --bin ra_tools -- lint"
|
||||
|
||||
# Runs the fuzzing test suite (currently only parser)
|
||||
fuzz-tests = "run --package ra_tools --bin ra_tools -- fuzz-tests"
|
||||
|
||||
render-test = "run --package ra_cli -- render-test"
|
||||
# Parse a file. This should be piped the file contents
|
||||
parse = "run --package ra_cli -- parse"
|
||||
|
|
|
@ -32,10 +32,10 @@ For setup for other editors, see [./docs/user](./docs/user).
|
|||
$ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer
|
||||
|
||||
# install both the language server and VS Code extension
|
||||
$ cargo install-code
|
||||
$ cargo install-ra
|
||||
|
||||
# alternatively, install only the server. Binary name is `ra_lsp_server`.
|
||||
$ cargo install-lsp
|
||||
$ cargo install-ra --server
|
||||
```
|
||||
## Documentation
|
||||
|
||||
|
|
|
@ -79,6 +79,29 @@ 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,
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(self) -> Result<()> {
|
||||
if cfg!(windows) {
|
||||
run(self.windows, self.work_dir)
|
||||
} else {
|
||||
run(self.unix, self.work_dir)
|
||||
}
|
||||
}
|
||||
pub fn run_with_output(self) -> Result<Output> {
|
||||
if cfg!(windows) {
|
||||
run_with_output(self.windows, self.work_dir)
|
||||
} else {
|
||||
run_with_output(self.unix, self.work_dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(cmdline: &str, dir: &str) -> Result<()> {
|
||||
do_run(cmdline, dir, |c| {
|
||||
c.stdout(Stdio::inherit());
|
||||
|
|
|
@ -1,70 +1,73 @@
|
|||
use clap::{App, SubCommand};
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use core::str;
|
||||
use ra_tools::{
|
||||
gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt,
|
||||
run_with_output, Overwrite, Result,
|
||||
gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd,
|
||||
Overwrite, Result,
|
||||
};
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
struct InstallOpt {
|
||||
client: Option<ClientOpt>,
|
||||
server: Option<ServerOpt>,
|
||||
}
|
||||
|
||||
enum ClientOpt {
|
||||
VsCode,
|
||||
}
|
||||
|
||||
struct ServerOpt {
|
||||
jemalloc: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let matches = App::new("tasks")
|
||||
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand(SubCommand::with_name("gen-syntax"))
|
||||
.subcommand(SubCommand::with_name("gen-tests"))
|
||||
.subcommand(SubCommand::with_name("install-code"))
|
||||
.subcommand(
|
||||
SubCommand::with_name("install-ra")
|
||||
.arg(Arg::with_name("server").long("--server"))
|
||||
.arg(Arg::with_name("jemalloc").long("jemalloc").requires("server"))
|
||||
.arg(Arg::with_name("client-code").long("client-code").conflicts_with("server")),
|
||||
)
|
||||
.alias("install-code")
|
||||
.subcommand(SubCommand::with_name("format"))
|
||||
.subcommand(SubCommand::with_name("format-hook"))
|
||||
.subcommand(SubCommand::with_name("fuzz-tests"))
|
||||
.subcommand(SubCommand::with_name("lint"))
|
||||
.get_matches();
|
||||
match matches.subcommand_name().expect("Subcommand must be specified") {
|
||||
"install-code" => {
|
||||
if cfg!(target_os = "macos") {
|
||||
fix_path_for_mac()?;
|
||||
}
|
||||
install_code_extension()?;
|
||||
match matches.subcommand() {
|
||||
("install-ra", Some(matches)) => {
|
||||
let opts = InstallOpt {
|
||||
client: if matches.is_present("server") { None } else { Some(ClientOpt::VsCode) },
|
||||
server: if matches.is_present("client-code") {
|
||||
None
|
||||
} else {
|
||||
Some(ServerOpt { jemalloc: matches.is_present("jemalloc") })
|
||||
},
|
||||
};
|
||||
install(opts)?
|
||||
}
|
||||
"gen-tests" => gen_tests(Overwrite)?,
|
||||
"gen-syntax" => generate(Overwrite)?,
|
||||
"format" => run_rustfmt(Overwrite)?,
|
||||
"format-hook" => install_format_hook()?,
|
||||
"lint" => run_clippy()?,
|
||||
"fuzz-tests" => run_fuzzer()?,
|
||||
("gen-tests", _) => gen_tests(Overwrite)?,
|
||||
("gen-syntax", _) => generate(Overwrite)?,
|
||||
("format", _) => run_rustfmt(Overwrite)?,
|
||||
("format-hook", _) => install_format_hook()?,
|
||||
("lint", _) => run_clippy()?,
|
||||
("fuzz-tests", _) => run_fuzzer()?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn install_code_extension() -> Result<()> {
|
||||
run("cargo install --path crates/ra_lsp_server --force", ".")?;
|
||||
if cfg!(windows) {
|
||||
run(r"cmd.exe /c npm.cmd ci", "./editors/code")?;
|
||||
run(r"cmd.exe /c npm.cmd run package", "./editors/code")?;
|
||||
} else {
|
||||
run(r"npm ci", "./editors/code")?;
|
||||
run(r"npm run package", "./editors/code")?;
|
||||
fn install(opts: InstallOpt) -> Result<()> {
|
||||
if cfg!(target_os = "macos") {
|
||||
fix_path_for_mac()?
|
||||
}
|
||||
if cfg!(windows) {
|
||||
run(
|
||||
r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
|
||||
"./editors/code",
|
||||
)?;
|
||||
} else {
|
||||
run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?;
|
||||
if let Some(client) = opts.client {
|
||||
install_client(client)?;
|
||||
}
|
||||
verify_installed_extensions()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_installed_extensions() -> Result<()> {
|
||||
let exts = if cfg!(windows) {
|
||||
run_with_output(r"cmd.exe /c code.cmd --list-extensions", ".")?
|
||||
} else {
|
||||
run_with_output(r"code --list-extensions", ".")?
|
||||
};
|
||||
if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
|
||||
Err("Could not install the Visual Studio Code extension. Please make sure you \
|
||||
have at least NodeJS 10.x installed and try again.")?;
|
||||
if let Some(server) = opts.server {
|
||||
install_server(server)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -101,3 +104,47 @@ fn fix_path_for_mac() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
||||
Cmd { unix: r"npm ci", windows: r"cmd.exe /c npm.cmd ci", work_dir: "./editors/code" }.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?")?;
|
||||
}
|
||||
|
||||
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",
|
||||
work_dir: "./editors/code",
|
||||
}
|
||||
.run()?;
|
||||
|
||||
let output = Cmd {
|
||||
unix: r"code --list-extensions",
|
||||
windows: r"cmd.exe /c code.cmd --list-extensions",
|
||||
work_dir: ".",
|
||||
}
|
||||
.run_with_output()?;
|
||||
|
||||
if !str::from_utf8(&output.stdout)?.contains("ra-lsp") {
|
||||
Err("Could not install the Visual Studio Code extension. \
|
||||
Please make sure you have at least NodeJS 10.x installed and try again.")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn install_server(opts: ServerOpt) -> Result<()> {
|
||||
if opts.jemalloc {
|
||||
run("cargo install --path crates/ra_lsp_server --force --features jemalloc", ".")
|
||||
} else {
|
||||
run("cargo install --path crates/ra_lsp_server --force", ".")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ typescript) and Emacs (in elisp). The `docs` top-level directory contains both
|
|||
developer and user documentation.
|
||||
|
||||
We have some automation infra in Rust in the `crates/tool` package. It contains
|
||||
stuff like formatting checking, code generation and powers `cargo install-code`.
|
||||
stuff like formatting checking, code generation and powers `cargo install-ra`.
|
||||
The latter syntax is achieved with the help of cargo aliases (see `.cargo`
|
||||
directory).
|
||||
|
||||
|
@ -84,7 +84,7 @@ However, launching a VS Code instance with locally build language server is
|
|||
possible. There's even a VS Code task for this, so just <kbd>F5</kbd> should
|
||||
work (thanks, [@andrew-w-ross](https://github.com/andrew-w-ross)!).
|
||||
|
||||
I often just install development version with `cargo jinstall-lsp` and
|
||||
I often just install development version with `cargo install-ra --server --jemalloc` and
|
||||
restart the host VS Code.
|
||||
|
||||
See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with
|
||||
|
@ -110,7 +110,7 @@ ways:
|
|||
|
||||
2. Run `npm test` from the command line. Although this is initiated from the
|
||||
command line it is not headless; it will also launch a temporary instance of
|
||||
VS Code.
|
||||
VS Code.
|
||||
|
||||
Due to the requirements of running the tests inside VS Code they are **not run
|
||||
on CI**. When making changes to the extension please ensure the tests are not
|
||||
|
@ -151,7 +151,7 @@ There's also two VS Code commands which might be of interest:
|
|||
$ cargo install --path crates/ra_lsp_server --force --features jemalloc
|
||||
```
|
||||
|
||||
There's an alias for this: `cargo jinstall-lsp`.
|
||||
There's an alias for this: `cargo install-ra --server --jemalloc`.
|
||||
|
||||
* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
The main interface to rust-analyzer is the
|
||||
[LSP](https://microsoft.github.io/language-server-protocol/) implementation. To
|
||||
install lsp server, use `cargo install-lsp`, which is a shorthand for `cargo
|
||||
install lsp server, use `cargo install-ra --server`, which is a shorthand for `cargo
|
||||
install --package ra_lsp_server`. The binary is named `ra_lsp_server`, you
|
||||
should be able to use it with any LSP-compatible editor. We use custom
|
||||
extensions to LSP, so special client-side support is required to take full
|
||||
|
@ -33,7 +33,7 @@ following commands:
|
|||
```
|
||||
$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
|
||||
$ cd rust-analyzer
|
||||
$ cargo install-code
|
||||
$ cargo install-ra
|
||||
```
|
||||
|
||||
The automatic installation is expected to *just work* for common cases, if it
|
||||
|
|
Loading…
Reference in a new issue