Skip to content

Commit a78dd06

Browse files
Veetahacdisselkoen
authored andcommitted
Preliminary refactoring of cargo.ts
1 parent 3e603a8 commit a78dd06

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

editors/code/src/cargo.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@ interface CompilationArtifact {
1010
}
1111

1212
export class Cargo {
13-
rootFolder: string;
14-
env?: Record<string, string>;
15-
output: OutputChannel;
13+
constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
1614

17-
public constructor(cargoTomlFolder: string, output: OutputChannel, env: Record<string, string> | undefined = undefined) {
18-
this.rootFolder = cargoTomlFolder;
19-
this.output = output;
20-
this.env = env;
21-
}
22-
23-
public async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
15+
private async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
2416
const artifacts: CompilationArtifact[] = [];
2517

2618
try {
@@ -37,27 +29,22 @@ export class Cargo {
3729
isTest: message.profile.test
3830
});
3931
}
40-
}
41-
else if (message.reason === 'compiler-message') {
32+
} else if (message.reason === 'compiler-message') {
4233
this.output.append(message.message.rendered);
4334
}
4435
},
45-
stderr => {
46-
this.output.append(stderr);
47-
}
36+
stderr => this.output.append(stderr),
4837
);
49-
}
50-
catch (err) {
38+
} catch (err) {
5139
this.output.show(true);
5240
throw new Error(`Cargo invocation has failed: ${err}`);
5341
}
5442

5543
return artifacts;
5644
}
5745

58-
public async executableFromArgs(args: string[]): Promise<string> {
59-
const cargoArgs = [...args]; // to remain args unchanged
60-
cargoArgs.push("--message-format=json");
46+
async executableFromArgs(args: readonly string[]): Promise<string> {
47+
const cargoArgs = [...args, "--message-format=json"];
6148

6249
const artifacts = await this.artifactsFromArgs(cargoArgs);
6350

@@ -70,24 +57,20 @@ export class Cargo {
7057
return artifacts[0].fileName;
7158
}
7259

73-
runCargo(
60+
private runCargo(
7461
cargoArgs: string[],
7562
onStdoutJson: (obj: any) => void,
7663
onStderrString: (data: string) => void
7764
): Promise<number> {
78-
return new Promise<number>((resolve, reject) => {
65+
return new Promise((resolve, reject) => {
7966
const cargo = cp.spawn('cargo', cargoArgs, {
8067
stdio: ['ignore', 'pipe', 'pipe'],
81-
cwd: this.rootFolder,
82-
env: this.env,
68+
cwd: this.rootFolder
8369
});
8470

85-
cargo.on('error', err => {
86-
reject(new Error(`could not launch cargo: ${err}`));
87-
});
88-
cargo.stderr.on('data', chunk => {
89-
onStderrString(chunk.toString());
90-
});
71+
cargo.on('error', err => reject(new Error(`could not launch cargo: ${err}`)));
72+
73+
cargo.stderr.on('data', chunk => onStderrString(chunk.toString()));
9174

9275
const rl = readline.createInterface({ input: cargo.stdout });
9376
rl.on('line', line => {
@@ -103,4 +86,4 @@ export class Cargo {
10386
});
10487
});
10588
}
106-
}
89+
}

editors/code/src/commands/runnables.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ export function debugSingle(ctx: Ctx): Cmd {
119119
}
120120

121121
if (!debugEngine) {
122-
vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})`
123-
+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`);
122+
vscode.window.showErrorMessage(
123+
`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId}) ` +
124+
`or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) ` +
125+
`extension for debugging.`
126+
);
124127
return;
125128
}
126129

0 commit comments

Comments
 (0)