Skip to content

Commit 364ac9b

Browse files
bors[bot]Aleksei Sidorovalekseysidorov
committed
Merge #1434
1434: Introduce cargo-watch.check-command option for Code extension r=matklad a=alekseysidorov By this option you can replace `check` command in `cargo watch` by the something else like `clippy`. Co-authored-by: Aleksei Sidorov <[email protected]> Co-authored-by: Aleksey Sidorov <[email protected]>
2 parents f634002 + 28e9e8d commit 364ac9b

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

editors/code/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,16 @@
201201
],
202202
"description": "Whether to run `cargo watch` on startup"
203203
},
204-
"rust-analyzer.cargo-watch.check-arguments": {
204+
"rust-analyzer.cargo-watch.arguments": {
205205
"type": "string",
206-
"description": "`cargo-watch` check arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
206+
"description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
207207
"default": ""
208208
},
209+
"rust-analyzer.cargo-watch.command": {
210+
"type": "string",
211+
"description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )",
212+
"default": "check"
213+
},
209214
"rust-analyzer.trace.server": {
210215
"type": "string",
211216
"scope": "window",

editors/code/src/commands/cargo_watch.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export class CargoWatchProvider implements vscode.Disposable {
4343
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
4444
'rustc'
4545
);
46-
this.statusDisplay = new StatusDisplay();
46+
this.statusDisplay = new StatusDisplay(
47+
Server.config.cargoWatchOptions.command
48+
);
4749
this.outputChannel = vscode.window.createOutputChannel(
4850
'Cargo Watch Trace'
4951
);
@@ -57,10 +59,12 @@ export class CargoWatchProvider implements vscode.Disposable {
5759
return;
5860
}
5961

60-
let args = 'check --all-targets --message-format json';
61-
if (Server.config.cargoWatchOptions.checkArguments.length > 0) {
62+
let args =
63+
Server.config.cargoWatchOptions.command +
64+
' --all-targets --message-format json';
65+
if (Server.config.cargoWatchOptions.command.length > 0) {
6266
// Excape the double quote string:
63-
args += ' ' + Server.config.cargoWatchOptions.checkArguments;
67+
args += ' ' + Server.config.cargoWatchOptions.arguments;
6468
}
6569
// Windows handles arguments differently than the unix-likes, so we need to wrap the args in double quotes
6670
if (process.platform === 'win32') {

editors/code/src/commands/watch_status.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export class StatusDisplay implements vscode.Disposable {
77

88
private i = 0;
99
private statusBarItem: vscode.StatusBarItem;
10+
private command: string;
1011
private timer?: NodeJS.Timeout;
1112

12-
constructor() {
13+
constructor(command: string) {
1314
this.statusBarItem = vscode.window.createStatusBarItem(
1415
vscode.StatusBarAlignment.Left,
1516
10
1617
);
18+
this.command = command;
1719
this.statusBarItem.hide();
1820
}
1921

@@ -24,11 +26,13 @@ export class StatusDisplay implements vscode.Disposable {
2426
this.timer ||
2527
setInterval(() => {
2628
if (this.packageName) {
27-
this.statusBarItem!.text = `cargo check [${
29+
this.statusBarItem!.text = `cargo ${this.command} [${
2830
this.packageName
2931
}] ${this.frame()}`;
3032
} else {
31-
this.statusBarItem!.text = `cargo check ${this.frame()}`;
33+
this.statusBarItem!.text = `cargo ${
34+
this.command
35+
} ${this.frame()}`;
3236
}
3337
}, 300);
3438

editors/code/src/config.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22

3+
import { strict } from 'assert';
34
import { Server } from './server';
45

56
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
@@ -9,7 +10,8 @@ export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
910

1011
export interface CargoWatchOptions {
1112
enableOnStartup: CargoWatchStartupOptions;
12-
checkArguments: string;
13+
arguments: string;
14+
command: string;
1315
trace: CargoWatchTraceOptions;
1416
}
1517

@@ -23,7 +25,8 @@ export class Config {
2325
public cargoWatchOptions: CargoWatchOptions = {
2426
enableOnStartup: 'ask',
2527
trace: 'off',
26-
checkArguments: ''
28+
arguments: '',
29+
command: ''
2730
};
2831

2932
private prevEnhancedTyping: null | boolean = null;
@@ -104,12 +107,20 @@ export class Config {
104107
);
105108
}
106109

107-
if (config.has('cargo-watch.check-arguments')) {
108-
this.cargoWatchOptions.checkArguments = config.get<string>(
109-
'cargo-watch.check-arguments',
110+
if (config.has('cargo-watch.arguments')) {
111+
this.cargoWatchOptions.arguments = config.get<string>(
112+
'cargo-watch.arguments',
110113
''
111114
);
112115
}
116+
117+
if (config.has('cargo-watch.command')) {
118+
this.cargoWatchOptions.command = config.get<string>(
119+
'cargo-watch.command',
120+
''
121+
);
122+
}
123+
113124
if (config.has('lruCapacity')) {
114125
this.lruCapacity = config.get('lruCapacity') as number;
115126
}

0 commit comments

Comments
 (0)