]> git.lizzy.rs Git - rust.git/commitdiff
Improve server version info
authorEdwin Cheng <edwin0cheng@gmail.com>
Fri, 21 Feb 2020 02:04:03 +0000 (10:04 +0800)
committerEdwin Cheng <edwin0cheng@gmail.com>
Fri, 21 Feb 2020 10:33:45 +0000 (18:33 +0800)
crates/rust-analyzer/build.rs
editors/code/package.json
editors/code/src/commands/index.ts
editors/code/src/commands/server_version.ts [new file with mode: 0644]
editors/code/src/main.ts

index 05f9772c0410221640961dedfdb45e3f56fd748a..cda8833d14dfe953f66583120ceb679ba3c7338b 100644 (file)
@@ -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<String> {
     let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?;
     let stdout = String::from_utf8(output.stdout).ok()?;
index c498c14b4290848ea1ede5083a47ece0c8884cca..72befe2b63a3431c7e0272a8b27a15a53d2762d9 100644 (file)
                 "command": "rust-analyzer.ssr",
                 "title": "Structural Search Replace",
                 "category": "Rust Analyzer"
+            },
+            {
+                "command": "rust-analyzer.serverVersion",
+                "title": "Show RA Version",
+                "category": "Rust Analyzer"
             }
         ],
         "keybindings": [
index bebd99ca931fd0275213afd1284286e4dedce569..839245f48756462063e5d07004dd1950805f695b 100644 (file)
@@ -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 (file)
index 0000000..3a982a4
--- /dev/null
@@ -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
index a22e0bc66601630e1334948e091e20fdfb7adffd..de19a44e517d6127321a050887d55b23660e35a5 100644 (file)
@@ -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);