================
@@ -157,6 +157,61 @@ async function getDAPArguments(
     .get<string[]>("arguments", []);
 }
 
+/**
+ * Retrieves the environment that will be provided to lldb-dap either from 
settings or the provided
+ * {@link vscode.DebugConfiguration}.
+ *
+ * @param workspaceFolder The {@link vscode.WorkspaceFolder} that the debug 
session will be launched within
+ * @param configuration The {@link vscode.DebugConfiguration} that will be 
launched
+ * @throws An {@link ErrorWithNotification} if something went wrong
+ * @returns The environment that will be provided to lldb-dap
+ */
+async function getDAPEnvironment(
+  workspaceFolder: vscode.WorkspaceFolder | undefined,
+  configuration: vscode.DebugConfiguration,
+): Promise<{ [key: string]: string }> {
+  const debugConfigEnv = configuration.debugAdapterEnv;
+  if (debugConfigEnv) {
+    if (
+      (typeof debugConfigEnv !== "object" ||
+
+        Object.values(debugConfigEnv).findIndex(
+          (entry) => typeof entry !== "string",
+        ) !== -1) &&
+      (!Array.isArray(debugConfigEnv) ||
+        debugConfigEnv.findIndex(
+          (entry) =>
+            typeof entry !== "string" || !/^((\\w+=.*)|^\\w+)$/.test(entry),
+        ) !== -1)
+    ) {
+      throw new ErrorWithNotification(
+        "The debugAdapterEnv property must be a dictionary of string keys and 
values OR an array of string values. Please update your launch configuration",
+        new ConfigureButton(),
+      );
+    }
----------------
walter-erquinigo wrote:

move this to a helper function called `validateEnv` or something like that. 
Otherwise it's very hard to read.
Also, that regex is sadly very difficult to read, can you do a simpler check? 
It doesn't need to be perfect perfect

https://github.com/llvm/llvm-project/pull/153536
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to