Skip to content

feat: add "extract to module" functionality - #18790

Open
Engin Polat (polatengin) wants to merge 4 commits into
mainfrom
polatengin/14482-extract-to-module
Open

Engin Polat (polatengin) wants to merge 4 commits into
mainfrom
polatengin/14482-extract-to-module

Conversation

@polatengin

@polatengin Engin Polat (polatengin) commented Jan 5, 2026

Copy link
Copy Markdown
Member

Fixes #14482

Description

  • Adds a VS Code “Extract to Module...” command that sends a new bicep/extractToModule LSP request, writes the generated module file, replaces the selected top-level resources with a module declaration, and initiates rename on the module symbol.
  • Language server validates selections (whole top-level resources only, no external references), lifts external params/vars into module parameters, builds the module text, and emits success/failure telemetry for extract-to-module operations.

Added new integration tests covering edge cases for extract-to-module feature;

  • Fails gracefully for an empty selection.
  • Fails when selecting a non-resource declaration, such as a variable.
  • Fails when the selection mixes a resource declaration with an unsupported declaration.
  • Fails when a selected resource is referenced outside the extracted selection.
  • Supports extracting multiple resources when references stay internal to the selected block.
  • Creates module parameters for external param and var dependencies used by the extracted resources.
  • Emits each external dependency only once, even when referenced multiple times.
  • Avoids module symbol name collisions with existing declarations.
  • Sanitizes module symbol names derived from nested module file paths while preserving the relative path.
  • Falls back to extractedModule when the module file name cannot produce a valid Bicep identifier.

Checklist

Microsoft Reviewers: Open in CodeFlow

@github-actions

github-actions Bot commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Test this change out locally with the following install scripts (Action run 34042674378)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 34042674378
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 34042674378"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 34042674378
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 34042674378"

@torreymicrosoft

Torrey Trahanovsky (torreymicrosoft) commented Jul 1, 2026

Copy link
Copy Markdown
Member

The user-facing documentation for this feature is now being drafted directly in the Azure docs repo, not as a PR here: MicrosoftDocs/azure-docs-pr#317807 (draft).

Going forward, please open Bicep product documentation ask directly in azure-docs-pr under articles/azure-resource-manager/bicep/, rather than as a PR in this repo. Then link it to your PR. That keeps content in the repo that publishes to Learn and routes review to the docs owners automatically.

FYI - stephaniezyen Engin Polat (@polatengin) Xelu86

cc Engin Polat (@polatengin) Xelu86 to co-own the technical content. Xelu86 (our doc writer) owns the final docs pass. No action needed on this code PR: the 📘 Docs Needed label moves to 📘 Docs Completed once the docs PR merges.

@polatengin Engin Polat (polatengin) moved this from Done to In Review in Bicep Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Extract to module

2 participants