Giter Club home page Giter Club logo

launch-config's Introduction

Launch Configs

This vscode extension allows you to create settings to launch any number of your launch.json configurations or compound configurations via separate keybindings. These launch configs can be in any root folder in a multi-root workspace. And a launch config from one root folder can be triggered while in a file from a different root folder. And you can create arrays of launch configs to run with a single keybinding.


[From startDebugging() documentation.] :

The named configurations are looked up in .vscode/launch.json found in the given folder. Before debugging starts, all unsaved files are saved and the launch configurations are brought up-to-date. Folder specific variables used in the configuration (e.g. ${workspaceFolder}) are resolved against the given folder.


The above caution has been modified by a later update to vscode (v1.54). Now you can explicitly set vscode to not save any unsaved files prior to debugging:

// Controls what editors to save before starting a debug session.  

// allEditorsInActiveGroup: Save all editors in the active group before starting a debug session.  
// nonUntitledEditorsInActiveGroup: Save all editors in the active group except untitled ones before starting a debug session.  
// none: Don't save any editors before starting a debug session.  

"debug.saveBeforeStart": "allEditorsInActiveGroup", 

If you use this extension to start a launch configuration from a workspace folder different than that of the active editor, note that vscode's built-in folder-specific variables, like ${workspaceFolder}, will be resolved to the folder that you are calling into, but variables like ${file} in that same launch configuration will be resolved to the active text editor at the time of triggering the command - which may not even be in that same workspaceFolder. This may not be what you expect.


Prior to v0.7.0, if you had started a debug session with a keybinding, and then re-triggered the same keybinding, it would fail and you would get a warning notification from vscode about attempting to start an already running launch configuration. With v0.7.0 this has been reworked so that you have more control over an already running debug session. Now you can choose to stop it, stop and then start it, start or restart it either through a setting which controls the handling of all currently running debug sessions or through a keybinding argument for that specific debug session.

For more on this new functionality, see session options.


Features

  • Shortcuts for launch configurations, in settings.json
  • Run any launch configuration found in any multi-root folder in a workspace, in settings.json
  "launches": {
    "RunNodeCurrentFile": "Serve File (Project A Folder)",
    "RunNodeCurrentFileB": "Launch File (Project B Folder)"
  }

In keybindings.json or added from the Keyboard Shortcuts UI:

  {
    "key": "alt+g",               <== whatever keybinding you wish    
    "command": "launches.RunNodeCurrentFile",
    "arg": "restart"              <== optional, see the session options
  }

Trigger from a Project A or Project B editor:

  {
    "key": "alt+h",                       
    "command": "launches.RunNodeBuildFileA"
  },
  {
    "key": "alt+i",                       
    "command": "launches.RunNodeBuildFileB"
  }
  • Run an array of launch configurations from any launch.json in the workspace, in settings.json:
  "launches": {
    "RunLaunchArray": ["Launch File (Project A)", "Launch File (Project B)"]
  }
  {
    "key": "alt+j",
    "command": "launches.RunLaunchArray"
  }
  • Open a QuickPick panel of all available launch configurations. Select and run one or many from this list.

Extension Settings

This extension contributes two settings:


  1. launches (an object of key : value pairs): Identify by using your launch.json name which configuration you would like to run. You can use "compounds" configurations as well.

The first part of each entry, like "RunNodeFile", can be anything you want (without spaces) - you will use it in the keybinding. The second part, like "Launch File", is the name of the configuration you would like to run. In settings.json:

  "launches": {

    "RunNodeFile": "Launch File (<some workspaceFolder name>)",  // the folder name will be provided for you
    "RunCompound1": "Launch file and start chrome"               // but you do not need to have a folder name
  },

You will get intellisense in your settings.json for the 'name' of all possible launch configurations or compound configurations. This intellisense will include all configurations and root folder names if you are in a multi-root workspace. That folder name is used to resolve which launch.json to look in for the corresponding configuration (especially important where the same config name - like Launch File - is used in multiple launch.json files).

Intellisense for Launch Settings demo



[The launch config names can be anything - I just happened to use "Launch" at the beginning of all these demo names, that is not necessary.]


Although intellisense will automatically append the folder name, you do not need to use one. If it is absent then the activeEditorWorkSpace will be used; so only the current workspaceFolder launch.json will be examined.

The name key and value can be anywhere within its configuration - it does not need to be first. An example launch.json file:

