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

306 Views Asked by At

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!

2

There are 2 best solutions below

0
On BEST ANSWER

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

2
On

Quote from the v1.57 release note:

Task status on terminal tab

The status of a task is now shown in its terminal tab. For background tasks, the status is only shown when there is an associated problem matcher.

enter image description here

To adjust the associated problem matcher, please see Modifying an existing problem matcher.