Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Removed the "features" property.
Browse files Browse the repository at this point in the history
Added properties passed to a cargo invocation
Fixes #11
  • Loading branch information
KalitaAlexey committed Dec 23, 2016
1 parent 3a42a65 commit 63ef635
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 14 deletions.
26 changes: 23 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,30 @@
"default": "check",
"description": "Choose between check, check-lib, clippy, build and test to lint"
},
"rust.features": {
"rust.buildArgs": {
"type": "array",
"default": [],
"description": "List of feature flags passed to cargo"
"description": "Arguments which is passed to cargo build"
},
"rust.checkArgs": {
"type": "array",
"default": [],
"description": "Arguments which is passed to cargo check"
},
"rust.clippyArgs": {
"type": "array",
"default": [],
"description": "Arguments which is passed to cargo clippy"
},
"rust.runArgs": {
"type": "array",
"default": [],
"description": "Arguments which is passed to cargo run"
},
"rust.testArgs": {
"type": "array",
"default": [],
"description": "Arguments which is passed to cargo test"
}
}
},
Expand Down Expand Up @@ -312,4 +332,4 @@
"find-up": "^1.1.2",
"elegant-spinner": "^1.0.1"
}
}
}
74 changes: 63 additions & 11 deletions src/services/commandService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export class CommandService {
});
}

private static getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration('rust');
}

private static determineExampleName(): string {
let showDocumentIsNotExampleWarning = () => {
vscode.window.showWarningMessage('Current document is not an example');
Expand All @@ -272,81 +276,129 @@ export class CommandService {
}

private static buildProject(buildType: BuildType): void {
let args = ['build', '--message-format', 'json'];
const args = ['build', '--message-format', 'json'];

if (buildType === BuildType.Release) {
args.push('--release');
}

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('buildArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

private static checkProject(target: CheckTarget): void {
this.checkCargoCheckAvailability().then(isAvailable => {
let args: string[];

if (isAvailable) {
let args = ['check'];
args = ['check'];

if (target === CheckTarget.Library) {
args.push('--lib');
}
this.runCargo(args, true);

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('checkArgs');

args.push(...userDefinedArgs);
} else {
let args = ['rustc'];
args = ['rustc'];

if (target === CheckTarget.Library) {
args.push('--lib');
}

args.push('--', '-Zno-trans');
this.runCargo(args, true);
}

this.runCargo(args, true);
});
}

private static checkProjectWithClippy(): void {
const args = ['clippy'];

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('clippyArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

private static runProject(buildType: BuildType): void {
let args = ['run'];
const args = ['run'];

if (buildType === BuildType.Release) {
args.push('--release');
}

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('runArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

private static testProject(buildType: BuildType): void {
let args = ['test'];
const args = ['test'];

if (buildType === BuildType.Release) {
args.push('--release');
}

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('testArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

private static buildExample(release: boolean): void {
let exampleName = this.determineExampleName();
const exampleName = this.determineExampleName();

if (exampleName.length === 0) {
return;
}
let args = ['build', '--example', exampleName];

const args = ['build', '--example', exampleName];

if (release) {
args.push('--release');
}

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('buildArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

private static runExample(release: boolean): void {
let exampleName = this.determineExampleName();
const exampleName = this.determineExampleName();

if (exampleName.length === 0) {
return;
}
let args = ['run', '--example', exampleName];

const args = ['run', '--example', exampleName];

if (release) {
args.push('--release');
}

const configuration = this.getConfiguration();
const userDefinedArgs: string[] = configuration.get<string[]>('runArgs');

args.push(...userDefinedArgs);

this.runCargo(args, true);
}

Expand Down

0 comments on commit 63ef635

Please sign in to comment.