Skip to content

Commit 48472f5

Browse files
bors[bot]vipentti
andcommitted
Merge #1010
1010: Change enableCargoWatchOnStartup to have three states r=matklad a=vipentti 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. Co-authored-by: Ville Penttinen <[email protected]>
2 parents aa0cc0c + 5c3e9c7 commit 48472f5

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

editors/code/package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,19 @@
169169
"description": "Path to ra_lsp_server executable"
170170
},
171171
"rust-analyzer.enableCargoWatchOnStartup": {
172-
"type": "boolean",
173-
"default": "true",
174-
"description": "When enabled, ask the user whether to run `cargo watch` on startup"
172+
"type": "string",
173+
"default": "ask",
174+
"enum": [
175+
"ask",
176+
"enabled",
177+
"disabled"
178+
],
179+
"enumDescriptions": [
180+
"Asks each time whether to run `cargo watch`",
181+
"`cargo watch` is always started",
182+
"Don't start `cargo watch`"
183+
],
184+
"description": "Whether to run `cargo watch` on startup"
175185
},
176186
"rust-analyzer.trace.server": {
177187
"type": "string",

editors/code/src/commands/runnables.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,25 @@ export const autoCargoWatchTask: vscode.Task = {
153153
* that, when accepted, allow us to `cargo install cargo-watch` and then run it.
154154
*/
155155
export async function interactivelyStartCargoWatch() {
156-
if (!Server.config.enableCargoWatchOnStartup) {
156+
if (Server.config.enableCargoWatchOnStartup === 'disabled') {
157157
return;
158158
}
159159

160-
const execPromise = util.promisify(child_process.exec);
161-
162-
const watch = await vscode.window.showInformationMessage(
163-
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
164-
'yes',
165-
'no'
166-
);
167-
if (watch === 'no') {
168-
return;
160+
if (Server.config.enableCargoWatchOnStartup === 'ask') {
161+
const watch = await vscode.window.showInformationMessage(
162+
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
163+
'yes',
164+
'no'
165+
);
166+
if (watch === 'no') {
167+
return;
168+
}
169169
}
170170

171+
const execPromise = util.promisify(child_process.exec);
172+
171173
const { stderr } = await execPromise('cargo watch --version').catch(e => e);
174+
172175
if (stderr.includes('no such subcommand: `watch`')) {
173176
const msg =
174177
'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)';

editors/code/src/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { Server } from './server';
44

55
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
66

7+
export type CargoWatchOptions = 'ask' | 'enabled' | 'disabled';
8+
79
export class Config {
810
public highlightingOn = true;
911
public enableEnhancedTyping = true;
1012
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
1113
public showWorkspaceLoadedNotification = true;
12-
public enableCargoWatchOnStartup = true;
14+
public enableCargoWatchOnStartup: CargoWatchOptions = 'ask';
1315

1416
private prevEnhancedTyping: null | boolean = null;
1517

@@ -71,9 +73,9 @@ export class Config {
7173
}
7274

7375
if (config.has('enableCargoWatchOnStartup')) {
74-
this.enableCargoWatchOnStartup = config.get<boolean>(
76+
this.enableCargoWatchOnStartup = config.get<CargoWatchOptions>(
7577
'enableCargoWatchOnStartup',
76-
true
78+
'ask'
7779
);
7880
}
7981
}

0 commit comments

Comments
 (0)