{
  "version": "0.2.0",
  "compounds": [
    {
      "name": "Launch file and start chrome",
      "configurations": ["Launch File", "Launch Chrome against localhost"],
      "preLaunchTask": "Start server",
      "stopAll": true
    }
  ],
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch File",
      "program": "${file}"
    },
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome against localhost",
      "url": "http://localhost:8080",
      "webRoot": "${workspaceRoot}",
      "file": "${workspaceRoot}/build.html"
    }
  ]
}

2.launch-config.ifDebugSessionRunning : Options: "stop/start", "stop" (the default), "restart" or start

This setting controls how to handle a currently running debug session when triggering the same keybinding again for that launch configuration. See more at session options.



Commands and Keybindings

This extension contributes three commands:

This extension generates commands from settings created by the user. These generated commands will appear in Keyboard Shortcuts and keybindings can be assigned there or manually, with intellisense, in keybindings.json. In this example there are four settings from which commands have been generated and two of those have had keybindings associated with them previously.

Keybindings shortcuts demo

  1. This extension also provides one built-in command launches.showAllLaunchConfigs which opens a QuickPick panel of all available launch configurations. From this panel you can select and run one or more configurations. Note: there is no guarantee that the configs will be run in the order you select them as just an alphabetical list of selections is returned by vscode.

QuickPick demo



  1. launches.focusNextDebugSession : no default keybinding

Launch Configs: Focus the next debug session (<= how it appears in the Command Palette) This command will focus the next debug session in the call stack. So if you have at least two debug sessions running at the same time you can use this command to focus the next one after the previously focused session. This is the same as clicking on a session in the call stack view or choosing one from the debug toolbar dropdown or the debug console dropdown.

  1. launches.focusPreviousDebugSession : no default keybinding

Launch Configs: Focus the previous debug session (<= how it appears in the Command Palette)This command will focus the previous debug session in the call stack.

The extension api does not provide a direct way to programmatically focus other debug sessions, so these commands are a little "kludgy" and use list navigation commands to do so. This is not optimal but I believe the best that can be done at this point.

You can create your own keybindings for these two commands either through the Keyboard Shortcuts GUI or adding these to your keybindings.json:

{
  "key": "alt+1",        // whatever keybinding you wish
  "command": "launches.focusNextDebugSession"
},
{
  "key": "alt+2",        // whatever keybinding you wish
  "command": "launches.focusPreviousDebugSession"
}


Keybindings for running launch configurations:

Choose whatever different keybindings you wish. Here are example keybindings (in keybindings.json):

  {
    "key": "alt+f",
    "command": "launches.RunAsArray"
    // "when": "editorTextFocus && editorLangId == javascript"  // for example
  },
  {
    "key": "alt+g",
    "command": "launches.RunCompound",
    "args": "restart"     // see Note below on using args in a keybinding
  },
  {
    "key": "alt+k",
    "command": "launches.showAllLaunchConfigs"  // open the QuickPick with available configs
  },

You will get intellisense in your keybindings.json file for the launches.showAllLaunchConfigs command and upon typing the "launches." part of the command. Then you will see a list of your available completions from your settings.json, such as RunAsArray and RunCompound.

Intellisense for Keybindings demo


Known Issues

  1. The restart option does not work when re-launching a browser. Example:
  {
    "type": "chrome",
    "request": "launch",
    "name": "Launch Chrome against localhost",
    "url": "http://localhost:8081",
    "file": "${workspaceFolder}/build.html"
  }

The browser will not successfully restart the second time - use the stop/start option instead when launching browsers.

  1. Similar to Issue 1, the restart option does not work when restarting a compound configuration from your launch.json file(s). From the launch.json example above:
  "compounds": [
    {
      "name": "Launch file and start chrome",
      "configurations": ["Launch File1", "Launch File2"],
      "preLaunchTask": "Start server",
      "stopAll": true
    }
  ],

When vscode starts this the first time, each debug session has a separate name and id, like Launch File1, but no compound name or compopund id, here the name would be Launch file and start chrome. This is a problem because the workbench.action.debug.restart requires a session.id to know which debugging session to restart. But there is no session.id that represents the compound configuration as a whole.

