mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
Merge #2511
2511: Implement `ra_lsp_server --version` r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
442ab3a34d
15
crates/ra_lsp_server/build.rs
Normal file
15
crates/ra_lsp_server/build.rs
Normal file
@ -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<String> {
|
||||
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())
|
||||
}
|
@ -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<Args> {
|
||||
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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user