aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Add better WithDebugSupport extensibility api

Open adamint opened this issue 2 months ago • 4 comments

Description

Creates two separate WithDebugSupport implementations. One, for when a debugger extension will exist for a language. This is only necessary when we need deep integration with VS Code or its extensions themselves. The other, in ResourceBuilderExtensions, allows for extending VS Code debugger support to any arbitrary resource type by modeling a debug configuration in code.

To specify specific debugger properties, you can use the WithDebuggerProperties extension method. Implementers will create their own subclass of DebuggerProperties, which contains the minimal required set of properties required for a vs code debug configuration. I've rewritten Python debug support to support this new pattern. Inside WithDebugging, basic debugger properties for Python are set, and if WithPythonDebuggerProperties has been called, its callback is invoked to modify the configuration.

An example use of this API is:

builder.AddPythonApp("instrumented-script", "../instrumented_script", "main.py")
    .WithPythonDebuggerProperties(props =>
    {
        props.StopOnEntry = true; // sets the stopOnEntry property
    });

=================

This pull request introduces enhanced support for Python debugging in Aspire applications, focusing on improved debugger configuration flexibility and integration with VS Code. The key changes include the introduction of a customizable Python debugger properties API, updates to launch configuration handling, and improvements to extension capabilities and resource builder APIs.

Debugger and Launch Configuration Enhancements:

  • Added a new PythonDebuggerProperties class with extensive options (e.g., StopOnEntry, AutoReload, PythonArgs, etc.) to model debugpy-compatible debugger properties for Python apps, and updated PythonLaunchConfiguration to support these properties.
  • Updated the resource builder extension API with a new WithPythonDebuggerProperties method, enabling users to customize Python debugger settings via a callback, and adjusted WithDebugging to use these properties. [1] [2]
  • Added examples in Program.cs to demonstrate using .WithPythonDebuggerProperties for custom debugging scenarios (e.g., stopping on entry, enabling auto-reload). [1] [2]

VS Code Extension and Debugger Integration:

  • Updated the VS Code extension's debug session creation logic to support configurations that provide custom debugger_properties (e.g., from Python), and to merge these properties into the debug configuration. [1] [2]
  • Modified the extension's capability detection to include all installed extensions as capabilities, improving extension awareness.
  • Adjusted the debug server logic to allow launch configurations with custom debugger_properties even if a matching debugger extension is not found.
  • Extended the ExecutableLaunchConfiguration type to include an optional debugger_properties field.

Infrastructure and Internal Improvements:

  • Added shared utility files (e.g., ResourceDebugSupportExtensions.cs) to both Python and core hosting projects to support debugger property configuration and extension. [1] [2]
  • Introduced an IBackchannelLoggerProvider interface for improved logging infrastructure.
  • Minor internal refactoring and logging improvements in resource builder extensions and DCP executor. [1] [2] [3] [4]

These changes collectively make Python debugging in Aspire more flexible, user-friendly, and better integrated with development tools. Fixes # (issue)

Checklist

  • Is this feature complete?
    • [X] Yes. Ready to ship.
    • [ ] No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • [X] Yes
    • [ ] No
  • Did you add public API?
    • [X] Yes
      • If yes, did you have an API Review for it?
        • [ ] Yes
        • [ ] No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • [X] Yes
        • [ ] No
    • [ ] No
  • Does the change make any security assumptions or guarantees?
    • [ ] Yes
      • If yes, have you done a threat model and had a security review?
        • [ ] Yes
        • [ ] No
    • [X] No
  • Does the change require an update in our Aspire docs?

adamint avatar Nov 05 '25 19:11 adamint

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12711

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12711"

github-actions[bot] avatar Nov 05 '25 19:11 github-actions[bot]

Will move the JS stuff out, it can be brought back when the time is right. I think these APIs are important to get in

adamint avatar Nov 11 '25 01:11 adamint

If this API is VS code specific we should include VSCode in the name right?

davidfowl avatar Nov 13 '25 08:11 davidfowl

If this API is VS code specific we should include VSCode in the name right?

Yeah, that's a good point. Renamed the APIs

adamint avatar Nov 13 '25 16:11 adamint