So this extension will simply stop and start the compound configuration, but not "restart" it (in some situations there is a difference). stop/start works as an option; the restart option will do the same thing as stop/start.

  1. In a multi-root workspace you can create launch configurations and compounds in a *.code-workspace file. This extension is able to retrieve those but cannot scope a debugging session to that file. Thus launch configurations in a *.code-workspace can not be used with this extension. vscode.debug.startDebugging(workspaceFolder|undefined, name|Configuration) needs to be scoped to a workspaceFolder.

  2. There is an unusual bug in vscode that pertains only to multi-root workspaces where you have at least two launch.json files with identically-named configurations that are used in a compound configuration. So if you have this in projectA's launch.json:

"compounds": [
      {
          "name": "Launch file and start chrome",
                                            // what if no "Launch File" config in file?
          "configurations": ["Launch File", "Launch Chrome against localhost" ],
          "stopAll": true 
      },
    ],

but assume there is actually no Launch File config in that file (projectA). If there should happen to be a Launch File config in projectB's launch.json that projectB Launch File will be started by vscode. That should not happen when the startDebugging() command is scoped to projectA - that debug call should fail and not look for another identically-named config somewhere in the multi-root workspace.

Of course, you shouldn't have a compound config that lists a configuration that doesn't exist in that same file - that is an error. So this bug should be easily avoided.


TODO

[ X ] - Add support for multiple workspaceFolders, finished in v0.4.
[ X ] - Explore running multiple debug sessions from one keybinding [v0.4].
[ X ] - Provide intellisense for settings.json, with all "names" fron launch.json [v0.3].
[ X ] - Provide intellisense for launches. commands in keybindings.json from settings.json keys [v0.2].
[ X ] - Add command and QuickPanel launch config and selections [v0.5].
[ X ] - Add support for stopping, restarting or stop/start a previously running debug session [v0.7.0].
[  ] - Explore retrieval of launch configs from .code-workspace files in a multi-root workspace.
[  ] - Explore support for task arguments.
[  ] - Explore generating a command directly from keybindings.
[ X ] - Provide intellisense for args in keybindings.json [v0.7.1].
[ X ] - Explore whether compound configuration handling can be stream-lined.
[ X ] - Explore whether other compound arguments like prelaunchTask and presentation can be retrieved on restarts.


Thank you

For the addition of the ability to bind any number of launch configurations to keybindings, I relied heavily on the code from Jeff Hykin and macro-commander.

For determining the workspaceFolder of the current file, I used code from rioj7's command-variable.

For helping getting Intellisense working in keybindings.json for launches. commands, see rioj7's answer.

For debugging DJ4ddi: issue 1 and filing Github issue Restart specific debugger using command that enabled the use of vscode.commands.executeCommand('workbench.action.debug.restart') with arguments.


Release Notes

For earlier release notes see the CHANGELOG.

  • 0.8.0   Stop opening debug view (a fix for debug toolbar focus issues in vscode < v1.54, issue).
         Fixed completions for keybindings commands and args.
         0.8.2   Added commands for navigating to the next/previous debug sessions in the call stack.

launch-config's People

Contributors

arturodent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

launch-config's Issues

Use of launch in settings.json rather than launch.json

First I would like to say this is a great extension to VS code and I have been happily using it for months now.
I recently discovered that rather than having to have the launch configurations defined in launch.json they can actually be defined in settings.json, eg

"launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Debug Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}",
                "console": "integratedTerminal",
            },
etc etc

This is great because they can be added to the user settings.json file and therefore all instance of VS code automatically get these launch configurations. This cannot be achieved using launch.json. (because you cannot have a user launch.json)

Unfortunately at the moment this extension only works with launch configurations defined in launch.json NOT settings.json.

Can this be fixed?

Creating a new plugin

Hello @ArturoDent,

I could not find your email address hence my contacting you via GitHub.

Thanks for creating this plugin - I use it daily.

I would like to hire you to create a new plugin for us at https://zato.io.

Please feel free to contact me on ***** and I will be happy to discuss the details with you.

Regards.

Allow for debug configurations not specific to a workspace?

I have multiple C# workspaces where I have a main project and a test project, and I want different keybindings to run each one. This works well in one workspace, but it seems that I am required to type the name of the base workspace folder as part of the debug configuration name, which means that I can't have your extension work for all workspaces, even though they all have the same name for the configurations in each launch.json. Note that at any given time, there is only one workspace and one .vscode folder open.

What I have to do right now in settings.json:

"launches": {
    "RunMainDebug": "Main Debug (WorkspaceName)",
    "RunTestDebug": "Test Debug (WorkspaceName)"
}

Where WorkspaceName is the name of the workspace or root folder.

