From 5c3e9c716e11a0b795d484403289fe9940b7efda Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Thu, 21 Mar 2019 13:56:25 +0200 Subject: [PATCH] Change enableCargoWatchOnStartup to have three states This fixes #1005. Defaults to `ask` which prompts users each time whether to start `cargo watch` or not. `enabled` always starts `cargo watch` and `disabled` does not. --- editors/code/package.json | 16 +++++++++++++--- editors/code/src/commands/runnables.ts | 23 +++++++++++++---------- editors/code/src/config.ts | 8 +++++--- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index 3e8cde3880..facb633d9a 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -169,9 +169,19 @@ "description": "Path to ra_lsp_server executable" }, "rust-analyzer.enableCargoWatchOnStartup": { - "type": "boolean", - "default": "true", - "description": "When enabled, ask the user whether to run `cargo watch` on startup" + "type": "string", + "default": "ask", + "enum": [ + "ask", + "enabled", + "disabled" + ], + "enumDescriptions": [ + "Asks each time whether to run `cargo watch`", + "`cargo watch` is always started", + "Don't start `cargo watch`" + ], + "description": "Whether to run `cargo watch` on startup" }, "rust-analyzer.trace.server": { "type": "string", diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index ea2883ad4c..420635f41f 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -153,22 +153,25 @@ 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) { + if (Server.config.enableCargoWatchOnStartup === 'disabled') { return; } + if (Server.config.enableCargoWatchOnStartup === 'ask') { + const watch = await vscode.window.showInformationMessage( + 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', + 'yes', + 'no' + ); + if (watch === 'no') { + return; + } + } + const execPromise = util.promisify(child_process.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 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)'; diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index d8795f3b0f..4205890684 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -4,12 +4,14 @@ import { Server } from './server'; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; +export type CargoWatchOptions = 'ask' | 'enabled' | 'disabled'; + export class Config { public highlightingOn = true; public enableEnhancedTyping = true; public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; public showWorkspaceLoadedNotification = true; - public enableCargoWatchOnStartup = true; + public enableCargoWatchOnStartup: CargoWatchOptions = 'ask'; private prevEnhancedTyping: null | boolean = null; @@ -71,9 +73,9 @@ export class Config { } if (config.has('enableCargoWatchOnStartup')) { - this.enableCargoWatchOnStartup = config.get( + this.enableCargoWatchOnStartup = config.get( 'enableCargoWatchOnStartup', - true + 'ask' ); } }