From 5a012fb9fd87404515033b2a5e025f2b7ec44b29 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Dec 2019 15:59:04 +0100 Subject: Implement `ra_lsp_server --version` --- crates/ra_lsp_server/build.rs | 15 +++++++++++++++ crates/ra_lsp_server/src/main.rs | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 crates/ra_lsp_server/build.rs (limited to 'crates') diff --git a/crates/ra_lsp_server/build.rs b/crates/ra_lsp_server/build.rs new file mode 100644 index 000000000..05f9772c0 --- /dev/null +++ b/crates/ra_lsp_server/build.rs @@ -0,0 +1,15 @@ +//! Just embed git-hash to `--version` + +use std::process::Command; + +fn main() { + let rev = rev().unwrap_or_else(|| "???????".to_string()); + println!("cargo:rustc-env=REV={}", rev) +} + +fn rev() -> Option { + let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; + let stdout = String::from_utf8(output.stdout).ok()?; + let short_hash = stdout.get(0..7)?; + Some(short_hash.to_owned()) +} diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 8076a7fa5..cdd925c9f 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -6,7 +6,10 @@ use ra_prof; fn main() -> Result<()> { setup_logging()?; - run_server()?; + match Args::parse()? { + Args::Version => println!("rust-analyzer {}", env!("REV")), + Args::Run => run_server()?, + } Ok(()) } @@ -22,6 +25,19 @@ fn setup_logging() -> Result<()> { Ok(()) } +enum Args { + Version, + Run, +} + +impl Args { + fn parse() -> Result { + let res = + if std::env::args().any(|it| it == "--version") { Args::Version } else { Args::Run }; + Ok(res) + } +} + fn run_server() -> Result<()> { log::info!("lifecycle: server started"); -- cgit v1.2.3