Skip to content

Can ${input:fileContent} be used with configurations.connect.host in a launch.json configuration? #86

@LoggerMN

Description

@LoggerMN

I'm trying to build a launch configuration that will,

  1. submit a python script to be ran on a server farm,
  2. wait for an indication that the script has started a debugpy server, and is listening for connections,
  3. ascertain the machine that is now listening for a debug client connection, and
  4. proceed to connect the debugger client to the remote server.

I have coded this solution as follows:

  1. launch.json runs a preLaunchTask called launchTest, that uses a shell script to,
    1. submit the job to run on the farm.
    2. waits for a file to exist that contains what machine the job is running on, and also indicates the debug server is now listening.
  2. launch.json also defines the host to connect to as ${input:debugpyLauncHost}
    • input:debugpyLauncHost uses extension.commandvariable.file.content to get the value from the file.

It appears that the launch configuration evaluates the value of ${input:debugpyLauncHost}, before running the preLaunchTask. Because, while launchTest starts the server and the file is created with the machine name, ${input:debugpyLauncHost} returns nothing, and the host connection fails.

I experimented with added delays after the file exists, but regardless of the length it doesn't matter. If on the other hand, I pre-populate the file before running the launch configuration ( and forcing the job to run on that specific machine ), ${input:debugpyLauncHost} successfully returns the machine name from the file and the client connects to the server.

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Py Debugger",
            "type": "debugpy",
            "preLaunchTask": "launchTest",
            "request": "attach",
            "connect": {
                "host": "${input:debugpyLaunchHost}",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ],
            "postDebugTask": "delete DebugpyLaunchHost.tmp"
        }
    ],
    "inputs": [
        {
            "id": "debugpyLaunchHost",
            "type": "command",
            "command": "extension.commandvariable.file.content",
            "args": {
                "fileName": "${workspaceFolder}/.vscode/debugpyLaunchHost.tmp"
            }
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "launchTest",
            "type": "shell",
            "command": "proj_env",
            "args": [
                "${workspaceFolder}/trunk/script/launch_test.sh"
            ],  
            "problemMatcher": []
        },
        {
            "label": "delete DebugpyLaunchHost.tmp",
            "type": "shell",
            "command": "rm",
            "args": [
                "${workspaceFolder}/.vscode/debugpyLaunchHost.tmp"
            ],  
            "problemMatcher": []
        }
    ]
}

The details of launch_test.sh aren't important, but it's working as expected.

Is there another way to leverage this extension to accomplish my goal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions