Repository navigation
Description
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
dbaeumer commentedon Sep 1, 2016
@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.
defr0std commentedon Sep 2, 2016
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.
[-]Running extension tools as tasks[/-][+]Running commands as tasks[/+]dbaeumer commentedon Oct 27, 2016
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.
xavierzwirtz commentedon Dec 10, 2016
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.
ytimenkov commentedon Jun 12, 2017
Besides problem matchers, ability to run commands as tasks allows using them as a prelaunch task in launch.json.
dlech commentedon Aug 12, 2017
This would be super-helpful. Would it make sense to add a new
typenamedcommand? 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.buildwould be a command contributed by an extension andargswould be passed to this command.dlech commentedon Aug 24, 2017
The closed duplicate for this issue was on the
On Deckmilestone, so this issue should be added to that milestone.dbaeumer commentedon Aug 25, 2017
Having a
type: commandfor this makes sense to me.joshtynjala commentedon Feb 9, 2018
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.
ddurschlag6river commentedon Aug 29, 2018
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.
ednl commentedon Oct 9, 2018
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.
dschaefer commentedon Nov 16, 2018
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.
dbaeumer commentedon Nov 21, 2018
Doug Schaefer (@dschaefer) this will come soon.
alexr00 commentedon Dec 20, 2018
You can now have commands in tasks.json https://code.visualstudio.com/docs/editor/variables-reference#_settings-command-variables-and-input-variables
dschaefer commentedon Dec 20, 2018
Very cool. Thanks!