Add better WithDebugSupport extensibility api
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
PythonDebuggerPropertiesclass with extensive options (e.g.,StopOnEntry,AutoReload,PythonArgs, etc.) to model debugpy-compatible debugger properties for Python apps, and updatedPythonLaunchConfigurationto support these properties. - Updated the resource builder extension API with a new
WithPythonDebuggerPropertiesmethod, enabling users to customize Python debugger settings via a callback, and adjustedWithDebuggingto use these properties. [1] [2] - Added examples in
Program.csto demonstrate using.WithPythonDebuggerPropertiesfor 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_propertieseven if a matching debugger extension is not found. - Extended the
ExecutableLaunchConfigurationtype to include an optionaldebugger_propertiesfield.
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
IBackchannelLoggerProviderinterface 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
- If yes, did you have an API Review for it?
- [ ] No
- [X] Yes
- 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
- If yes, have you done a threat model and had a security review?
- [X] No
- [ ] Yes
- Does the change require an update in our Aspire docs?
- [ ] Yes
- Link to aspire-docs issue (consider using one of the following templates):
- [X] No
- [ ] Yes
🚀 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"
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
If this API is VS code specific we should include VSCode in the name right?
If this API is VS code specific we should include VSCode in the name right?
Yeah, that's a good point. Renamed the APIs