Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RA version display #3247

Merged
merged 6 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion crates/rust-analyzer/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
//! Just embed git-hash to `--version`

use std::process::Command;
use std::{env, path::PathBuf, process::Command};

fn main() {
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()?;
Expand Down
4 changes: 4 additions & 0 deletions docs/user/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Shows the full macro expansion of the macro at current cursor.

Shows internal statistic about memory usage of rust-analyzer

#### Show RA Version

Show current rust-analyzer version

#### Run garbage collection

Manually triggers GC
Expand Down
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions editors/code/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
21 changes: 21 additions & 0 deletions editors/code/src/commands/server_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as vscode from 'vscode';
import { ensureServerBinary } from '../installation/server';
import { Ctx, Cmd } from '../ctx';
import { spawnSync } from 'child_process';

export function serverVersion(ctx: Ctx): Cmd {
return async () => {
const binaryPath = await ensureServerBinary(ctx.config.serverSource);

if (binaryPath == null) {
throw new Error(
"Rust Analyzer Language Server is not available. " +
"Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)."
);
}

const version = spawnSync(binaryPath, ["--version"], { encoding: "utf8" }).stdout;
vscode.window.showInformationMessage('rust-analyzer version : ' + version);
};
}

1 change: 1 addition & 0 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down