-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathswaCliTask.ts
More file actions
45 lines (38 loc) · 2.23 KB
/
swaCliTask.ts
File metadata and controls
45 lines (38 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IActionContext, registerEvent } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { swa } from '../../constants';
interface IRunningSwaTask {
processId: number;
}
const runningSwaTaskMap: Map<vscode.WorkspaceFolder | vscode.TaskScope, IRunningSwaTask> = new Map<vscode.WorkspaceFolder | vscode.TaskScope, IRunningSwaTask>();
export function registerSwaCliTaskEvents(): void {
registerEvent('staticWebApps.onDidTerminateDebugSession', vscode.debug.onDidTerminateDebugSession, async (context: IActionContext, debugSession: vscode.DebugSession) => {
context.errorHandling.suppressDisplay = true;
context.telemetry.suppressIfSuccessful = true;
if (!debugSession.parentSession && debugSession.workspaceFolder) {
stopSwaTaskIfRunning(debugSession.workspaceFolder);
}
});
registerEvent('staticWebApps.onDidStartTask', vscode.tasks.onDidStartTaskProcess, async (context: IActionContext, e: vscode.TaskProcessStartEvent) => {
context.errorHandling.suppressDisplay = true;
context.telemetry.suppressIfSuccessful = true;
if (e.execution.task.scope !== undefined && isSwaCliTask(e.execution.task)) {
runningSwaTaskMap.set(e.execution.task.scope, { processId: e.processId });
}
});
}
function isSwaCliTask(task: vscode.Task): boolean {
return !!(task.source === swa && task.execution instanceof vscode.ShellExecution && task.execution?.command === swa);
}
function stopSwaTaskIfRunning(workspaceFolder: vscode.WorkspaceFolder): void {
const runningFuncTask: IRunningSwaTask | undefined = runningSwaTaskMap.get(workspaceFolder);
if (runningFuncTask !== undefined) {
// Use `process.kill` because `TaskExecution.terminate` closes the terminal pane and erases all output
process.kill(runningFuncTask.processId);
runningSwaTaskMap.delete(workspaceFolder);
}
}