From f3deb3cedc2b319c60387fa14419f246ed2d049c Mon Sep 17 00:00:00 2001 From: Jeffrey Chen Date: Mon, 29 Dec 2025 16:32:05 +0000 Subject: [PATCH] Export `WaitForDebugger` for extension command debugging --- cli/azd/pkg/azdext/debugger.go | 6 ++++-- cli/azd/pkg/azdext/extension_host.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/azd/pkg/azdext/debugger.go b/cli/azd/pkg/azdext/debugger.go index e84ff44628e..88c50c7cb82 100644 --- a/cli/azd/pkg/azdext/debugger.go +++ b/cli/azd/pkg/azdext/debugger.go @@ -15,9 +15,10 @@ import ( "google.golang.org/grpc/metadata" ) -// waitForDebugger checks if AZD_EXT_DEBUG environment variable is set to a truthy value. +// WaitForDebugger checks if AZD_EXT_DEBUG environment variable is set to a truthy value. // If set, prompts the user to attach a debugger to the current process. -func waitForDebugger(ctx context.Context, extensionId string, azdClient *AzdClient) { +// This should be called at the start of extension command implementations to enable debugging. +func WaitForDebugger(ctx context.Context, azdClient *AzdClient) { debugValue := os.Getenv("AZD_EXT_DEBUG") if debugValue == "" { return @@ -28,6 +29,7 @@ func waitForDebugger(ctx context.Context, extensionId string, azdClient *AzdClie return } + extensionId := getExtensionId(ctx) message := fmt.Sprintf("Extension '%s' ready to debug (pid: %d).", extensionId, os.Getpid()) _, err = azdClient.Prompt().Confirm(ctx, &ConfirmRequest{ diff --git a/cli/azd/pkg/azdext/extension_host.go b/cli/azd/pkg/azdext/extension_host.go index f22498a8644..cb844e0722d 100644 --- a/cli/azd/pkg/azdext/extension_host.go +++ b/cli/azd/pkg/azdext/extension_host.go @@ -146,7 +146,7 @@ func (er *ExtensionHost) Run(ctx context.Context) error { er.init(extensionId) // Wait for debugger if AZD_EXT_DEBUG is set - waitForDebugger(ctx, extensionId, er.client) + WaitForDebugger(ctx, er.client) // Determine which managers will be active hasServiceTargets := len(er.serviceTargets) > 0