//! Just embed git-hash to `--version`
-use std::process::Command;
+use std::{env, path::PathBuf, process::Command};
fn main() {
+ let _ = set_rerun();
+
let rev = rev().unwrap_or_else(|| "???????".to_string());
println!("cargo:rustc-env=REV={}", rev)
}
+fn set_rerun() {
+ let mut manifest_dir = PathBuf::from(
+ env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
+ );
+
+ while manifest_dir.parent().is_some() {
+ if manifest_dir.join(".git/HEAD").exists() {
+ let git_dir = manifest_dir.join(".git");
+
+ println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display());
+ // current branch ref
+ if let Ok(output) =
+ Command::new("git").args(&["rev-parse", "--symbolic-full-name", "HEAD"]).output()
+ {
+ if let Ok(ref_link) = String::from_utf8(output.stdout) {
+ println!("cargo:rerun-if-changed={}", git_dir.join(ref_link).display());
+ }
+ }
+ return;
+ }
+
+ manifest_dir.pop();
+ }
+ println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!");
+}
+
fn rev() -> Option<String> {
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?;
let stdout = String::from_utf8(output.stdout).ok()?;
"command": "rust-analyzer.ssr",
"title": "Structural Search Replace",
"category": "Rust Analyzer"
+ },
+ {
+ "command": "rust-analyzer.serverVersion",
+ "title": "Show RA Version",
+ "category": "Rust Analyzer"
}
],
"keybindings": [
--- /dev/null
+import * as vscode from 'vscode';
+import { ServerVersion } from '../installation/server';
+import { Cmd } from '../ctx';
+
+export function serverVersion(): Cmd {
+ return () => {
+ vscode.window.showInformationMessage('rust-analyzer version : ' + ServerVersion);
+ };
+}
\ No newline at end of file
ctx.registerCommand('run', commands.run);
ctx.registerCommand('onEnter', commands.onEnter);
ctx.registerCommand('ssr', commands.ssr);
+ ctx.registerCommand('serverVersion', commands.serverVersion);
// Internal commands which are invoked by the server.
ctx.registerCommand('runSingle', commands.runSingle);