Search code examples
visual-studio-codevscode-extensions

Is it possible to write VS Code extension that modifies tasks.json and launch.json?


I would like to create my own extension that would provide predefined configuration for debugger (launch.json) and a predefined set of tasks (tasks.json).

Right now I have vs code configured in those 2 files but there are lot of hardcodes in many places that will vary across different projects. So ideally I would like to have a plugin that eg reads one configuration file and applies all that stuff to "tasks.json" and "launch.json".

Wondering if that's even possible with vs code extensions API.


Solution

  • I think you can do this with variables defined in settings.json. You can define your own custom settings in settings.json (either user or workspace settings):

    {
      "editor.formatOnSave": false,  // normal settings defined by the editor and plugins
      "foo.bar": "baz" // custom setting
    }
    

    You can then reference this setting inside tasks.json or launch.json using string interpolation as "${config:foo.bar}".

    I'm not sure where this is documented, but I found a reference to this in https://github.com/Microsoft/vscode/pull/11291

    Update:

    I've created a test repo at https://github.com/boyvinall/vscode-c-dbg. When I invoke the "run" task within tasks.json, I get the following output:

    enter image description here

    Using through launch.json with my current configuration doesn't seem to work with the "gdb" configuration, although the "cppdbg" configuration does seem to work ok:

    enter [...] "Edits must be at least 6 characters; is there something else to improve in this post?"...stackoverflow is annoying

    NB, in case it's important, I'm running vscode v1.8.1