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.ts81
1 files changed, 45 insertions, 36 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index c6d2bcc2b2..a047f9659a 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -2,8 +2,9 @@ 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 { Env } from "./client";
+import type { Env } from "./client";
import { log } from "./util";
+import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
export type RunnableEnvCfg =
| undefined
@@ -37,7 +38,7 @@ export class Config {
vscode.workspace.onDidChangeConfiguration(
this.onDidChangeConfiguration,
this,
- ctx.subscriptions
+ ctx.subscriptions,
);
this.refreshLogging();
this.configureLanguage();
@@ -63,7 +64,7 @@ export class Config {
this.configureLanguage();
const requiresReloadOpt = this.requiresReloadOpts.find((opt) =>
- event.affectsConfiguration(opt)
+ event.affectsConfiguration(opt),
);
if (!requiresReloadOpt) return;
@@ -98,7 +99,8 @@ export class Config {
let onEnterRules: vscode.OnEnterRule[] = [
{
// Carry indentation from the previous line
- beforeText: /^\s*$/,
+ // if it's only whitespace
+ beforeText: /^\s+$/,
action: { indentAction: vscode.IndentAction.None },
},
{
@@ -208,8 +210,8 @@ export class Config {
Object.entries(extraEnv).map(([k, v]) => [
k,
typeof v !== "string" ? v.toString() : v,
- ])
- )
+ ]),
+ ),
);
}
get traceExtension() {
@@ -220,12 +222,16 @@ export class Config {
return this.get<string[] | undefined>("discoverProjectCommand");
}
+ get problemMatcher(): string[] {
+ return this.get<string[]>("runnables.problemMatcher") || [];
+ }
+
get cargoRunner() {
return this.get<string | undefined>("cargoRunner");
}
- get runnableEnv() {
- const item = this.get<any>("runnableEnv");
+ get runnablesExtraEnv() {
+ const item = this.get<any>("runnables.extraEnv") ?? this.get<any>("runnableEnv");
if (!item) return item;
const fixRecord = (r: Record<string, any>) => {
for (const key in r) {
@@ -300,7 +306,7 @@ export class Config {
// to interact with.
export function prepareVSCodeConfig<T>(
resp: T,
- cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void
+ cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void,
): T {
if (Is.string(resp)) {
return substituteVSCodeVariableInString(resp) as T;
@@ -334,7 +340,7 @@ export function substituteVariablesInEnv(env: Env): Env {
const depRe = new RegExp(/\${(?<depName>.+?)}/g);
let match = undefined;
while ((match = depRe.exec(value))) {
- const depName = match.groups!.depName;
+ const depName = unwrapUndefinable(match.groups?.["depName"]);
deps.add(depName);
// `depName` at this point can have a form of `expression` or
// `prefix:expression`
@@ -343,7 +349,7 @@ export function substituteVariablesInEnv(env: Env): Env {
}
}
return [`env:${key}`, { deps: [...deps], value }];
- })
+ }),
);
const resolved = new Set<string>();
@@ -352,7 +358,7 @@ export function substituteVariablesInEnv(env: Env): Env {
if (match) {
const { prefix, body } = match.groups!;
if (prefix === "env") {
- const envName = body;
+ const envName = unwrapUndefinable(body);
envWithDeps[dep] = {
value: process.env[envName] ?? "",
deps: [],
@@ -380,13 +386,12 @@ export function substituteVariablesInEnv(env: Env): Env {
do {
leftToResolveSize = toResolve.size;
for (const key of toResolve) {
- if (envWithDeps[key].deps.every((dep) => resolved.has(dep))) {
- envWithDeps[key].value = envWithDeps[key].value.replace(
- /\${(?<depName>.+?)}/g,
- (_wholeMatch, depName) => {
- return envWithDeps[depName].value;
- }
- );
+ 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;
+ });
resolved.add(key);
toResolve.delete(key);
}
@@ -395,7 +400,8 @@ export function substituteVariablesInEnv(env: Env): Env {
const resolvedEnv: Env = {};
for (const key of Object.keys(env)) {
- resolvedEnv[key] = envWithDeps[`env:${key}`].value;
+ const item = unwrapUndefinable(envWithDeps[`env:${key}`]);
+ resolvedEnv[key] = item.value;
}
return resolvedEnv;
}
@@ -414,20 +420,19 @@ function substituteVSCodeVariableInString(val: string): string {
function computeVscodeVar(varName: string): string | null {
const workspaceFolder = () => {
const folders = vscode.workspace.workspaceFolders ?? [];
- if (folders.length === 1) {
- // TODO: support for remote workspaces?
- return folders[0].uri.fsPath;
- } else if (folders.length > 1) {
- // could use currently opened document to detect the correct
- // workspace. However, that would be determined by the document
- // user has opened on Editor startup. Could lead to
- // unpredictable workspace selection in practice.
- // It's better to pick the first one
- return folders[0].uri.fsPath;
- } else {
- // no workspace opened
- return "";
- }
+ const folder = folders[0];
+ // TODO: support for remote workspaces?
+ const fsPath: string =
+ folder === undefined
+ ? // no workspace opened
+ ""
+ : // could use currently opened document to detect the correct
+ // workspace. However, that would be determined by the document
+ // 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;
+ return fsPath;
};
// https://code.visualstudio.com/docs/editor/variables-reference
const supportedVariables: { [k: string]: () => string } = {
@@ -444,13 +449,17 @@ function computeVscodeVar(varName: string): string | null {
// https://github.com/microsoft/vscode/blob/08ac1bb67ca2459496b272d8f4a908757f24f56f/src/vs/workbench/api/common/extHostVariableResolverService.ts#L81
// or
// https://github.com/microsoft/vscode/blob/29eb316bb9f154b7870eb5204ec7f2e7cf649bec/src/vs/server/node/remoteTerminalChannel.ts#L56
- execPath: () => process.env.VSCODE_EXEC_PATH ?? process.execPath,
+ execPath: () => process.env["VSCODE_EXEC_PATH"] ?? process.execPath,
pathSeparator: () => path.sep,
};
if (varName in supportedVariables) {
- return supportedVariables[varName]();
+ const fn = expectNotUndefined(
+ supportedVariables[varName],
+ `${varName} should not be undefined here`,
+ );
+ return fn();
} else {
// return "${" + varName + "}";
return null;