diff --git a/package.json b/package.json index 8569c26..e769eb7 100644 --- a/package.json +++ b/package.json @@ -239,15 +239,17 @@ "default": false, "description": "Turn on/off autoformatting file on save" }, - "rust.checkOnSave": { - "type": "boolean", - "default": false, - "description": "Turn on/off autochecking file on save using cargo check" - }, - "rust.checkWith": { + "rust.actionOnSave": { "type": "string", - "default": "check", - "description": "Choose between check, check-lib, clippy, build and test to lint" + "default": null, + "enum": [ + "build", + "check", + "clippy", + "run", + "test", + null + ] }, "rust.buildArgs": { "type": "array", diff --git a/src/extension.ts b/src/extension.ts index a6863e7..ac67055 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -92,26 +92,35 @@ export function activate(ctx: vscode.ExtensionContext): void { }); } - if (rustConfig['checkOnSave']) { - formatPromise.then(() => { - switch (rustConfig['checkWith']) { - case 'clippy': - vscode.commands.executeCommand('rust.cargo.clippy'); - break; - case 'build': - vscode.commands.executeCommand('rust.cargo.build.debug'); - break; - case 'check-lib': - vscode.commands.executeCommand('rust.cargo.check.lib'); - break; - case 'test': - vscode.commands.executeCommand('rust.cargo.test.debug'); - break; - default: - vscode.commands.executeCommand('rust.cargo.check'); - } - }); + const actionOnSave: string | null = rustConfig['actionOnSave']; + + if (actionOnSave === null) { + return; } + + let command: string; + + switch (actionOnSave) { + case 'build': + command = 'rust.cargo.build.debug'; + break; + case 'check': + command = 'rust.cargo.check'; + break; + case 'clippy': + command = 'rust.cargo.clippy'; + break; + case 'run': + command = 'rust.cargo.run.debug'; + break; + case 'test': + command = 'rust.cargo.test.debug'; + break; + } + + formatPromise.then(() => { + vscode.commands.executeCommand(command); + }); })); // Watch for configuration changes for ENV