However, this limits my keybinds to this specific workspace, and if I open another workspace I need to edit settings.json to make a new keybind with that workspace's debug configurations in them, despite all being called "Main Debug" and "Test Debug".

I tried replacing WorkspaceName above with ${WorkspaceFolderBasename} but I now see that #15 says that those variables are not evaluated. How can I set up my keybindings to run for every workspace, given there is "Main Debug" and "Test Debug" in .vscode/launch.json?

[Feature] Support restarting the configuration if it is already running.

It would be great to allow this extension to restart an active debugging session if the configuration is already running when the command is invoked. See microsoft/vscode#114467 for a possible use case.

This could be done in a setting, e.g.

"launches.stopRunningInstance": "no" // Show an error (current behavior, default)
"launches.stopRunningInstance": "yes" // Stop and start the configuration
"launches.stopRunningInstance": "restart" // Restart the configuration (not the same as stop and start for some debuggers)

[Feature] Invoke without keybinding

Currently it seems like the only way to invoke my launch config is with a keybinding. This is a bit awkward since keybindings are global but my launch config is specific to a particular project. It would be nice if I could also invoke my launch config via the F1 command palette.

use a default workspace instead of reporting "workspace has no launch.json"

Background

Sometimes I edit files not located in my workspace folder, although the workspace is created from a folder and has only 1 root folder.

What I do

Press a shortcut to trigger launches.RunXxxx.

What's the current result

It reports Passed workspace has no "launch.json".

image

What I expect

It runs the mapped launch configuration from .vscode/launch.json of a "default" workspace.

I'm not sure whether VS Code has such a "default" workspace or not, but I guess it should support this.

"'Launch.json' does not exist for passed workspace folder"

When using Multi root workspace folders, if the active files root folder does not have a launch.json file, the extension throws a notification and aborts.

I know you made a note of it:

If you use this extension to start a launch configuration from a workspace folder different than that of the active editor, note that vscode's built-in folder-specific variables, like ${workspaceFolder}, will be resolved to the folder that you are calling into, but variables like ${file} in that same launch configuration will be resolved to the active text editor at the time of triggering the command - which may not even be in that same workspaceFolder. This may not be what you expect.

I don't understand why not use a launch.json file found in another root folder? or is this already possible? I am forced to only keep a single ~\.vscode folder, present only in one of my workspace root folder. Is there a way around this currently? If not any chance we can get support for this?

Thanks for this amazing extension by the way.

not keyboard only friendly.

I assigned the 'F5' keybind to the 'Show all launch configurations' feature. However, when the end-user selects a configuration, they still need to use the mouse to check the corresponding checkbox. It would be more efficient to enable the functionality of confirming a selected configuration by simply pressing the 'Enter' key. Currently, when I press 'F5,' and i press "arrow down" it highlights the first configuration, 'Config 1,' but we still need to use the mouse to check the checkbox. Implementing the ability to confirm the selection with the 'Enter' key would greatly enhance the user experience.

Global Settings for behaviour

I have following tasks config
{
"version": "2.0.0",
"tasks": [
{
"label": "builddotnet",
"detail": "Builds the application",
"command": "dotnet build "${input:remember.SLNorProjPath}"",
"type": "shell",
"problemMatcher": "$msCompile"
},
{
"label": "builddotnetwithargs",
"detail": "Builds the application",
"command": "dotnet build "${input:remember.SLNorProjPath}" ${input:remember.BuildArgs}",
"type": "shell",
"problemMatcher": "$msCompile"
}
],
//VSCode Extension https://marketplace.visualstudio.com/items?itemName=ArturoDent.launch-config
"inputs": [
{
"id": "remember.SLNorProjPath",
"type": "command",
"command": "extension.commandvariable.remember",
"args": { "key": "SLNorProjPath" }
},
{
"id": "remember.BuildArgs",
"type": "command",
"command": "extension.commandvariable.remember",
"args": { "key": "BuildArgs" }
}
]
}

I need now two tasks "builddotnet" and "builddotnetwithargs".

I set the variable as following
"inputs": [
{
"id": "rememberConfig.Service.SLNorProjPath",
"type": "command",
"command": "extension.commandvariable.remember",
"args": {
"store": {"SLNorProjPath":"${workspaceFolder}/src/SGOIMDispatcher.Service/SGOIMDispatcher.Service.csproj"}
}
},
{
"id": "rememberConfig.Service.ReleaseBuildArgs",
"type": "command",
"command": "extension.commandvariable.remember",
"args": {
"store": {"BuildArgs":"-c Release"}
}
}
]

