daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
372 stars 44 forks source link

Add support for input variables #224

Open Jackenmen opened 1 year ago

Jackenmen commented 1 year ago

Today I was doing some debugging, changing arguments in the debugger configuration between runs which was a bit of a hassle and I started wondering whether perhaps this is an already solved problem. When doing so, I first found the ${command:SpecifyProgramArgs} option of the VS Code Java extension and opened feature requests for different vs code extensions but since the language I was interested in was not Java and the feature requests weren't pursued, that wasn't really useful.

Pursuing this a bit more, I encountered a feature of VS Code's debugging and task configuration files that solves this problem nicely - input variables. Input variables are substitutions that you can define under "inputs" key in launch.json and later use in e.g. debugger configuration with ${input:variableID}. Then when you launch the debugger with the configuration that requires some inputs, VS Code will prompt you for those variables (either through free text or through a list of options to choose from, depending on input definition), as well as allow you to use its defined default value (if any is provided).

I think that this would be a useful addition to this plugin as well and one of the use cases would be the previously mentioned args argument. Here's how an example launch.json with this options looks ("inputs" key would probably map to "debugger_inputs" in sublime project file):

{
    "version": "0.2.0",
    "inputs": [
        {
            "id": "fileArguments",
            "description": "The arguments to send to the debugger",
            "type": "promptString",
            "default": "",
        }
    ],
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "console": "integratedTerminal",
            "request": "launch",
            "program": "${file}",
            "args": "${input:fileArguments}",
            "justMyCode": true
        }
    ]
}

Note that "args" key specifically can be a string in VS Code since July 2022 (for participating extensions, whatever that means): https://github.com/microsoft/vscode/issues/83678#issuecomment-1236381454 This isn't the only use case of course (being able to choose the component to run with inputs could be quite useful too) but I would appreciate if this case could be supported as well if you choose to pursue this.

daveleroy commented 1 year ago

I probably don't have time for this right now but if its something you want to add support for you are welcome to open a pull request.

This could be useful for some other cases as well like adding a promptPID type that lets the user select a process to attach to.