Skip to content

VS Code extension: Auto-restore on workspace open and config change#15546

Open
adamint wants to merge 7 commits intomicrosoft:mainfrom
adamint:dev/adamint/run-aspire-restore-branch-switch-workspace-open
Open

VS Code extension: Auto-restore on workspace open and config change#15546
adamint wants to merge 7 commits intomicrosoft:mainfrom
adamint:dev/adamint/run-aspire-restore-branch-switch-workspace-open

Conversation

@adamint
Copy link
Copy Markdown
Member

@adamint adamint commented Mar 24, 2026

Description

Adds automatic aspire restore execution in the VS Code extension to keep integration packages in sync with aspire.config.json.

Problem: When switching git branches that have different Aspire integrations configured, the editor shows squiggly errors until you manually run aspire restore. This is a common friction point during development.

Solution: The new AspirePackageRestoreProvider automatically runs aspire restore:

  • On workspace open — restores all aspire.config.json files found in the workspace
  • On config content change — a FileSystemWatcher monitors aspire.config.json files; when content actually changes (e.g., branch switch, manual edit), it runs restore

Features

  • Concurrency-limited parallel restore — up to 4 concurrent restores, with progress shown in the status bar (Running aspire restore (2/5 projects) ...)
  • Status bar feedback — spinner during restore, checkmark on completion, error icon with red background on failure
  • Clickable status bar — clicking the status bar item runs the aspire restore command in the Aspire terminal
  • Aspire: Restore command — new command palette entry (aspire-vscode.restore) to manually trigger restore
  • Pending restore queue — if a config file changes while restore is already running for that directory, it queues a re-restore instead of dropping the change
  • Content-based change detection — only triggers restore when aspire.config.json content actually changes, not on every file-save event
  • Baseline tracking_lastContent is only updated after a successful restore, so failures don't prevent retries on the next change
  • Configurable — controlled by aspire.enableAutoRestore setting (default: true); toggling the setting on immediately starts watching and restoring
  • Timeout protection — restores time out after 2 minutes with proper cleanup
  • Graceful disposal — kills child processes, clears timeouts, and disposes watchers on extension deactivation

Testing

I tested this using:

  1. The playground folder, since there are over a hundred TS apphosts. The apphosts are restored slowly, respecting the concurrency limit. This should not be an issue in practice, as the likelihood of a repo having hundreds of apphosts is low.
  2. A separate local git repo where one branch had a redis package entry, and another branch had redis + PostgreSQL — switching branches triggers restore automatically.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Copilot AI review requested due to automatic review settings March 24, 2026 20:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

🚀 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15546

Or

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an auto-restore mechanism to the VS Code extension so aspire restore is run automatically to keep integration packages in sync with aspire.config.json, reducing editor squiggles after branch switches/config edits.

Changes:

  • Introduces AspirePackageRestoreProvider to run aspire restore on workspace open and on aspire.config.json changes (with a concurrency cap and status bar progress).
  • Adds the aspire.enableAutoRestore setting (default true) plus localized strings for restore progress and results.
  • Updates TypeScript playground aspire.config.json files and refreshes generated AppHost .modules outputs.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
playground/TypeScriptApps/RpsArena/aspire.config.json Moves package versions to 13.2.0 and removes daily SDK/channel fields.
playground/TypeScriptApps/AzureFunctionsSample/aspire.config.json Adds appHost metadata and moves package versions to 13.2.0.
playground/TypeScriptApps/AzureFunctionsSample/AppHost/.modules/transport.ts Updates generated transport layer (cancellation, marshalling, connection/auth flow).
playground/TypeScriptApps/AzureFunctionsSample/AppHost/.modules/base.ts Updates generated base SDK types (ReferenceExpression enhancements, transport value serialization).
playground/TypeScriptApps/AzureFunctionsSample/AppHost/.modules/.codegen-hash Updates codegen hash to reflect regenerated modules.
extension/src/utils/settings.ts Adds accessor for enableAutoRestore.
extension/src/utils/AspirePackageRestoreProvider.ts New provider that runs/monitors aspire restore and shows status bar progress.
extension/src/loc/strings.ts Adds localized runtime strings for restore progress/results.
extension/src/extension.ts Wires up the new auto-restore provider during activation.
extension/package.nls.json Adds localized description for the new setting and restore messages.
extension/package.json Defines the new aspire.enableAutoRestore configuration setting.
extension/loc/xlf/aspire-vscode.xlf Adds localization units for new strings/setting description.

Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review — focused on problems only. 5 inline comments on the new AspirePackageRestoreProvider.

adamint and others added 6 commits March 28, 2026 16:43
…g restores, separate errors, fix timeout leak, handle unhandled promise
Co-authored-by: Ankit Jain <radical@gmail.com>
… status bar

- Fix floating promises in watcher handlers (void + catch)
- Fix timing bug: .finally() runs before _hadFailure is updated
- Extract _scheduleHide() for status bar auto-hide logic
- Add explicit _showProgress() call on success path
- Only update _lastContent after successful restore
- Add settled flag to prevent double resolve/reject
- Add try/catch around proc.kill()
- Replace magic numbers with named constants
- Fix space before ellipsis in localized strings
- Wire up AspirePackageRestoreProvider in extension.ts
- Add aspire-vscode.restore command
- Show failure state in status bar with error background
- Make status bar item clickable (runs restore command)
- Early returns (file-read failure, unchanged content) now increment
  _completed so the progress bar doesn't get stuck
- Skip _total increment when a re-restore is already queued for the
  same directory, preventing counter inflation from duplicate events
@adamint adamint force-pushed the dev/adamint/run-aspire-restore-branch-switch-workspace-open branch from 1c0e42c to 8a23f34 Compare March 28, 2026 23:44
- Guard counter mutations during batch with _batchRunning flag
- Replace single _hadFailure boolean with per-directory _failedDirs set
- Use single _hideTimeout reference instead of accumulating timeouts
- Change recursive pending-restore tail call to iterative while loop

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants