Repository navigation
Add Extract to let binding and Extract to literal refactorings - #20537
Open
xperiandri wants to merge 13 commits into
Open
xperiandri wants to merge 13 commits into
xperiandri wants to merge 13 commits into
Conversation
Contributor
✅ Release notes checked
|
xperiandri
commented
Sep 14, 2026
|
|
||
| tryGetRefactoringActionsForSpan code (selectionOf code selected) context (new FSharpExtractLetBindingRefactoring()) | ||
| |> Seq.map _.Title | ||
| |> List.ofSeq |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| |> List.ofSeq | |
| |> Seq.toList |
xperiandri
marked this pull request as ready for review
September 14, 2026 19:40
This comment has been minimized.
This comment has been minimized.
T-Gro
requested changes
Sep 15, 2026
T-Gro
left a comment
Member
There was a problem hiding this comment.
🤖🕵️ Please shorten the description using this guidance. Focus on the problem and why the change is needed, in simplified technical English. Leave the implementation inventory to the Files tab and retain necessary caveats.
Contributor
Author
Covered casesOffered
Not offered
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 23, 2026
Port of the dotnet#20538 compaction (feature/extract-function-refactoring 838b68d..b4cccb8) to all-fixes. The part of that range which merges the compacted Extract to let binding (dotnet#20537) came with the previous commit; this one carries what is specific to Extract to function: - Compact the Extract to function code and name what its comments said - Fold the Extract to function tests into parameterized theories The tests use caretSpanAt, the name the Extract suites' caret helper has in the shared refactoring test framework on all-fixes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 23, 2026
This branch had only the two copies without the PR link. They give way to the bullet the PR keeps (7bf3578 of dotnet#20537). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 23, 2026
Port of the dotnet#20537 compaction (feature/extract-let-binding-refactoring 2920e42..1711de9) to all-fixes: - Compact the Extract to let binding code and name what its comments said - Fold the Extract to let binding tests into parameterized theories Extract to function (dotnet#20538) shares RefactoringHelpers.fs, so its callers follow the renames here, as in the pull request's merge of this head. The refactoring test framework carries the helpers of both the Extract and the tuple/record test suites on all-fixes. The caret helper of the Extract suites, which returns a TextSpan and reads a `|` in the marker, is therefore named caretSpanAt; the existing caretAt of the conversion suites keeps returning the index of the marker. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 23, 2026
Port of the dotnet#20538 compaction (feature/extract-function-refactoring 838b68d..b4cccb8) to all-fixes. The part of that range which merges the compacted Extract to let binding (dotnet#20537) came with the previous commit; this one carries what is specific to Extract to function: - Compact the Extract to function code and name what its comments said - Fold the Extract to function tests into parameterized theories The tests use caretSpanAt, the name the Extract suites' caret helper has in the shared refactoring test framework on all-fixes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 29, 2026
This branch had only the two copies without the PR link. They give way to the bullet the PR keeps (7bf3578 of dotnet#20537). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 29, 2026
Port of the dotnet#20537 compaction (feature/extract-let-binding-refactoring 2920e42..1711de9) to all-fixes: - Compact the Extract to let binding code and name what its comments said - Fold the Extract to let binding tests into parameterized theories Extract to function (dotnet#20538) shares RefactoringHelpers.fs, so its callers follow the renames here, as in the pull request's merge of this head. The refactoring test framework carries the helpers of both the Extract and the tuple/record test suites on all-fixes. The caret helper of the Extract suites, which returns a TextSpan and reads a `|` in the marker, is therefore named caretSpanAt; the existing caretAt of the conversion suites keeps returning the index of the marker. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
to xperiandri/fsharp
that referenced
this pull request
Oct 29, 2026
Port of the dotnet#20538 compaction (feature/extract-function-refactoring 838b68d..b4cccb8) to all-fixes. The part of that range which merges the compacted Extract to let binding (dotnet#20537) came with the previous commit; this one carries what is specific to Extract to function: - Compact the Extract to function code and name what its comments said - Fold the Extract to function tests into parameterized theories The tests use caretSpanAt, the name the Extract suites' caret helper has in the shared refactoring test framework on all-fixes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feature/extract-let-binding-refactoring
branch
from
October 30, 2026 01:02
1711de9 to
1f3e6fb
Compare
…g or a literal The selected expression is bound to a new name in front of the statement that uses it: above a statement that starts its line, or, when the body of a binding, match clause, branch or lambda shares the line with its keyword, on new lines under that keyword. A constant inside a module-level declaration can instead become a [<Literal>] in front of that declaration. The shared selection and placement logic lives in Refactor/RefactoringHelpers.fs, and the refactoring test framework gains helpers that run a provider on a selected span. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
C# offers Introduce Constant without a selection. With a caret alone only the literal is offered; a let binding still needs a selection. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A caret between 'fun' and the end of '->' acts as a selection of the parenthesized lambda; in the body a caret offers nothing new. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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>
…on's way The name collector now also records the heads of assignment targets, so the new local cannot shadow a value the selection's statement assigns to. Lines inside multi-line strings of inactive #if branches are found by lexing each inactive branch as the code it is when taken, and are not re-indented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to literal - Annotate an extracted lambda or function expression with the type its context gave it, unless that type has a variable inference introduced. - Do not extract from inside assert, the operand of nameof, or a parenthesized name, address-of or named argument. - Bind an expression of a finally block inside that block. - Indent a body moved under its keyword from the let, match, try, if or loop that starts inside the line. - Offer the literal for decimal constants and not for native integers. - Qualify the generated Literal attribute where another LiteralAttribute hides the FSharp.Core one. - Do not offer the literal where the module-level let does not start its line. - Reserve every identifier of a long pattern when picking a new name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ected inside its parentheses The checker records the type of the parenthesized expression, so a lambda selected without the parentheses around it takes the type from them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the explanatory comments with names, keep the document state of an extraction and the registration of its code actions in one record and one function, flatten the provider and the declaration builders to two levels of nesting, and scan the rest of a line for closing brackets without copying it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
One theory per kind of assertion with a scenario name per row. The module wrapper, the selection and caret spans, the refactored text and the offered titles move to the refactoring test framework, where the Extract to function tests can use them too. Every case is kept; tests that asserted several things became one row per assertion, so 64 cases became 74. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replaying the branch onto main left some files short of the branch's own content; this restores it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The syntax tree holds only the active branch, so an extracted name could shadow an identifier that an inactive #if branch uses and change what that branch means once its symbol is defined. The lexer pass that already finds the string lines of inactive branches now also collects their identifiers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feature/extract-let-binding-refactoring
branch
from
November 8, 2026 03:29
1f3e6fb to
0c0c12e
Compare
xperiandri
force-pushed
the
feature/extract-let-binding-refactoring
branch
from
November 18, 2026 22:00
0c0c12e to
96b00b4
Compare
Member
|
/azp run |
|
No pipelines are associated with this pull request. |
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This branch has not been deployed
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.
Offers
Ctrl+.on a selected expression to bind it to aletin front of the statement that uses it, or, for a constant in a module-level declaration, to a[<Literal>]above that declaration. A caret inside a constant offers the literal; a caret in thefun … ->header of a parenthesized lambda extracts the lambda.The value is computed at the start of the enclosing statement, so it can run earlier than where it was written, as with C#'s Introduce Local. The selection must match a whole expression; nothing is offered inside quotations, interpolation holes,
whileconditions orwhenguards.🤖 Generated with Claude Code