mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Improve server version info
This commit is contained in:
parent
88014fcec0
commit
4e48a73f9c
5 changed files with 45 additions and 1 deletions
|
@ -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()?;
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
9
editors/code/src/commands/server_version.ts
Normal file
9
editors/code/src/commands/server_version.ts
Normal file
|
@ -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);
|
||||
};
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue