mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +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]
|
[alias]
|
||||||
# Automatically generates the ast and syntax kinds files
|
# Automatically generates the ast and syntax kinds files
|
||||||
gen-syntax = "run --package ra_tools --bin ra_tools -- gen-syntax"
|
gen-syntax = "run --package ra_tools --bin ra_tools -- gen-syntax"
|
||||||
|
|
||||||
# Extracts the tests from
|
# Extracts the tests from
|
||||||
gen-tests = "run --package ra_tools --bin ra_tools -- gen-tests"
|
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
|
# 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.
|
# Formats the full repository or installs the git hook to do it automatically.
|
||||||
format = "run --package ra_tools --bin ra_tools -- format"
|
format = "run --package ra_tools --bin ra_tools -- format"
|
||||||
format-hook = "run --package ra_tools --bin ra_tools -- format-hook"
|
format-hook = "run --package ra_tools --bin ra_tools -- format-hook"
|
||||||
|
|
||||||
# Run clippy
|
# Run clippy
|
||||||
lint = "run --package ra_tools --bin ra_tools -- lint"
|
lint = "run --package ra_tools --bin ra_tools -- lint"
|
||||||
|
|
||||||
# Runs the fuzzing test suite (currently only parser)
|
# Runs the fuzzing test suite (currently only parser)
|
||||||
fuzz-tests = "run --package ra_tools --bin ra_tools -- fuzz-tests"
|
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 a file. This should be piped the file contents
|
||||||
parse = "run --package ra_cli -- parse"
|
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
|
$ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer
|
||||||
|
|
||||||
# install both the language server and VS Code extension
|
# 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`.
|
# alternatively, install only the server. Binary name is `ra_lsp_server`.
|
||||||
$ cargo install-lsp
|
$ cargo install-ra --server
|
||||||
```
|
```
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,29 @@ pub fn project_root() -> PathBuf {
|
||||||
Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf()
|
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<()> {
|
pub fn run(cmdline: &str, dir: &str) -> Result<()> {
|
||||||
do_run(cmdline, dir, |c| {
|
do_run(cmdline, dir, |c| {
|
||||||
c.stdout(Stdio::inherit());
|
c.stdout(Stdio::inherit());
|
||||||
|
|
|
@ -1,70 +1,73 @@
|
||||||
use clap::{App, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use core::str;
|
use core::str;
|
||||||
use ra_tools::{
|
use ra_tools::{
|
||||||
gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt,
|
gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd,
|
||||||
run_with_output, Overwrite, Result,
|
Overwrite, Result,
|
||||||
};
|
};
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
|
struct InstallOpt {
|
||||||
|
client: Option<ClientOpt>,
|
||||||
|
server: Option<ServerOpt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ClientOpt {
|
||||||
|
VsCode,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ServerOpt {
|
||||||
|
jemalloc: bool,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let matches = App::new("tasks")
|
let matches = App::new("tasks")
|
||||||
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(SubCommand::with_name("gen-syntax"))
|
.subcommand(SubCommand::with_name("gen-syntax"))
|
||||||
.subcommand(SubCommand::with_name("gen-tests"))
|
.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"))
|
||||||
.subcommand(SubCommand::with_name("format-hook"))
|
.subcommand(SubCommand::with_name("format-hook"))
|
||||||
.subcommand(SubCommand::with_name("fuzz-tests"))
|
.subcommand(SubCommand::with_name("fuzz-tests"))
|
||||||
.subcommand(SubCommand::with_name("lint"))
|
.subcommand(SubCommand::with_name("lint"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
match matches.subcommand_name().expect("Subcommand must be specified") {
|
match matches.subcommand() {
|
||||||
"install-code" => {
|
("install-ra", Some(matches)) => {
|
||||||
if cfg!(target_os = "macos") {
|
let opts = InstallOpt {
|
||||||
fix_path_for_mac()?;
|
client: if matches.is_present("server") { None } else { Some(ClientOpt::VsCode) },
|
||||||
}
|
server: if matches.is_present("client-code") {
|
||||||
install_code_extension()?;
|
None
|
||||||
|
} else {
|
||||||
|
Some(ServerOpt { jemalloc: matches.is_present("jemalloc") })
|
||||||
|
},
|
||||||
|
};
|
||||||
|
install(opts)?
|
||||||
}
|
}
|
||||||
"gen-tests" => gen_tests(Overwrite)?,
|
("gen-tests", _) => gen_tests(Overwrite)?,
|
||||||
"gen-syntax" => generate(Overwrite)?,
|
("gen-syntax", _) => generate(Overwrite)?,
|
||||||
"format" => run_rustfmt(Overwrite)?,
|
("format", _) => run_rustfmt(Overwrite)?,
|
||||||
"format-hook" => install_format_hook()?,
|
("format-hook", _) => install_format_hook()?,
|
||||||
"lint" => run_clippy()?,
|
("lint", _) => run_clippy()?,
|
||||||
"fuzz-tests" => run_fuzzer()?,
|
("fuzz-tests", _) => run_fuzzer()?,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_code_extension() -> Result<()> {
|
fn install(opts: InstallOpt) -> Result<()> {
|
||||||
run("cargo install --path crates/ra_lsp_server --force", ".")?;
|
if cfg!(target_os = "macos") {
|
||||||
if cfg!(windows) {
|
fix_path_for_mac()?
|
||||||
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")?;
|
|
||||||
}
|
}
|
||||||
if cfg!(windows) {
|
if let Some(client) = opts.client {
|
||||||
run(
|
install_client(client)?;
|
||||||
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")?;
|
|
||||||
}
|
}
|
||||||
verify_installed_extensions()?;
|
if let Some(server) = opts.server {
|
||||||
Ok(())
|
install_server(server)?;
|
||||||
}
|
|
||||||
|
|
||||||
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.")?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -101,3 +104,47 @@ fn fix_path_for_mac() -> Result<()> {
|
||||||
|
|
||||||
Ok(())
|
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.
|
developer and user documentation.
|
||||||
|
|
||||||
We have some automation infra in Rust in the `crates/tool` package. It contains
|
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`
|
The latter syntax is achieved with the help of cargo aliases (see `.cargo`
|
||||||
directory).
|
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
|
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)!).
|
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.
|
restart the host VS Code.
|
||||||
|
|
||||||
See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with
|
See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with
|
||||||
|
@ -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
|
$ 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.
|
* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
The main interface to rust-analyzer is the
|
The main interface to rust-analyzer is the
|
||||||
[LSP](https://microsoft.github.io/language-server-protocol/) implementation. To
|
[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
|
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
|
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
|
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
|
$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
|
||||||
$ cd rust-analyzer
|
$ cd rust-analyzer
|
||||||
$ cargo install-code
|
$ cargo install-ra
|
||||||
```
|
```
|
||||||
|
|
||||||
The automatic installation is expected to *just work* for common cases, if it
|
The automatic installation is expected to *just work* for common cases, if it
|
||||||
|
|
Loading…
Reference in a new issue