From bc560a2f5b323b6b3581b30e97cd8cca792ddb65 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 17:53:07 +0100 Subject: Remove redundant Runnable.range --- editors/code/src/commands/runnables.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c0f2ada76..28ad7a302 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -8,7 +8,6 @@ interface RunnablesParams { } interface Runnable { - range: lc.Range; label: string; bin: string; args: string[]; -- cgit v1.2.3 From 9f1ae658dbb0d091bd384efbab93d622e5fff49f Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 20:47:52 +0100 Subject: Define a cargo watch task --- editors/code/src/commands/runnables.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 28ad7a302..74d664034 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -33,7 +33,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition { env?: { [key: string]: string }; } -function createTask(spec: Runnable): vscode.Task { +export function createTask(spec: Runnable): vscode.Task { const TASK_SOURCE = 'Rust'; const definition: CargoTaskDefinition = { type: 'cargo', @@ -123,3 +123,23 @@ export async function handleSingle(runnable: Runnable) { return vscode.tasks.executeTask(task); } + +export const autoCargoWatchTask: vscode.Task = { + name: 'cargo watch', + source: 'rust-analyzer', + definition: { + type: "dupa", + }, + execution: new vscode.ShellExecution('cargo', ['watch'], { cwd: '.' }), + + isBackground: true, + problemMatchers: ['$rustc-watch'], + presentationOptions: { + clear: true + }, + // Not yet exposed in the vscode.d.ts + runOptions: { + runOn: 2 // RunOnOptions.folderOpen, https://github.com/Microsoft/vscode/blob/ea7c31d770e04b51d586b0d3944f3a7feb03afb9/src/vs/workbench/contrib/tasks/common/tasks.ts#L444-L456 + } as unknown as vscode.RunOptions, + +}; -- cgit v1.2.3 From 21b73f984433ca6ca1500826af59f8dd8bc22618 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 21:04:33 +0100 Subject: Respect the user-provided label when creating task --- editors/code/src/commands/runnables.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 74d664034..c6d23a185 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -37,7 +37,7 @@ export function createTask(spec: Runnable): vscode.Task { const TASK_SOURCE = 'Rust'; const definition: CargoTaskDefinition = { type: 'cargo', - label: 'cargo', + label: spec.label, command: spec.bin, args: spec.args, env: spec.env -- cgit v1.2.3 From 5c3cc8c95f392c523bb638d78e0217780d6e8476 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 22:15:03 +0100 Subject: Reformat using Prettier --- editors/code/src/commands/runnables.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c6d23a185..23fd280b4 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -128,7 +128,7 @@ export const autoCargoWatchTask: vscode.Task = { name: 'cargo watch', source: 'rust-analyzer', definition: { - type: "dupa", + type: 'watch' }, execution: new vscode.ShellExecution('cargo', ['watch'], { cwd: '.' }), @@ -138,8 +138,8 @@ export const autoCargoWatchTask: vscode.Task = { clear: true }, // Not yet exposed in the vscode.d.ts - runOptions: { - runOn: 2 // RunOnOptions.folderOpen, https://github.com/Microsoft/vscode/blob/ea7c31d770e04b51d586b0d3944f3a7feb03afb9/src/vs/workbench/contrib/tasks/common/tasks.ts#L444-L456 - } as unknown as vscode.RunOptions, - + // https://github.com/Microsoft/vscode/blob/ea7c31d770e04b51d586b0d3944f3a7feb03afb9/src/vs/workbench/contrib/tasks/common/tasks.ts#L444-L456 + runOptions: ({ + runOn: 2 // RunOnOptions.folderOpen + } as unknown) as vscode.RunOptions }; -- cgit v1.2.3 From 60cac299640912ad1ad75644bfa0088d7ba6e367 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 22:30:23 +0100 Subject: Separate out the interactive cargo watch procedure --- editors/code/src/commands/runnables.ts | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 23fd280b4..285afaaf6 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -1,5 +1,8 @@ +import { exec } from 'child_process'; +import * as util from 'util'; import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; + import { Server } from '../server'; interface RunnablesParams { @@ -33,7 +36,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition { env?: { [key: string]: string }; } -export function createTask(spec: Runnable): vscode.Task { +function createTask(spec: Runnable): vscode.Task { const TASK_SOURCE = 'Rust'; const definition: CargoTaskDefinition = { type: 'cargo', @@ -143,3 +146,66 @@ export const autoCargoWatchTask: vscode.Task = { runOn: 2 // RunOnOptions.folderOpen } as unknown) as vscode.RunOptions }; + +/** + * Interactively asks the user whether we should run `cargo check` in order to + * provide inline diagnostics; the user is met with a series of dialog boxes + * that, when accepted, allow us to `cargo install cargo-watch` and then run it. + */ +export async function interactivelyStartCargoWatch() { + const execAsync = util.promisify(exec); + + const watch = await vscode.window.showInformationMessage( + 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', + 'yes', + 'no' + ); + if (watch === 'no') { + return; + } + + const { stderr } = await execAsync('cargo watch --version').catch(e => e); + if (stderr.includes('no such subcommand: `watch`')) { + const msg = + 'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)'; + const install = await vscode.window.showInformationMessage( + msg, + 'yes', + 'no' + ); + if (install === 'no') { + return; + } + + const label = 'install-cargo-watch'; + const taskFinished = new Promise((resolve, reject) => { + let disposable = vscode.tasks.onDidEndTask(({ execution }) => { + if (execution.task.name === label) { + disposable.dispose(); + resolve(); + } + }); + }); + + vscode.tasks.executeTask( + createTask({ + label, + bin: 'cargo', + args: ['install', 'cargo-watch'], + env: {} + }) + ); + await taskFinished; + const { stderr } = await execAsync('cargo watch --version').catch( + e => e + ); + if (stderr !== '') { + vscode.window.showErrorMessage( + `Couldn't install \`cargo-\`watch: ${stderr}` + ); + return; + } + } + + vscode.tasks.executeTask(autoCargoWatchTask); +} -- cgit v1.2.3 From 7c2595c26820917fa9ad1b1c36f01fc6ac979287 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 22:35:47 +0100 Subject: Guard auto cargo watch behind a config option --- editors/code/src/commands/runnables.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 285afaaf6..74407dc3e 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -153,6 +153,10 @@ export const autoCargoWatchTask: vscode.Task = { * that, when accepted, allow us to `cargo install cargo-watch` and then run it. */ export async function interactivelyStartCargoWatch() { + if (!Server.config.enableCargoWatchOnStartup) { + return; + } + const execAsync = util.promisify(exec); const watch = await vscode.window.showInformationMessage( -- cgit v1.2.3 From 34b428cc5e4b37ecd44063547f73fd1b05bf2b9e Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 22:51:01 +0100 Subject: Appease CI --- editors/code/src/commands/runnables.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 74407dc3e..ea2883ad4 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -1,4 +1,4 @@ -import { exec } from 'child_process'; +import * as child_process from 'child_process'; import * as util from 'util'; import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; @@ -157,7 +157,7 @@ export async function interactivelyStartCargoWatch() { return; } - const execAsync = util.promisify(exec); + const execPromise = util.promisify(child_process.exec); const watch = await vscode.window.showInformationMessage( 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', @@ -168,7 +168,7 @@ export async function interactivelyStartCargoWatch() { return; } - const { stderr } = await execAsync('cargo watch --version').catch(e => e); + const { stderr } = await execPromise('cargo watch --version').catch(e => e); if (stderr.includes('no such subcommand: `watch`')) { const msg = 'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)'; @@ -183,7 +183,7 @@ export async function interactivelyStartCargoWatch() { const label = 'install-cargo-watch'; const taskFinished = new Promise((resolve, reject) => { - let disposable = vscode.tasks.onDidEndTask(({ execution }) => { + const disposable = vscode.tasks.onDidEndTask(({ execution }) => { if (execution.task.name === label) { disposable.dispose(); resolve(); @@ -200,12 +200,10 @@ export async function interactivelyStartCargoWatch() { }) ); await taskFinished; - const { stderr } = await execAsync('cargo watch --version').catch( - e => e - ); - if (stderr !== '') { + const output = await execPromise('cargo watch --version').catch(e => e); + if (output.stderr !== '') { vscode.window.showErrorMessage( - `Couldn't install \`cargo-\`watch: ${stderr}` + `Couldn't install \`cargo-\`watch: ${output.stderr}` ); return; } -- cgit v1.2.3