about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorveetaha <veetaha2@gmail.com>2020-05-06 01:22:02 +0300
committerCraig Disselkoen <craigdissel@gmail.com>2020-05-05 16:12:56 -0700
commita78dd06951dffcc6ff69aec21a2d8224c12f5026 (patch)
treef96585d3d63c86dee8f179f37507c2ec853ab4c7 /editors/code/src
parent3e603a8fdd207f9ad5a2ad2898350f54d5bc2fb8 (diff)
downloadrust-a78dd06951dffcc6ff69aec21a2d8224c12f5026.tar.gz
rust-a78dd06951dffcc6ff69aec21a2d8224c12f5026.zip
Preliminary refactoring of cargo.ts
Diffstat (limited to 'editors/code/src')
-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 a328ba9bd01..613aa82da9a 100644
--- a/editors/code/src/cargo.ts
+++ b/editors/code/src/cargo.ts
@@ -10,17 +10,9 @@ interface CompilationArtifact {
 }
 
 export class Cargo {
-    rootFolder: string;
-    env?: Record<string, string>;
-    output: OutputChannel;
+    constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
 
-    public constructor(cargoTomlFolder: string, output: OutputChannel, env: Record<string, string> | undefined = undefined) {
-        this.rootFolder = cargoTomlFolder;
-        this.output = output;
-        this.env = env;
-    }
-
-    public async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
+    private async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> {
         const artifacts: CompilationArtifact[] = [];
 
         try {
@@ -37,17 +29,13 @@ export class Cargo {
                                 isTest: message.profile.test
                             });
                         }
-                    }
-                    else if (message.reason === 'compiler-message') {
+                    } else if (message.reason === 'compiler-message') {
                         this.output.append(message.message.rendered);
                     }
                 },
-                stderr => {
-                    this.output.append(stderr);
-                }
+                stderr => this.output.append(stderr),
             );
-        }
-        catch (err) {
+        } catch (err) {
             this.output.show(true);
             throw new Error(`Cargo invocation has failed: ${err}`);
         }
@@ -55,9 +43,8 @@ export class Cargo {
         return artifacts;
     }
 
-    public async executableFromArgs(args: string[]): Promise<string> {
-        const cargoArgs = [...args]; // to remain  args unchanged
-        cargoArgs.push("--message-format=json");
+    async executableFromArgs(args: readonly string[]): Promise<string> {
+        const cargoArgs = [...args, "--message-format=json"];
 
         const artifacts = await this.artifactsFromArgs(cargoArgs);
 
@@ -70,24 +57,20 @@ export class Cargo {
         return artifacts[0].fileName;
     }
 
-    runCargo(
+    private runCargo(
         cargoArgs: string[],
         onStdoutJson: (obj: any) => void,
         onStderrString: (data: string) => void
     ): Promise<number> {
-        return new Promise<number>((resolve, reject) => {
+        return new Promise((resolve, reject) => {
             const cargo = cp.spawn('cargo', cargoArgs, {
                 stdio: ['ignore', 'pipe', 'pipe'],
-                cwd: this.rootFolder,
-                env: this.env,
+                cwd: this.rootFolder
             });
 
-            cargo.on('error', err => {
-                reject(new Error(`could not launch cargo: ${err}`));
-            });
-            cargo.stderr.on('data', chunk => {
-                onStderrString(chunk.toString());
-            });
+            cargo.on('error', err => reject(new Error(`could not launch cargo: ${err}`)));
+
+            cargo.stderr.on('data', chunk => onStderrString(chunk.toString()));
 
             const rl = readline.createInterface({ input: cargo.stdout });
             rl.on('line', line => {
@@ -103,4 +86,4 @@ export class Cargo {
             });
         });
     }
-}
\ No newline at end of file
+}
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index d77e8188c75..2ed150e25f2 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 {
         }
 
         if (!debugEngine) {
-            vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})`
-                + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`);
+            vscode.window.showErrorMessage(
+                `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId}) ` +
+                `or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) ` +
+                `extension for debugging.`
+            );
             return;
         }