visual-studio-codevscode-tasksvscode-problem-matcher

How to change a VS Code task's status ? (VS Code extension development)


I am developing a VS Code extension and there is a customized task in my extension. Everything works well before an update in VS Code recently. The task now seems has a status like below screenshot:

enter image description here

In the terminal / task window, it shows "Task has errors" and also the task colors red. But actually my task executed correctly. I remember this 'status' doesn't exist before. Do anyone know how to clear this status or how to modify it? I didn't find related APIs or commands in VS Code official document. Could you help give some guidance?

And this is my task settings ('targets' is a customized property):

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "basiccompile",
            "targets": ["TEST_FILE"],
            "label": "basiccompile",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Thanks a lot!


Solution

  • I have got the solution. According to the latest sample of task-provider, when emit the a close event, you can pass 0 to fire(), then the status would be success.

    class CustomBuildTaskTerminal implements vscode.Pseudoterminal {
        // ...
    
        private closeEmitter = new vscode.EventEmitter<number>();
        onDidClose?: vscode.Event<number> = this.closeEmitter.event;
    
        // ...
        
        open(initialDimensions: vscode.TerminalDimensions | undefined): void {
            // ...
            
            this.closeEmitter.fire(0);
        }
    

    Here is the official sample from VS code: https://github.com/microsoft/vscode-extension-samples/blob/b7d400880ac08100bd168a22b70d217e6abfd6b9/task-provider-sample/src/customTaskProvider.ts#L129