Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/config.ts')
| -rw-r--r-- | editors/code/src/config.ts | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 896b3c10cb..f36e18a73d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -2,7 +2,7 @@ import * as Is from "vscode-languageclient/lib/common/utils/is"; import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; -import { expectNotUndefined, log, unwrapUndefinable } from "./util"; +import { expectNotUndefined, log, normalizeDriveLetter, unwrapUndefinable } from "./util"; import type { Env } from "./util"; import type { Disposable } from "vscode"; @@ -213,12 +213,13 @@ export class Config { get serverExtraEnv(): Env { const extraEnv = - this.get<{ [key: string]: string | number } | null>("server.extraEnv") ?? {}; + this.get<{ [key: string]: { toString(): string } | null } | null>("server.extraEnv") ?? + {}; return substituteVariablesInEnv( Object.fromEntries( Object.entries(extraEnv).map(([k, v]) => [ k, - typeof v !== "string" ? v.toString() : v, + typeof v === "string" ? v : v?.toString(), ]), ), ); @@ -323,7 +324,6 @@ export class Config { return { engine: this.get<string>("debug.engine"), engineSettings: this.get<object>("debug.engineSettings") ?? {}, - openDebugPane: this.get<boolean>("debug.openDebugPane"), buildBeforeRestart: this.get<boolean>("debug.buildBeforeRestart"), sourceFileMap: sourceFileMap, }; @@ -399,6 +399,7 @@ export function prepareVSCodeConfig<T>(resp: T): T { // FIXME: Merge this with `substituteVSCodeVariables` above export function substituteVariablesInEnv(env: Env): Env { + const depRe = new RegExp(/\${(?<depName>.+?)}/g); const missingDeps = new Set<string>(); // vscode uses `env:ENV_NAME` for env vars resolution, and it's easier // to follow the same convention for our dependency tracking @@ -406,15 +407,16 @@ export function substituteVariablesInEnv(env: Env): Env { const envWithDeps = Object.fromEntries( Object.entries(env).map(([key, value]) => { const deps = new Set<string>(); - const depRe = new RegExp(/\${(?<depName>.+?)}/g); - let match = undefined; - while ((match = depRe.exec(value))) { - const depName = unwrapUndefinable(match.groups?.["depName"]); - deps.add(depName); - // `depName` at this point can have a form of `expression` or - // `prefix:expression` - if (!definedEnvKeys.has(depName)) { - missingDeps.add(depName); + if (value) { + let match = undefined; + while ((match = depRe.exec(value))) { + const depName = unwrapUndefinable(match.groups?.["depName"]); + deps.add(depName); + // `depName` at this point can have a form of `expression` or + // `prefix:expression` + if (!definedEnvKeys.has(depName)) { + missingDeps.add(depName); + } } } return [`env:${key}`, { deps: [...deps], value }]; @@ -455,11 +457,10 @@ export function substituteVariablesInEnv(env: Env): Env { do { leftToResolveSize = toResolve.size; for (const key of toResolve) { - const item = unwrapUndefinable(envWithDeps[key]); - if (item.deps.every((dep) => resolved.has(dep))) { - item.value = item.value.replace(/\${(?<depName>.+?)}/g, (_wholeMatch, depName) => { - const item = unwrapUndefinable(envWithDeps[depName]); - return item.value; + const item = envWithDeps[key]; + if (item && item.deps.every((dep) => resolved.has(dep))) { + item.value = item.value?.replace(/\${(?<depName>.+?)}/g, (_wholeMatch, depName) => { + return envWithDeps[depName]?.value ?? ""; }); resolved.add(key); toResolve.delete(key); @@ -499,7 +500,7 @@ function computeVscodeVar(varName: string): string | null { // user has opened on Editor startup. Could lead to // unpredictable workspace selection in practice. // It's better to pick the first one - folder.uri.fsPath; + normalizeDriveLetter(folder.uri.fsPath); return fsPath; }; // https://code.visualstudio.com/docs/editor/variables-reference |