-
Notifications
You must be signed in to change notification settings - Fork 149
Skip emulator setup if preLaunchTask chain includes mention of them
#4959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MicroFish91
wants to merge
11
commits into
main
Choose a base branch
from
mwf/debug-dont-prompt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−21
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1486306
Search preLaunchTasks for emulators
MicroFish91 43f3fd9
Update comment
MicroFish91 787d714
Add tests and update a comment
MicroFish91 4e65473
Fix configuration target scope and empty dir
MicroFish91 5ae36d6
Update task inject pattern for tests
MicroFish91 f50ee35
Add a setting
MicroFish91 4279d95
Rename a var
MicroFish91 a5e0677
Rename another var
MicroFish91 2f3bb5e
Improve nls wording
MicroFish91 c57cf1c
Add typeof string guard
MicroFish91 6dcd3de
Check workspace folder setting as well
MicroFish91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { ITask } from '../vsCodeConfig/tasks'; | ||
|
|
||
| /** | ||
| * Resolves the full chain of tasks associated with a given `preLaunchTask`. | ||
| * Recursively follows the `dependsOn` references found in the `tasks.json`. | ||
| */ | ||
| export function getPreLaunchTaskChain(tasks: ITask[], preLaunchTask: string): string[] { | ||
| const tasksMap = new Map<string, ITask>(); | ||
|
|
||
| for (const task of tasks) { | ||
| if (task.label) { | ||
| tasksMap.set(task.label, task); | ||
| } | ||
| } | ||
|
|
||
| const dependentTasks = new Set<string>(); | ||
|
|
||
| function getDependentTasks(name: string): void { | ||
| const task = tasksMap.get(name); | ||
| if (!task || dependentTasks.has(name)) { | ||
| return; | ||
| } | ||
| dependentTasks.add(name); | ||
|
|
||
| const dependsOn: unknown = task?.dependsOn; | ||
| if (typeof dependsOn === 'string') { | ||
| getDependentTasks(dependsOn); | ||
| } else if (Array.isArray(dependsOn)) { | ||
| for (const dep of dependsOn) { | ||
| if (typeof dep === 'string') { | ||
| getDependentTasks(dep); | ||
| } | ||
| } | ||
| } | ||
|
MicroFish91 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (!tasksMap.has(preLaunchTask)) { | ||
| return []; | ||
| } | ||
|
|
||
| getDependentTasks(preLaunchTask); | ||
| return Array.from(dependentTasks.values()); | ||
|
MicroFish91 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ import { durableUtils } from '../utils/durableUtils'; | |
| import { isPythonV2Plus } from '../utils/programmingModelUtils'; | ||
| import { getDebugConfigs, isDebugConfigEqual } from '../vsCodeConfig/launch'; | ||
| import { getWorkspaceSetting, tryGetFunctionsWorkerRuntimeForProject } from "../vsCodeConfig/settings"; | ||
| import { getTasks } from '../vsCodeConfig/tasks'; | ||
| import { getPreLaunchTaskChain } from './getPreLaunchTaskChain'; | ||
| import { validateDTSConnectionPreDebug } from './storageProviders/validateDTSConnectionPreDebug'; | ||
| import { validateNetheriteConnectionPreDebug } from './storageProviders/validateNetheriteConnectionPreDebug'; | ||
| import { validateSQLConnectionPreDebug } from './storageProviders/validateSQLConnectionPreDebug'; | ||
|
|
@@ -32,12 +34,23 @@ export interface IPreDebugContext extends Omit<ISetConnectionSettingContext, 'pr | |
| projectPath?: string; | ||
| } | ||
|
|
||
| const emulatorTaskRegExp: RegExp = /azurite|emulator/i; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worried this could be pretty fragile |
||
|
|
||
| export async function preDebugValidate(actionContext: IActionContext, debugConfig: vscode.DebugConfiguration): Promise<IPreDebugValidateResult> { | ||
| const context: IPreDebugContext = Object.assign(actionContext, { action: CodeAction.Debug }); | ||
| const workspace: vscode.WorkspaceFolder = getMatchingWorkspace(debugConfig); | ||
| let shouldContinue: boolean; | ||
| context.telemetry.properties.debugType = debugConfig.type; | ||
|
|
||
| // If one of the `preLaunchTasks` already handles starting emulators, assume the user is already on top of automating this part of the setup | ||
| const preLaunchTaskName: string | undefined = debugConfig.preLaunchTask; | ||
| const preLaunchTaskChain: string[] = typeof preLaunchTaskName === 'string' ? getPreLaunchTaskChain(getTasks(workspace), preLaunchTaskName) : []; | ||
| const hasEmulatorTask: boolean = preLaunchTaskChain.some(label => emulatorTaskRegExp.test(label)); | ||
| const forceEmulatorValidation: boolean = !!getWorkspaceSetting<boolean>('forceEmulatorValidation', workspace.uri.fsPath); | ||
| const skipEmulatorValidation: boolean = hasEmulatorTask && !forceEmulatorValidation; | ||
| context.telemetry.properties.hasEmulatorTask = String(hasEmulatorTask); | ||
| context.telemetry.properties.forceEmulatorValidation = String(forceEmulatorValidation); | ||
|
|
||
| try { | ||
| context.telemetry.properties.lastValidateStep = 'funcInstalled'; | ||
| const message: string = localize('installFuncTools', 'You must have the Azure Functions Core Tools installed to debug your local functions.'); | ||
|
|
@@ -62,28 +75,30 @@ export async function preDebugValidate(actionContext: IActionContext, debugConfi | |
| context.telemetry.properties.lastValidateStep = 'workerRuntime'; | ||
| await validateWorkerRuntime(context, projectLanguage, context.projectPath); | ||
|
|
||
| switch (durableStorageType) { | ||
| case DurableBackend.DTS: | ||
| context.telemetry.properties.lastValidateStep = 'dtsConnection'; | ||
| await validateDTSConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.Netherite: | ||
| context.telemetry.properties.lastValidateStep = 'netheriteConnection'; | ||
| await validateNetheriteConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.SQL: | ||
| context.telemetry.properties.lastValidateStep = 'sqlDbConnection'; | ||
| await validateSQLConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.Storage: | ||
| default: | ||
| if (!skipEmulatorValidation) { | ||
| switch (durableStorageType) { | ||
| case DurableBackend.DTS: | ||
| context.telemetry.properties.lastValidateStep = 'dtsConnection'; | ||
| await validateDTSConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.Netherite: | ||
| context.telemetry.properties.lastValidateStep = 'netheriteConnection'; | ||
| await validateNetheriteConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.SQL: | ||
| context.telemetry.properties.lastValidateStep = 'sqlDbConnection'; | ||
| await validateSQLConnectionPreDebug(context, context.projectPath); | ||
| break; | ||
| case DurableBackend.Storage: | ||
| default: | ||
| } | ||
|
|
||
| context.telemetry.properties.lastValidateStep = 'azureWebJobsStorage'; | ||
| await validateAzureWebJobsStorage(context, context.projectPath); | ||
|
|
||
| context.telemetry.properties.lastValidateStep = 'emulatorRunning'; | ||
| shouldContinue = await validateEmulatorIsRunning(context, context.projectPath); | ||
| } | ||
|
|
||
| context.telemetry.properties.lastValidateStep = 'azureWebJobsStorage'; | ||
| await validateAzureWebJobsStorage(context, context.projectPath); | ||
|
|
||
| context.telemetry.properties.lastValidateStep = 'emulatorRunning'; | ||
| shouldContinue = await validateEmulatorIsRunning(context, context.projectPath); | ||
| } | ||
| } | ||
| } catch (error) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as assert from 'assert'; | ||
| import { getPreLaunchTaskChain } from '../src/debug/getPreLaunchTaskChain'; | ||
| import type { ITask } from '../src/vsCodeConfig/tasks'; | ||
|
|
||
| suite('getPreLaunchTaskChain', () => { | ||
| test('returns only the preLaunchTask when it has no dependencies', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', command: 'npm run build' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build']); | ||
| }); | ||
|
|
||
| test('returns empty array when preLaunchTask is not found in tasks list', () => { | ||
| const result = getPreLaunchTaskChain([], 'nonexistent'); | ||
| assert.deepStrictEqual(result, []); | ||
|
MicroFish91 marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test('resolves a single string dependsOn', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', command: 'npm run build', dependsOn: 'compile' }, | ||
| { type: 'shell', label: 'compile', command: 'tsc' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build', 'compile']); | ||
| }); | ||
|
|
||
| test('resolves an array dependsOn', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', command: 'npm run build', dependsOn: ['compile', 'lint'] }, | ||
| { type: 'shell', label: 'compile', command: 'tsc' }, | ||
| { type: 'shell', label: 'lint', command: 'eslint .' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build', 'compile', 'lint']); | ||
| }); | ||
|
|
||
| test('resolves chained dependencies', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', dependsOn: 'compile' }, | ||
| { type: 'shell', label: 'compile', dependsOn: 'clean' }, | ||
| { type: 'shell', label: 'clean', command: 'rm -rf dist' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build', 'compile', 'clean']); | ||
| }); | ||
|
|
||
| test('handles circular dependencies without infinite loop', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'a', dependsOn: 'b' }, | ||
| { type: 'shell', label: 'b', dependsOn: 'a' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'a'); | ||
| assert.deepStrictEqual(result, ['a', 'b']); | ||
| }); | ||
|
|
||
| test('excludes dependency names when they are not defined tasks', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', dependsOn: 'unknown-task' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build']); | ||
| }); | ||
|
|
||
| test('skips non-string values in dependsOn array', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', dependsOn: ['compile', 42, null, 'lint'] } as unknown as ITask, | ||
| { type: 'shell', label: 'compile', command: 'tsc' }, | ||
| { type: 'shell', label: 'lint', command: 'eslint .' } | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build', 'compile', 'lint']); | ||
| }); | ||
|
|
||
| test('skips tasks without labels when building task map', () => { | ||
| const tasks: ITask[] = [ | ||
| { type: 'shell', label: 'build', dependsOn: 'compile' }, | ||
| { type: 'shell', command: 'tsc' } // no label - should not be in the task map | ||
| ]; | ||
| const result = getPreLaunchTaskChain(tasks, 'build'); | ||
| assert.deepStrictEqual(result, ['build']); | ||
| }); | ||
|
|
||
| test('returns empty array for empty string preLaunchTask', () => { | ||
| const result = getPreLaunchTaskChain([], ''); | ||
| assert.deepStrictEqual(result, []); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems to be a great candidate for unit tests