diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs index 05f9772c04..cda8833d14 100644 --- a/crates/rust-analyzer/build.rs +++ b/crates/rust-analyzer/build.rs @@ -1,12 +1,40 @@ //! 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 { let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; let stdout = String::from_utf8(output.stdout).ok()?; diff --git a/editors/code/package.json b/editors/code/package.json index c498c14b42..72befe2b63 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -131,6 +131,11 @@ "command": "rust-analyzer.ssr", "title": "Structural Search Replace", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.serverVersion", + "title": "Show RA Version", + "category": "Rust Analyzer" } ], "keybindings": [ diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index bebd99ca93..839245f487 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -13,6 +13,7 @@ export * from './syntax_tree'; export * from './expand_macro'; export * from './runnables'; export * from './ssr'; +export * from './server_version'; export function collectGarbage(ctx: Ctx): Cmd { return async () => { diff --git a/editors/code/src/commands/server_version.ts b/editors/code/src/commands/server_version.ts new file mode 100644 index 0000000000..3a982a418a --- /dev/null +++ b/editors/code/src/commands/server_version.ts @@ -0,0 +1,9 @@ +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 diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index a22e0bc666..de19a44e51 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -55,6 +55,7 @@ export async function activate(context: vscode.ExtensionContext) { 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);