Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode: pass extra env when validating #654

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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