I trigger the remember config by calling one of it or multiple of it in the launch config they need to be, eg:

        "name": "SGOIMDispatcher.Service_Release",
        //make static analyzer happy. debugs symbols are not emitted, so type and request not needed...
        "type": "clr",
         "request": "launch",
        //build in release without debug symbols
        "preLaunchTask": "builddotnetwithargs",
        "program": "${workspaceFolder}/bin/Release/net48/SGOIMDispatcher.exe",
        //Used to trigger keyvalue store, returns empty as args
        "args": ["${input:rememberConfig.Service.SLNorProjPath}",
                "${input:rememberConfig.Service.ReleaseBuildArgs}"
        ],
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "internalConsoleOptions": "openOnSessionStart"
    }

If now i don't set a value that is used in a task i get the error "i cannot remember". If it wouldn't throw this error I could use just one task with both input variables defined in it. So it would be nice to have an enhancement where i can controll the behaviour if a value is not throw (e.g. return empty or throw).

Also a option/mechanism that can contcat multiple stored keys with the same keyname when defined instead of overriding the value in the key/valuestore could be usefull.

e.g.
"store": {"BuildArgs":"-path [path]"}
"store": {"BuildArgs":"-c release"}

${input:remember.BuildArgs) -> "-path [path]> -c release".

With this i can reuse the defined args for the different launch.configs without rewriting them

Provided setting does not match actual setting

The documentation (as well as autocomplete and the extension capabilities) specifies launches.ifDebugSessionRunning, but the setting that is actually used is launch.ifDebugSessionRunning.

Dropping launch.json "args"

Hi ArturoDent, first I want to say this extension is amazing and super helpful! I recently installed it and went over the documentation but am unsure of where to find this issue, if any, as it looks like the "arg" for the keybind(s) is another topic.
The problem I'm having is the "args" from launch.json seem to not be getting executed.

image

Basically, the "--outputdir=..." (as you'd expect) redirects result files to the specified location, however, they are going into the top level ${workspaceFolder} when ran via Launches keybind.

typo in README

In Extension Settings is the string:

That folder name is used to resolve which launch.js to look in for the corresponding configuration

launch.js should be launch.json


In Known Issues

number 3 is "missing"


Release Notes

VSC Marketplace supports the CHANGELOG.md file

Issue when .vscode folder is hidden in explorer

It seems like launch-config is filtering out hidden files in the explorer (and can't find launch.json maybe)?

project/.vscode/settings.json:

this will work:

{
    "debug.internalConsoleOptions": "neverOpen",
    "files.exclude": {
	"*.*": false,
        ".vscode": false,
        "dist": true,
        "node_modules": true
    },
    "launches": {
        "SWA": "SWA"
    }
}

this will not:

{
    "debug.internalConsoleOptions": "neverOpen",
    "files.exclude": {
        "*.*": true,
        ".vscode": false, // due to a reported issue .vscode is still hidden when *.* is set to true
        "dist": true,
        "node_modules": true
    },
    "launches": {
        "SWA": "SWA"
    }
}

Please note that I am calling the command launches.SWA remotely. It might work with keybindings

Feature request: Switch between active debug configurations

Hi @ArturoDent, thank you for writing this awesome plugin!

Question: Would it possible to assign a shortcut to switch between 2 active debug sessions?

Context:
Consider a multi-target (or "compound") configuration, where VS Code concurrently runs & debugs two processes (e.g., a React client and a node-based Server).

Both processes send debug messages to the debug console panel, and one can select the active process either in the debug configuration dropdown menu (usually on the left pane, on the top) or in the debug console drop down menu.

The inconvenience is that as far as I can see, switching between the active sessions can only be done with the cursor.

License

Can you confirm under what license this extension has been released.
Thanks.

Feature request: support hot reload

Not sure if this is a bug or a feature request really.

If I have a session going and I manually restart it like this:

image)

it will hot reload if that is supported (eg in Dart/Flutter).

However, if I launch it via this plugin, it will kill the existing session and restart it, despite me having "restart" in the key binding:

image

and also having "launch-config.ifDebugSessionRunning": "restart" in my settings.

Configuration 'my config' is missing in 'launch.json'.

I'm trying the command "Launch Counfigs: Show all launch configurations", checking one of them, then press OK, and I got:

Configuration 'my config' is missing in 'launch.json'.

where 'my config' is the config name, for each selected config.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.