Refactoring to convert between a namespace with one nested module and a root-level module - #20536
Open
xperiandri wants to merge 4 commits into
Open
xperiandri wants to merge 4 commits into
xperiandri wants to merge 4 commits into
Conversation
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
xperiandri
force-pushed
the
feature/namespace-module-refactoring
branch
from
September 14, 2026 11:09
e51d4cd to
7863f7e
Compare
xperiandri
marked this pull request as ready for review
September 14, 2026 19:40
…ot-level module With the caret on the header, 'namespace A.B' holding a single 'module C =' converts to 'module A.B.C', and 'module A.B.C' converts back. The compiler treats the two forms as the same module, so the edit only rewrites the header and moves the body by the nested module's indentation; lines inside multi-line string literals keep their text. Files with a signature file are not offered the conversion, because converting one side would unpair it from the other. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The namespace line and the opens were deleted as one block ending at the first kept line, so a comment between the namespace and the opens left the opens in place while copies were added under the new header. Each of them is now deleted on its own, with the blank lines after it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…e of its section Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
xperiandri
force-pushed
the
feature/namespace-module-refactoring
branch
from
September 14, 2026 19:46
5f7ae33 to
afc3127
Compare
Contributor
|
🔍 Tooling Safety Check — Affects-Design-Time
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a refactoring (
Ctrl+., caret on the header line) that converts a file written asnamespace A.Bwith a single nestedmodule C =into a root-levelmodule A.B.C, and a root-levelmodule A.B.Cback intonamespace A.Bwith a nestedmodule C =.The compiler already lowers
module [rec] A.B.Mintonamespace [rec] A.B+module M =internally, so the two forms are the same module by construction; the refactoring only rewrites the header and re-indents the body by line, the same technique Roslyn's block ⟷ file-scoped namespace conversion uses (no formatter call, deliberately).Applicability, nested → root: exactly one
namespacein the file, whose declarations are a single nested module, optionally preceded byopens (no type, no second module, noopenafter the module — moving those would change their compiled name or what they resolve against). The leadingopens move to just below the newmodule A.B.Cheader, since a root-style module declaration must come first in the file; comments and XML doc between the namespace and the module stay in front of the new header.recon the namespace withoutrecon the module becomesmodule rec A.B.C. Root → nested is the mirror. Both directions refuse when the file has a paired.fsi: converting only the implementation would unpair it from its signature byQualifiedNameOfFile, which the compiler reports as FS0240. Attributes, XML doc and accessibility on the module stay attached to it; lines inside multi-line string literals are never re-indented.Covered cases
Converts
namespace My.Company+module private Helpers =⟷module private My.Company.Helpers, both directions, with the caret on thenamespaceor themoduleline; covers an XML doc comment,[<AutoOpen; RequireQualifiedAccess>],let inlineand a multi-line triple-quoted string whose lines are not re-indentedrecon the namespace, the module or both:namespace rec A.B/module rec C =→module rec A.B.C// Helpers for B.abovemodule A.B.C#if DEBUG/#endifinside the body are dedented along with itopens between the namespace and the module move below the new header:namespace A.B+open System+module C =→module A.B.Cfollowed byopen System; also with several opens, a doc comment on the module, and a comment above the opens (it stays above the header and the opens are not left behind)module A.B.C→namespace A.B+module C =with the body indented and blank lines left emptymodule rec A.B.C→module rec C =; header attributes and accessibility are kept:module [<AutoOpen>] internal A.B.C→module [<AutoOpen>] internal C =module ``A-B``.C // header→namespace ``A-B``+module C = // headernamespace A.B\r\n\r\nmodule C =\r\n let x = 1\r\n⟷module A.B.C\r\nlet x = 1\r\nmodule A.B.Cconverted to a nested module and back gives the original textNot offered
module C =…module D =) or no module (type T = int)namespace globalwith a nested modulemodule Cmodule C = begin … endnamespace A.B // Blet x = 1, in either shapemodule C =with no declarationsopenafter the module, or a declaration other thanopenbefore it (type T = int)Checklist
🤖 Generated with Claude Code