Repository navigation
Add Extract to function and Extract to private member refactorings - #20538
xperiandri wants to merge 17 commits into
Conversation
✅ Release notes checked
|
9689259 to
dc118df
Compare
This comment has been minimized.
This comment has been minimized.
T-Gro
left a comment
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.
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.
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>
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>
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>
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>
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>
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>
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>
b4cccb8 to
c064fb1
Compare
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>
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>
…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>
…tion, a module function or a private member The branch carried two copies of the commits of the extract let binding branch, so its history is rebuilt as this one commit on top of that branch. It holds the refactorings with the review fixes and the compaction made since they were first written.
Outside List.map a lambda such as fun x -> x.Length loses the type that its context gave x, so the extracted function failed with FS0072. The local function, module function and private member now declare the lambda's recorded function type as their return type, as Extract to let binding does; a type with a variable inference introduced is left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A captured let mutable lives in a hidden ref cell, so a by-value parameter copy goes stale when the selection calls a closure that writes it, as in (bump (); n). The check now looks at every use of the local in its declaration through the checker, not only the uses inside the selection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ruct A by-value parameter of a struct type is a copy, so s.Inc() on it left the caller's mutable s unchanged. When a mutable struct local that would become a parameter is the receiver of a member call, a field or indexer access or an address-of in the selection, no function extraction is offered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c064fb1 to
69cd2fe
Compare
Build Failure AnalysisSummary - All 15 failed build-attempt binlogs stop in Root cause: UI resource XLF files are staleThe PR adds four Extract-to-function option strings to Affected errors
Fix attempt - validated Delivery - patch Regenerated all 13 Checks - Build evidence
Structured data: {
"artifact_kind": "analysis",
"fix_delivery": "patch",
"fix_status": "validated",
"workflow_artifact": "build-failure-analysis"
}Checked patch (not applied to your branch): Download .patch (retained 14 days). At Warning Firewall blocked 43 domainsThe following domains were blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "11vvsblobprodcus336.vsblob.vsassets.io"
- "169.254.169.254"
- "1p7vsblobprodcus324.vsblob.vsassets.io"
- "2kmvsblobprodcus39.vsblob.vsassets.io"
- "2zsvsblobprodwus2125.vsblob.vsassets.io"
- "37bvsblobprodcus311.vsblob.vsassets.io"
- "4myvsblobprodcus32.vsblob.vsassets.io"
- "5rqvsblobprodcus385.vsblob.vsassets.io"
- "6yfvsblobprodwus2121.vsblob.vsassets.io"
- "7k6vsblobprodcus337.vsblob.vsassets.io"
- "7tjvsblobprodcus341.vsblob.vsassets.io"
- "ajhvsblobprodcus363.vsblob.vsassets.io"
- "b53vsblobprodwus2154.vsblob.vsassets.io"
- "bcnvsblobprodcus378.vsblob.vsassets.io"
- "builds.dotnet.microsoft.com"
- "c78vsblobprodcus322.vsblob.vsassets.io"
- "cflvsblobprodcus383.vsblob.vsassets.io"
- "ci.dot.net"
- "d94vsblobprodwus2119.vsblob.vsassets.io"
- "data.nuget.org"
- "fdpvsblobprodcus345.vsblob.vsassets.io"
- "h6tvsblobprodcus346.vsblob.vsassets.io"
- "jd4vsblobprodcus366.vsblob.vsassets.io"
- "k0ivsblobprodcus356.vsblob.vsassets.io"
- "k4kvsblobprodcus344.vsblob.vsassets.io"
- "kh4vsblobprodcus325.vsblob.vsassets.io"
- "kxqvsblobprodcus376.vsblob.vsassets.io"
- "m16vsblobprodcus374.vsblob.vsassets.io"
- "m6xvsblobprodcus342.vsblob.vsassets.io"
- "mfjvsblobprodcus373.vsblob.vsassets.io"
- "n3kvsblobprodcus335.vsblob.vsassets.io"
- "nypvsblobprodwus2178.vsblob.vsassets.io"
- "pc2vsblobprodcus360.vsblob.vsassets.io"
- "pdfvsblobprodcus380.vsblob.vsassets.io"
- "pkgs.dev.azure.com"
- "s8mvsblobprodcus38.vsblob.vsassets.io"
- "se1vsblobprodcus349.vsblob.vsassets.io"
- "southcentralus0.in.applicationinsights.azure.com"
- "sqdvsblobprodcus333.vsblob.vsassets.io"
- "tphvsblobprodcus375.vsblob.vsassets.io"
- "u3hvsblobprodcus371.vsblob.vsassets.io"
- "x3yvsblobprodcus370.vsblob.vsassets.io"
- "zugvsblobprodwus2169.vsblob.vsassets.io"See Network Configuration for more information.
|
69cd2fe to
b7b1334
Compare
Stacked on #20537.
Offers
Ctrl+.on a selected expression to move it into a local function, a module function, or, when it usesthisorbase, a private member. Values the selection reads from the enclosing function become parameters in first-use order.Parameters are annotated by default because the new function is its own generalization point; the new Parameter types in Extract to function option under Code Fixes can relax that. Not offered when the selection assigns to a captured
mutableor reads a byref value.🤖 Generated with Claude Code