You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sh...@apache.org on 2023/06/12 16:17:32 UTC

[daffodil-vscode] branch main updated: Always export env variables

This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new 2514d25  Always export env variables
2514d25 is described below

commit 2514d2561358ae44fad0f45f3117ccf5add1c061
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Wed Jun 7 13:23:55 2023 -0400

    Always export env variables
    
    - Close any opened daffodil-debugger terminal by default.
      - This makes sure any env we rely on get set every time a new debug is ran.
    - Manually set all env variables instead of passing `env: env` to createTerminal.
      - createTerminal `env: env` will not override variables that are already set.
    
    Closes #652
---
 src/utils.ts | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/utils.ts b/src/utils.ts
index 799bc15..6e3408e 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -238,20 +238,34 @@ export const getTerminal = (
   createTerminal: boolean
 ) => {
   if (!createTerminal) {
-    if (vscode.window.activeTerminal) {
-      const activeTerminal = vscode.window.activeTerminal
-
-      // check allows for shell name or full path to shell in terminal name
-      if (activeTerminal.name.includes(terminalName)) return activeTerminal
-    }
+    vscode.window.terminals.forEach((terminal) => {
+      if (terminal.name.includes(terminalName)) terminal.dispose()
+    })
   }
 
   // If no good active terminal available create new one
-  return vscode.window.createTerminal({
+  const terminal = vscode.window.createTerminal({
     name: terminalName,
     hideFromUser: hideTerminal,
-    env: env,
   })
+
+  // Looping to manual set all env variables. Setting "env: env" inside of createTerminal won't override variables already set
+  for (var key in env) {
+    if (key !== null && key !== undefined) {
+      let workspaceFolder = vscode.workspace.workspaceFolders
+        ? vscode.workspace.workspaceFolders[0].uri.fsPath
+        : ''
+      let exportVar = `${osCheck('set', 'export')} ${key}=${env[key]}`
+
+      if (exportVar.includes('${workspaceFolder}')) {
+        exportVar = exportVar.replaceAll('${workspaceFolder}', workspaceFolder)
+      }
+
+      terminal.sendText(exportVar, true)
+    }
+  }
+
+  return terminal
 }
 
 export async function runScript(