diff options
-rw-r--r-- | crates/rust-analyzer/build.rs | 30 | ||||
-rw-r--r-- | docs/user/features.md | 4 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 1 | ||||
-rw-r--r-- | editors/code/src/commands/server_version.ts | 21 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 |
6 files changed, 61 insertions, 1 deletions
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs index 05f9772c0..d4b010c04 100644 --- a/crates/rust-analyzer/build.rs +++ b/crates/rust-analyzer/build.rs | |||
@@ -1,12 +1,40 @@ | |||
1 | //! Just embed git-hash to `--version` | 1 | //! Just embed git-hash to `--version` |
2 | 2 | ||
3 | use std::process::Command; | 3 | use std::{env, path::PathBuf, process::Command}; |
4 | 4 | ||
5 | fn main() { | 5 | fn main() { |
6 | set_rerun(); | ||
7 | |||
6 | let rev = rev().unwrap_or_else(|| "???????".to_string()); | 8 | let rev = rev().unwrap_or_else(|| "???????".to_string()); |
7 | println!("cargo:rustc-env=REV={}", rev) | 9 | println!("cargo:rustc-env=REV={}", rev) |
8 | } | 10 | } |
9 | 11 | ||
12 | fn set_rerun() { | ||
13 | let mut manifest_dir = PathBuf::from( | ||
14 | env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."), | ||
15 | ); | ||
16 | |||
17 | while manifest_dir.parent().is_some() { | ||
18 | if manifest_dir.join(".git/HEAD").exists() { | ||
19 | let git_dir = manifest_dir.join(".git"); | ||
20 | |||
21 | println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display()); | ||
22 | // current branch ref | ||
23 | if let Ok(output) = | ||
24 | Command::new("git").args(&["rev-parse", "--symbolic-full-name", "HEAD"]).output() | ||
25 | { | ||
26 | if let Ok(ref_link) = String::from_utf8(output.stdout) { | ||
27 | println!("cargo:rerun-if-changed={}", git_dir.join(ref_link).display()); | ||
28 | } | ||
29 | } | ||
30 | return; | ||
31 | } | ||
32 | |||
33 | manifest_dir.pop(); | ||
34 | } | ||
35 | println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!"); | ||
36 | } | ||
37 | |||
10 | fn rev() -> Option<String> { | 38 | fn rev() -> Option<String> { |
11 | let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; | 39 | let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; |
12 | let stdout = String::from_utf8(output.stdout).ok()?; | 40 | let stdout = String::from_utf8(output.stdout).ok()?; |
diff --git a/docs/user/features.md b/docs/user/features.md index 309d2775d..a00fa35da 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -89,6 +89,10 @@ Shows the full macro expansion of the macro at current cursor. | |||
89 | 89 | ||
90 | Shows internal statistic about memory usage of rust-analyzer | 90 | Shows internal statistic about memory usage of rust-analyzer |
91 | 91 | ||
92 | #### Show RA Version | ||
93 | |||
94 | Show current rust-analyzer version | ||
95 | |||
92 | #### Run garbage collection | 96 | #### Run garbage collection |
93 | 97 | ||
94 | Manually triggers GC | 98 | Manually triggers GC |
diff --git a/editors/code/package.json b/editors/code/package.json index c498c14b4..72befe2b6 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -131,6 +131,11 @@ | |||
131 | "command": "rust-analyzer.ssr", | 131 | "command": "rust-analyzer.ssr", |
132 | "title": "Structural Search Replace", | 132 | "title": "Structural Search Replace", |
133 | "category": "Rust Analyzer" | 133 | "category": "Rust Analyzer" |
134 | }, | ||
135 | { | ||
136 | "command": "rust-analyzer.serverVersion", | ||
137 | "title": "Show RA Version", | ||
138 | "category": "Rust Analyzer" | ||
134 | } | 139 | } |
135 | ], | 140 | ], |
136 | "keybindings": [ | 141 | "keybindings": [ |
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index bebd99ca9..839245f48 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -13,6 +13,7 @@ export * from './syntax_tree'; | |||
13 | export * from './expand_macro'; | 13 | export * from './expand_macro'; |
14 | export * from './runnables'; | 14 | export * from './runnables'; |
15 | export * from './ssr'; | 15 | export * from './ssr'; |
16 | export * from './server_version'; | ||
16 | 17 | ||
17 | export function collectGarbage(ctx: Ctx): Cmd { | 18 | export function collectGarbage(ctx: Ctx): Cmd { |
18 | return async () => { | 19 | 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 000000000..421301b42 --- /dev/null +++ b/editors/code/src/commands/server_version.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import { ensureServerBinary } from '../installation/server'; | ||
3 | import { Ctx, Cmd } from '../ctx'; | ||
4 | import { spawnSync } from 'child_process'; | ||
5 | |||
6 | export function serverVersion(ctx: Ctx): Cmd { | ||
7 | return async () => { | ||
8 | const binaryPath = await ensureServerBinary(ctx.config.serverSource); | ||
9 | |||
10 | if (binaryPath == null) { | ||
11 | throw new Error( | ||
12 | "Rust Analyzer Language Server is not available. " + | ||
13 | "Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)." | ||
14 | ); | ||
15 | } | ||
16 | |||
17 | const version = spawnSync(binaryPath, ["--version"], { encoding: "utf8" }).stdout; | ||
18 | vscode.window.showInformationMessage('rust-analyzer version : ' + version); | ||
19 | }; | ||
20 | } | ||
21 | |||
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index a22e0bc66..de19a44e5 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -55,6 +55,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
55 | ctx.registerCommand('run', commands.run); | 55 | ctx.registerCommand('run', commands.run); |
56 | ctx.registerCommand('onEnter', commands.onEnter); | 56 | ctx.registerCommand('onEnter', commands.onEnter); |
57 | ctx.registerCommand('ssr', commands.ssr); | 57 | ctx.registerCommand('ssr', commands.ssr); |
58 | ctx.registerCommand('serverVersion', commands.serverVersion); | ||
58 | 59 | ||
59 | // Internal commands which are invoked by the server. | 60 | // Internal commands which are invoked by the server. |
60 | ctx.registerCommand('runSingle', commands.runSingle); | 61 | ctx.registerCommand('runSingle', commands.runSingle); |