Skip to content

Commit 1486306

Browse files
committed
Search preLaunchTasks for emulators
1 parent 57d1500 commit 1486306

File tree

2 files changed

+82
-21
lines changed

2 files changed

+82
-21
lines changed

src/debug/getPreLaunchTaskChain.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { getTasks, ITask } from '../vsCodeConfig/tasks';
8+
9+
/**
10+
* Resolves the full chain of tasks associated with a given `preLaunchTask`.
11+
* Recursively follows the `dependsOn` references found in the `tasks.json`.
12+
*/
13+
export function getPreLaunchTaskChain(workspace: vscode.WorkspaceFolder, preLaunchTask: string): string[] {
14+
const allTasks: ITask[] = getTasks(workspace);
15+
const allTasksMap = new Map<string, ITask>();
16+
17+
for (const task of allTasks) {
18+
if (task.label) {
19+
allTasksMap.set(task.label, task);
20+
}
21+
}
22+
23+
const dependentTasks = new Set<string>();
24+
25+
function getDependentTasks(name: string): void {
26+
if (dependentTasks.has(name)) {
27+
return;
28+
}
29+
dependentTasks.add(name);
30+
31+
const task = allTasksMap.get(name);
32+
if (!task) {
33+
return;
34+
}
35+
36+
const dependsOn: unknown = task?.dependsOn;
37+
if (typeof dependsOn === 'string') {
38+
getDependentTasks(dependsOn);
39+
} else if (Array.isArray(dependsOn)) {
40+
for (const dep of dependsOn) {
41+
if (typeof dep === 'string') {
42+
getDependentTasks(dep);
43+
}
44+
}
45+
}
46+
}
47+
48+
getDependentTasks(preLaunchTask);
49+
return Array.from(dependentTasks.values());
50+
}

src/debug/validatePreDebug.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { durableUtils } from '../utils/durableUtils';
1818
import { isPythonV2Plus } from '../utils/programmingModelUtils';
1919
import { getDebugConfigs, isDebugConfigEqual } from '../vsCodeConfig/launch';
2020
import { getWorkspaceSetting, tryGetFunctionsWorkerRuntimeForProject } from "../vsCodeConfig/settings";
21+
import { getPreLaunchTaskChain } from './getPreLaunchTaskChain';
2122
import { validateDTSConnectionPreDebug } from './storageProviders/validateDTSConnectionPreDebug';
2223
import { validateNetheriteConnectionPreDebug } from './storageProviders/validateNetheriteConnectionPreDebug';
2324
import { validateSQLConnectionPreDebug } from './storageProviders/validateSQLConnectionPreDebug';
@@ -32,12 +33,20 @@ export interface IPreDebugContext extends Omit<ISetConnectionSettingContext, 'pr
3233
projectPath?: string;
3334
}
3435

36+
const emulatorTaskRegExp: RegExp = /azurite|emulator/i;
37+
3538
export async function preDebugValidate(actionContext: IActionContext, debugConfig: vscode.DebugConfiguration): Promise<IPreDebugValidateResult> {
3639
const context: IPreDebugContext = Object.assign(actionContext, { action: CodeAction.Debug });
3740
const workspace: vscode.WorkspaceFolder = getMatchingWorkspace(debugConfig);
3841
let shouldContinue: boolean;
3942
context.telemetry.properties.debugType = debugConfig.type;
4043

44+
// If one of the `preLaunchTasks` already handles starting emulators, we should skip the pre-validate prompts and setup for them
45+
const preLaunchTaskName: string | undefined = debugConfig.preLaunchTask;
46+
const preLaunchTaskChain: string[] = preLaunchTaskName ? getPreLaunchTaskChain(workspace, preLaunchTaskName) : [];
47+
const hasEmulatorTask: boolean = preLaunchTaskChain.some(label => emulatorTaskRegExp.test(label));
48+
context.telemetry.properties.hasEmulatorTask = String(hasEmulatorTask);
49+
4150
try {
4251
context.telemetry.properties.lastValidateStep = 'funcInstalled';
4352
const message: string = localize('installFuncTools', 'You must have the Azure Functions Core Tools installed to debug your local functions.');
@@ -62,28 +71,30 @@ export async function preDebugValidate(actionContext: IActionContext, debugConfi
6271
context.telemetry.properties.lastValidateStep = 'workerRuntime';
6372
await validateWorkerRuntime(context, projectLanguage, context.projectPath);
6473

65-
switch (durableStorageType) {
66-
case DurableBackend.DTS:
67-
context.telemetry.properties.lastValidateStep = 'dtsConnection';
68-
await validateDTSConnectionPreDebug(context, context.projectPath);
69-
break;
70-
case DurableBackend.Netherite:
71-
context.telemetry.properties.lastValidateStep = 'netheriteConnection';
72-
await validateNetheriteConnectionPreDebug(context, context.projectPath);
73-
break;
74-
case DurableBackend.SQL:
75-
context.telemetry.properties.lastValidateStep = 'sqlDbConnection';
76-
await validateSQLConnectionPreDebug(context, context.projectPath);
77-
break;
78-
case DurableBackend.Storage:
79-
default:
74+
if (!hasEmulatorTask) {
75+
switch (durableStorageType) {
76+
case DurableBackend.DTS:
77+
context.telemetry.properties.lastValidateStep = 'dtsConnection';
78+
await validateDTSConnectionPreDebug(context, context.projectPath);
79+
break;
80+
case DurableBackend.Netherite:
81+
context.telemetry.properties.lastValidateStep = 'netheriteConnection';
82+
await validateNetheriteConnectionPreDebug(context, context.projectPath);
83+
break;
84+
case DurableBackend.SQL:
85+
context.telemetry.properties.lastValidateStep = 'sqlDbConnection';
86+
await validateSQLConnectionPreDebug(context, context.projectPath);
87+
break;
88+
case DurableBackend.Storage:
89+
default:
90+
}
91+
92+
context.telemetry.properties.lastValidateStep = 'azureWebJobsStorage';
93+
await validateAzureWebJobsStorage(context, context.projectPath);
94+
95+
context.telemetry.properties.lastValidateStep = 'emulatorRunning';
96+
shouldContinue = hasEmulatorTask || await validateEmulatorIsRunning(context, context.projectPath);
8097
}
81-
82-
context.telemetry.properties.lastValidateStep = 'azureWebJobsStorage';
83-
await validateAzureWebJobsStorage(context, context.projectPath);
84-
85-
context.telemetry.properties.lastValidateStep = 'emulatorRunning';
86-
shouldContinue = await validateEmulatorIsRunning(context, context.projectPath);
8798
}
8899
}
89100
} catch (error) {

0 commit comments

Comments
 (0)