Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/toolchain.ts')
-rw-r--r--editors/code/src/toolchain.ts19
1 files changed, 12 insertions, 7 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index 917a1d6b09..58e5fc747a 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -4,6 +4,8 @@ import * as path from "path";
import * as readline from "readline";
import * as vscode from "vscode";
import { execute, log, memoizeAsync } from "./util";
+import { unwrapNullable } from "./nullable";
+import { unwrapUndefinable } from "./undefinable";
interface CompilationArtifact {
fileName: string;
@@ -21,7 +23,7 @@ export class Cargo {
constructor(
readonly rootFolder: string,
readonly output: vscode.OutputChannel,
- readonly env: Record<string, string>
+ readonly env: Record<string, string>,
) {}
// Made public for testing purposes
@@ -74,7 +76,7 @@ export class Cargo {
this.output.append(message.message.rendered);
}
},
- (stderr) => this.output.append(stderr)
+ (stderr) => this.output.append(stderr),
);
} catch (err) {
this.output.show(true);
@@ -93,13 +95,14 @@ export class Cargo {
throw new Error("Multiple compilation artifacts are not supported.");
}
- return artifacts[0].fileName;
+ const artifact = unwrapUndefinable(artifacts[0]);
+ return artifact.fileName;
}
private async runCargo(
cargoArgs: string[],
onStdoutJson: (obj: any) => void,
- onStderrString: (data: string) => void
+ onStderrString: (data: string) => void,
): Promise<number> {
const path = await cargoPath();
return await new Promise((resolve, reject) => {
@@ -142,7 +145,9 @@ export async function getRustcId(dir: string): Promise<string> {
const data = await execute(`${rustcPath} -V -v`, { cwd: dir });
const rx = /commit-hash:\s(.*)$/m;
- return rx.exec(data)![1];
+ const result = unwrapNullable(rx.exec(data));
+ const first = unwrapUndefinable(result[1]);
+ return first;
}
/** Mirrors `toolchain::cargo()` implementation */
@@ -167,11 +172,11 @@ export const getPathForExecutable = memoizeAsync(
if (await isFileAtUri(standardPath)) return standardPath.fsPath;
}
return executableName;
- }
+ },
);
async function lookupInPath(exec: string): Promise<boolean> {
- const paths = process.env.PATH ?? "";
+ const paths = process.env["PATH"] ?? "";
const candidates = paths.split(path.delimiter).flatMap((dirInPath) => {
const candidate = path.join(dirInPath, exec);