How do get provideTasks method of registerTaskProv

2019-07-18 14:49发布

问题:

I am trying to get the new registerTaskProvider method in the VSCode Task API working within my extension, and I have been unable to make this work so far.

I have used the npm extension as a basis. Here are the steps that I have followed:

  1. Used yo to create a new extension
  2. Updated package.json to include a new activationEvent onCommand:workbench.action.tasks.runTask
  3. Updated package.json to include configuration and taskDefinitions sections in the contributes section
  4. Added the following code to the extension.ts file

NOTE: I realise that the linked code won't actually provide any additional tasks, I am just using this code as a basis for testing.

Now, when I try to debug the extension, the provideTasks method is never invoked. What am I missing?

Also, the only way to have the activate method called is when I invoke the Hello World command. However, I might not have a command associated with the extension. How can I force the activation of the extension?

Is there any additional documentation on how to get started with the registerTaskProvider API?

I have added a sample repository that has the current work to date.

回答1:

Turns out that this was a case of PEBKAC.

After a Twitter discussion with Erich Gamma, he showed me that the provideTasks method is only consulted when you begin running a task. As shown here:

https://twitter.com/ErichGamma/status/885823516293177346

I had assumed that the provideTasks method would be consulted on activation of the extension.