Skip to content

Commit

Permalink
vscode: Pass extra env when validating (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
SWW13 authored Nov 2, 2023
1 parent c9a61dd commit 4b611d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Ctx {

log.info("Using server binary at", binary.path);

if (!isValidExecutable(binary.path)) {
if (!isValidExecutable(binary.path, this.config.serverExtraEnv)) {
if (this.config.serverPath) {
throw new Error(`Failed to execute ${binary.path} --version. \`config.server.path\` has been set explicitly.\
Consider removing this config or making a valid server binary available at that path.`);
Expand Down Expand Up @@ -166,7 +166,7 @@ export class Ctx {
});
});

if (code != 0) {
if (code !== 0) {
let e = new Error(`cargo --version: failed (${code})`);
// Smuggle details.
(e as any).details = err;
Expand Down Expand Up @@ -230,13 +230,13 @@ export class Ctx {

let output = JSON.parse(data) as ReasonOutput;

if (output.reason == "compiler-artifact") {
if (output.reason === "compiler-artifact") {
let artifact = output as CompilerArtifact;
this.statusBar.text = `rune: cargo (${artifact.target.name})`;

let [id, ...rest] = artifact.package_id.split(" ");

if (id == name && artifact.target.kind.includes("bin")) {
if (id === name && artifact.target.kind.includes("bin")) {
executable = artifact.executable;
}
}
Expand Down
8 changes: 6 additions & 2 deletions editors/code/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import { strict as nativeAssert } from "assert";
import { exec, ExecOptions, spawnSync } from "child_process";
import { Env, substituteVariablesInEnv } from "./config";
import { inspect } from "util";

export function assert(condition: boolean, explanation: string): asserts condition {
Expand Down Expand Up @@ -60,10 +61,13 @@ export const log = new (class {
}
})();

export function isValidExecutable(path: string): boolean {
export function isValidExecutable(path: string, extraEnv: Env): boolean {
log.debug("Checking availability of a binary at", path);

const res = spawnSync(path, ["--version"], { encoding: "utf8" });
const newEnv = substituteVariablesInEnv(Object.assign({}, process.env, extraEnv));
log.debug('newEnv', newEnv);

const res = spawnSync(path, ["--version"], { encoding: "utf8", env: newEnv });

const printOutput = res.error && (res.error as any).code !== "ENOENT" ? log.warn : log.debug;
printOutput(path, "--version:", res);
Expand Down

0 comments on commit 4b611d2

Please sign in to comment.