From 4e48a73f9c342544e4eabd1c1cd31cdfb6a6e5e3 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 21 Feb 2020 10:04:03 +0800 Subject: Improve server version info --- editors/code/src/commands/index.ts | 1 + editors/code/src/commands/server_version.ts | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 editors/code/src/commands/server_version.ts (limited to 'editors/code/src/commands') 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'; 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 000000000..3a982a418 --- /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 -- cgit v1.2.3 From e7a0d8f8d0ab4b03e1d85fce2973bdc50d0391c0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 20 Feb 2020 16:49:31 +0800 Subject: Add trailing newline --- editors/code/src/commands/server_version.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/server_version.ts b/editors/code/src/commands/server_version.ts index 3a982a418..307408a37 100644 --- a/editors/code/src/commands/server_version.ts +++ b/editors/code/src/commands/server_version.ts @@ -6,4 +6,5 @@ export function serverVersion(): Cmd { return () => { vscode.window.showInformationMessage('rust-analyzer version : ' + ServerVersion); }; -} \ No newline at end of file +} + -- cgit v1.2.3 From 489be40d3a6181b0eb0ee71e8b399692b639baf4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 21 Feb 2020 09:57:24 +0800 Subject: Use ensureServerBinary instead --- editors/code/src/commands/server_version.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/server_version.ts b/editors/code/src/commands/server_version.ts index 307408a37..34c18bf3b 100644 --- a/editors/code/src/commands/server_version.ts +++ b/editors/code/src/commands/server_version.ts @@ -1,10 +1,22 @@ import * as vscode from 'vscode'; -import { ServerVersion } from '../installation/server'; -import { Cmd } from '../ctx'; +import { ensureServerBinary } from '../installation/server'; +import { Ctx, Cmd } from '../ctx'; +import { spawnSync } from 'child_process'; -export function serverVersion(): Cmd { - return () => { - vscode.window.showInformationMessage('rust-analyzer version : ' + ServerVersion); +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 res = spawnSync(binaryPath, ["--version"]); + const version = res.output?.filter(x => x !== null).map(String).join(" "); + vscode.window.showInformationMessage('rust-analyzer version : ' + version); }; } -- cgit v1.2.3 From 319a09847b47086b73ea7184ee39b3be0b924c60 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 21 Feb 2020 15:51:55 +0800 Subject: Use stdout directly --- editors/code/src/commands/server_version.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/server_version.ts b/editors/code/src/commands/server_version.ts index 34c18bf3b..421301b42 100644 --- a/editors/code/src/commands/server_version.ts +++ b/editors/code/src/commands/server_version.ts @@ -14,8 +14,7 @@ export function serverVersion(ctx: Ctx): Cmd { ); } - const res = spawnSync(binaryPath, ["--version"]); - const version = res.output?.filter(x => x !== null).map(String).join(" "); + const version = spawnSync(binaryPath, ["--version"], { encoding: "utf8" }).stdout; vscode.window.showInformationMessage('rust-analyzer version : ' + version); }; } -- cgit v1.2.3