aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/build.rs15
-rw-r--r--crates/ra_lsp_server/src/main.rs18
2 files changed, 32 insertions, 1 deletions
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 @@
1//! Just embed git-hash to `--version`
2
3use std::process::Command;
4
5fn main() {
6 let rev = rev().unwrap_or_else(|| "???????".to_string());
7 println!("cargo:rustc-env=REV={}", rev)
8}
9
10fn rev() -> Option<String> {
11 let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?;
12 let stdout = String::from_utf8(output.stdout).ok()?;
13 let short_hash = stdout.get(0..7)?;
14 Some(short_hash.to_owned())
15}
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;
6 6
7fn main() -> Result<()> { 7fn main() -> Result<()> {
8 setup_logging()?; 8 setup_logging()?;
9 run_server()?; 9 match Args::parse()? {
10 Args::Version => println!("rust-analyzer {}", env!("REV")),
11 Args::Run => run_server()?,
12 }
10 Ok(()) 13 Ok(())
11} 14}
12 15
@@ -22,6 +25,19 @@ fn setup_logging() -> Result<()> {
22 Ok(()) 25 Ok(())
23} 26}
24 27
28enum Args {
29 Version,
30 Run,
31}
32
33impl Args {
34 fn parse() -> Result<Args> {
35 let res =
36 if std::env::args().any(|it| it == "--version") { Args::Version } else { Args::Run };
37 Ok(res)
38 }
39}
40
25fn run_server() -> Result<()> { 41fn run_server() -> Result<()> {
26 log::info!("lifecycle: server started"); 42 log::info!("lifecycle: server started");
27 43