aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-05-05 23:22:02 +0100
committerCraig Disselkoen <[email protected]>2020-05-06 00:12:56 +0100
commita78dd06951dffcc6ff69aec21a2d8224c12f5026 (patch)
treef96585d3d63c86dee8f179f37507c2ec853ab4c7
parent3e603a8fdd207f9ad5a2ad2898350f54d5bc2fb8 (diff)
Preliminary refactoring of cargo.ts
-rw-r--r--editors/code/src/cargo.ts45
-rw-r--r--editors/code/src/commands/runnables.ts7
2 files changed, 19 insertions, 33 deletions
diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts
index a328ba9bd..613aa82da 100644
--- a/editors/code/src/cargo.ts
+++ b/editors/code/src/cargo.ts
@@ -10,17 +10,9 @@ interface CompilationArtifact {
10} 10}
11 11
12export class Cargo { 12export class Cargo {
13 rootFolder: string; 13 constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
14 env?: Record<string, string>;
15 output: OutputChannel;
16 14
17 public constructor(cargoTomlFolder: string, output: OutputChannel, env: Record<string, string> | undefined = undefined) { 15 private async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
18 this.rootFolder = cargoTomlFolder;
19 this.output = output;
20 this.env = env;
21 }
22
23 public async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
24 const artifacts: CompilationArtifact[] = []; 16 const artifacts: CompilationArtifact[] = [];
25 17
26 try { 18 try {
@@ -37,17 +29,13 @@ export class Cargo {
37 isTest: message.profile.test 29 isTest: message.profile.test
38 }); 30 });
39 } 31 }
40 } 32 } else if (message.reason === 'compiler-message') {
41 else if (message.reason === 'compiler-message') {
42 this.output.append(message.message.rendered); 33 this.output.append(message.message.rendered);
43 } 34 }
44 }, 35 },
45 stderr => { 36 stderr => this.output.append(stderr),
46 this.output.append(stderr);
47 }
48 ); 37 );
49 } 38 } catch (err) {
50 catch (err) {
51 this.output.show(true); 39 this.output.show(true);
52 throw new Error(`Cargo invocation has failed: ${err}`); 40 throw new Error(`Cargo invocation has failed: ${err}`);
53 } 41 }
@@ -55,9 +43,8 @@ export class Cargo {
55 return artifacts; 43 return artifacts;
56 } 44 }
57 45
58 public async executableFromArgs(args: string[]): Promise<string> { 46 async executableFromArgs(args: readonly string[]): Promise<string> {
59 const cargoArgs = [...args]; // to remain args unchanged 47 const cargoArgs = [...args, "--message-format=json"];
60 cargoArgs.push("--message-format=json");
61 48
62 const artifacts = await this.artifactsFromArgs(cargoArgs); 49 const artifacts = await this.artifactsFromArgs(cargoArgs);
63 50
@@ -70,24 +57,20 @@ export class Cargo {
70 return artifacts[0].fileName; 57 return artifacts[0].fileName;
71 } 58 }
72 59
73 runCargo( 60 private runCargo(
74 cargoArgs: string[], 61 cargoArgs: string[],
75 onStdoutJson: (obj: any) => void, 62 onStdoutJson: (obj: any) => void,
76 onStderrString: (data: string) => void 63 onStderrString: (data: string) => void
77 ): Promise<number> { 64 ): Promise<number> {
78 return new Promise<number>((resolve, reject) => { 65 return new Promise((resolve, reject) => {
79 const cargo = cp.spawn('cargo', cargoArgs, { 66 const cargo = cp.spawn('cargo', cargoArgs, {
80 stdio: ['ignore', 'pipe', 'pipe'], 67 stdio: ['ignore', 'pipe', 'pipe'],
81 cwd: this.rootFolder, 68 cwd: this.rootFolder
82 env: this.env,
83 }); 69 });
84 70
85 cargo.on('error', err => { 71 cargo.on('error', err => reject(new Error(`could not launch cargo: ${err}`)));
86 reject(new Error(`could not launch cargo: ${err}`)); 72
87 }); 73 cargo.stderr.on('data', chunk => onStderrString(chunk.toString()));
88 cargo.stderr.on('data', chunk => {
89 onStderrString(chunk.toString());
90 });
91 74
92 const rl = readline.createInterface({ input: cargo.stdout }); 75 const rl = readline.createInterface({ input: cargo.stdout });
93 rl.on('line', line => { 76 rl.on('line', line => {
@@ -103,4 +86,4 @@ export class Cargo {
103 }); 86 });
104 }); 87 });
105 } 88 }
106} \ No newline at end of file 89}
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index d77e8188c..2ed150e25 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -119,8 +119,11 @@ export function debugSingle(ctx: Ctx): Cmd {
119 } 119 }
120 120
121 if (!debugEngine) { 121 if (!debugEngine) {
122 vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})` 122 vscode.window.showErrorMessage(
123 + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`); 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 );
124 return; 127 return;
125 } 128 }
126 129