Skip to content

Running commands as tasks #11396

Closed
Closed

Description

@defr0std

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.

Activity

  1. added
    tasks
    feature-request
    on Sep 1, 2016
  2. dbaeumer commented on Sep 1, 2016

    @dbaeumer
    Member

    @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.

  3. defr0std commented on Sep 2, 2016

    @defr0std
    Author

    Thanks, Dirk Bäumer (@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.

  4. changed the title [-]Running extension tools as tasks[/-] [+]Running commands as tasks[/+] on Sep 2, 2016
  5. dbaeumer commented on Oct 27, 2016

    @dbaeumer
    Member

    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.

  6. xavierzwirtz commented on Dec 10, 2016

    @xavierzwirtz

    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.

  7. ytimenkov commented on Jun 12, 2017

    @ytimenkov

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

  8. dlech commented on Aug 12, 2017

    @dlech
    Contributor

    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.

  9. dlech commented on Aug 24, 2017

    @dlech
    Contributor

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

  10. dbaeumer commented on Aug 25, 2017

    @dbaeumer
    Member

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

  11. joshtynjala commented on Feb 9, 2018

    @joshtynjala

    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.

  12. ddurschlag6river commented on Aug 29, 2018

    @ddurschlag6river

    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.

  13. ednl commented on Oct 9, 2018

    @ednl

    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.

  14. dschaefer commented on Nov 16, 2018

    @dschaefer

    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.

  15. dbaeumer commented on Nov 21, 2018

    @dbaeumer
    Member

    Doug Schaefer (@dschaefer) this will come soon.

  16. dschaefer commented on Dec 20, 2018

    @dschaefer

    Very cool. Thanks!

  17. locked and limited conversation to collaborators on Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requesttasks

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions