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

Support external terminal option #1992

Open
Avivbens opened this issue Apr 15, 2024 · 3 comments
Open

Support external terminal option #1992

Avivbens opened this issue Apr 15, 2024 · 3 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@Avivbens
Copy link

Is your feature request related to a problem? Please describe.

The issue

I was trying to find a way to run the debug session whitin an external terminal (such as Warp / iTerm2) - based on the default terminal setting, for MacOS it is terminal.external.osxExec.

Describe the feature you'd like

My suggestion

A nice checkbox for enabling this feature, so once I'm hitting on the new debug session (by the code lens on the package.json OR with any menu exists, such as the NPM SCRIPTS) - the new debug session would trigger commands over my default terminal.

Screenshots

CleanShot 2024-04-15 at 15 08 56@2x
CleanShot 2024-04-15 at 15 08 04@2x

@Avivbens Avivbens added the feature-request Request for new features or functionality label Apr 15, 2024
@Avivbens
Copy link
Author

HI @connor4312 👋

Any idea about that?
I can help with the PR 👍

@connor4312
Copy link
Member

Sure, a PR is welcome. Note this is actually implemented in https://github.com/microsoft/vscode/tree/main/extensions/npm

@zvictor
Copy link

zvictor commented Sep 12, 2024

I was trying to find a way to run the debug session whitin an external terminal (such as Warp / iTerm2)

I managed to have external processes (i.e. launched from outside vscode integrated terminals) auto-attach to vscode debug sessions by hacking with it a bit.

Step 1:

Create an automatic task that exports the debugging env vars.

.vscode/tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Capture Debug Vars",
      "type": "shell",
      "command": "bash",
      "args": [".vscode/captureDebugVars.sh"],
      "problemMatcher": [],
      "options": {
        "env": {
          "ENV_FILE": "${workspaceFolder}/.env.local" // set any file you want
        }
      },
      "runOptions": {
        "runOn": "folderOpen"
      }
    }
  ]
}

.vscode/captureDebugVars.sh

#!/usr/bin/env bash
set -euo pipefail

# Check if required environment variables are set
if [[ -z "${ENV_FILE:-}" ]]; then
  echo "You forgot to set ENV_FILE"
  exit 1
fi

if [[ -z "${VSCODE_INSPECTOR_OPTIONS:-}" || -z "${NODE_OPTIONS:-}" ]]; then
  echo "VS Code has not defined VSCODE_INSPECTOR_OPTIONS or NODE_OPTIONS"
  exit 1
fi

# Load current configuration if the file exists
declare -A env
if [[ -f "$ENV_FILE" ]]; then
  while IFS='=' read -r key value; do
    env["$key"]="$value"
  done < "$ENV_FILE"
fi

# Merge new configuration
env["NODE_OPTIONS"]="${NODE_OPTIONS}"
env["VSCODE_INSPECTOR_OPTIONS"]="${VSCODE_INSPECTOR_OPTIONS}"

# Write the new configuration back to the file
{
  for key in "${!env[@]}"; do
    echo "$key=${env[$key]}"
  done
} > "$ENV_FILE"

echo "Environment variables captured to $ENV_FILE"

Step 2

Find a way to automatically load the env vars into your terminal. I use and recommend direnv:

.envrc

source .env.local # or whatever you used as ENV_FILE on step 1

With that in place, all your scripts will be automatically debugged in vscode as long as vscode is running and you have opened it before running your external script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants