Vscode: Running commands as tasks

Created on 1 Sep 2016  路  15Comments  路  Source: microsoft/vscode

Could you help me find the right solution for the following scenario?
I have an extension which is a custom compiler. The compiler executables come together with an extension and I would like the user to run my executable through tasks.json (so that he can get all the problem matcher support, default ctrl+shift+b experience, etc).

The problem is this - the executables in the tasks.json must be in the current PATH, so it will not find the files inside my extension installation folder.
The only viable solution as of now is to install the tools I need as another action (npm install, custom vscode command to install prerequisites, etc). But this is a bit sub-optimal, because a first-time user needs to do another action to install/update the tools and I need to have two different release processes - one for tools and one for extension itself.

Would it be possible to do one of the following:

  • Run not only executables, but also vscode commands from tasks.json. For example, my extension registers a command called "MyBuild" and in tasks.json you specify something like {vscommand: 'MyBuild'; isBuildCommand: true}. Then it would be up to my extension to find and run the proper executable file in its installation path.
  • Patch PATH of the process at the extension activation time so that {command: 'mycompiler.exe'} would be resolved when running a task. Did not manage to make it work.
feature-request tasks

Most helpful comment

This would be super-helpful. Would it make sense to add a new type named command? Then you could do something like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "type": "command",
            "command": "my-extension.build",
            "args": [
                "${workspaceRoot}/main.file"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

my-extension.build would be a command contributed by an extension and args would be passed to this command.

All 15 comments

@dennisfrostlander unfortunately this is currently not possible. Patching the PATH doesn't work either since the extension host and the vscode main are different processes. For now all you can instruct the user to do is to call your command, and then in the extension you execute the program parse the output and generate diagnostic objects using the API.

Thanks, @dbaeumer. Since this already got a feature-request label, I'll formalize my request as "Run commands as tasks". This would gracefully solve my particular problem and is generic enough to be useful for others, I think.

Thinking about this again I would say that we should open up the Ctrl+Shift+B command for participation like we allow participation on hover or code complete. Then tasks.json execution would be simply one participant.

I could also use this. I am building a language server that does compilation inside itself. Being able to register for participation in Ctrl+Shift+B would make it a lot simpler for the user.

Besides problem matchers, ability to run commands as tasks allows using them as a prelaunch task in launch.json.

This would be super-helpful. Would it make sense to add a new type named command? Then you could do something like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "type": "command",
            "command": "my-extension.build",
            "args": [
                "${workspaceRoot}/main.file"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

my-extension.build would be a command contributed by an extension and args would be passed to this command.

The closed duplicate for this issue was on the On Deck milestone, so this issue should be added to that milestone.

Having a type: command for this makes sense to me.

Here's another use-case for allowing commands as tasks, if it helps!

My language server is able to build a project based on the code model it keeps in memory. It's significantly faster than launching a new instance of the compiler executable. I'd love to be able to register a command from the language server that I could expose as a build task.

Some large NPM commands seem to cause the TypeScript server to enter a bad state, solved easily with the "restart typescript server" command. Would be great to use dependsOn to build a task that kicks off this NPM work then restarts VSCode's TS server when complete.

Just ran into this issue. Still open, so I guess using VSCode-commands in tasks is not possible, yet? What would the recommended workflow be currently; make an extension?

And sorry, noob question: commands are mentioned here https://code.visualstudio.com/docs/editor/variables-reference#_settings-and-command-variables but where is the full reference? Can't seem to find it.

As far as I can tell, command variables are not allowed in tasks.json, which is very misleading in the document.

My use case is a task that forks code.exe to run a node script and allow the user to customize the arguments passed to it. If I had command variables I could write one to return process.argv0 from my extension.

@dschaefer this will come soon.

You can now have commands in tasks.json https://code.visualstudio.com/docs/editor/variables-reference#_settings-command-variables-and-input-variables

Very cool. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsccarl picture vsccarl  路  3Comments

sirius1024 picture sirius1024  路  3Comments

villiv picture villiv  路  3Comments

borekb picture borekb  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments