Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.VisualStudio/18.vNext.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Suggest active-pattern cases from unopened modules and offer valid Add Open and qualification edits. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))
* Add maintainer-requested F# Apex Visual Studio integration tests on DartLab-1ES CloudTest, using PR pipeline definitions pinned to an explicitly requested commit SHA. ([PR #20625](https://github.com/dotnet/fsharp/pull/20625))
* Code-fixes for FS3888 (compiler-semantic attribute on the `.fs` but not the `.fsi`): copy the attribute into the `.fsi`, or remove it from the `.fs`. ([Issue #19560](https://github.com/dotnet/fsharp/issues/19560), [PR #19880](https://github.com/dotnet/fsharp/pull/19880))
* Refactoring to convert a tuple between a reference tuple and a struct tuple, following its value through the solution: annotations of values, parameters, record fields and results it flows through, tuple patterns that take it apart, and the arguments and values that flow into it. What cannot be followed (`fst`, `snd`, generic collections) is left for the compiler to report. ([PR #20548](https://github.com/dotnet/fsharp/pull/20548))
* Expand `<inheritdoc/>` in IDE tooltips, completion, and signature help, inheriting XML documentation from base classes, interfaces, overridden members, and constructors. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19188](https://github.com/dotnet/fsharp/pull/19188))
* Move F# editor and Interactive options to 43 native Unified Settings with independent roaming and a one-time import of existing settings. Preserve the legacy groupings and Interactive setting order, with restart requirements displayed by Unified Settings. Quick Info's preferred description width is a checkbox with a dependent integer control. Remove the eight legacy options pages; the user-wide compiler setting remains external. Typing and deletion completion triggers are independent. ([PR #20877](https://github.com/dotnet/fsharp/pull/20877))
* Added a **Compiler** option in F# Unified Settings, **"Use the .NET SDK F# compiler for builds"**, on by default. Visual Studio uses the .NET SDK F# compiler when the project supplies SDK paths, matching `dotnet build`. Otherwise, it uses the bundled .NET Framework compiler. Turn the option off to use the bundled compiler for all projects. Command-line builds are unaffected. ([Issue #20484](https://github.com/dotnet/fsharp/issues/20484), [PR #20485](https://github.com/dotnet/fsharp/pull/20485))
Expand Down
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Compile Include="Refactor\ChangeTypeofWithNameToNameofExpression.fs" />
<Compile Include="Refactor\AddExplicitTypeToParameter.fs" />
<Compile Include="Refactor\ChangeDerefToValueRefactoring.fs" />
<Compile Include="Refactor\TupleConversion.fs" />
<Compile Include="Refactor\TuplePropagation.fs" />
<Compile Include="Refactor\ConvertTuple.fs" />
<Compile Include="CodeFixes\IFSharpCodeFix.fs" />
<Compile Include="CodeFixes\CodeFixHelpers.fs" />
<Compile Include="CodeFixes\ChangeEqualsInFieldTypeToColon.fs" />
Expand Down
6 changes: 6 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.resx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@
{2}</value>
<comment>Tooltip of an F# declaration in the Copilot Chat "#" picker, as Copilot shows a C# one. {0} is the kind of declaration (Class, Method, Field...), {1} the file name, {2} the declaration's name.</comment>
</data>
<data name="ConvertToStructTuple" xml:space="preserve">
<value>Convert to struct tuple</value>
</data>
<data name="ConvertToReferenceTuple" xml:space="preserve">
<value>Convert to reference tuple</value>
</data>
<data name="UnifiedSettingsIntelliSenseTitle" xml:space="preserve">
<value>IntelliSense</value>
</data>
Expand Down
88 changes: 88 additions & 0 deletions vsintegration/src/FSharp.Editor/Refactor/ConvertTuple.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Composition
open System.Threading
open System.Threading.Tasks

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CodeActions
open Microsoft.CodeAnalysis.CodeRefactorings

open FSharp.Compiler.Syntax
open FSharp.Compiler.Text

open CancellableTasks
open TupleConversion

[<ExportCodeRefactoringProvider(FSharpConstants.FSharpLanguageName, Name = "ConvertTuple"); Shared>]
type internal FSharpConvertTupleRefactoring [<ImportingConstructor>] () =
inherit CodeRefactoringProvider()

static let hasSignatureFile (document: Document) =
let signaturePath = document.FilePath + "i"

document.Project.Documents
|> Seq.exists (fun d -> String.Equals(d.FilePath, signaturePath, StringComparison.OrdinalIgnoreCase))

static let isInQuotation (caretNode: CaretNode) =
let path =
match caretNode with
| CaretNode.Expr(path = path)
| CaretNode.Pat(path = path)
| CaretNode.Type(annotated = Annotated.Pattern(path = path))
| CaretNode.Type(annotated = Annotated.Expression(path = path)) -> path
| CaretNode.Type _ -> []

path
|> List.exists (function
| SyntaxNode.SynExpr(SynExpr.Quote _) -> true
| _ -> false)

override _.ComputeRefactoringsAsync context =
cancellableTask {
let document = context.Document

if not (document.IsFSharpSignatureFile || hasSignatureFile document) then
let! cancellationToken = CancellableTask.getCancellationToken ()
let! sourceText = document.GetTextAsync cancellationToken
let! parseResults = document.GetFSharpParseResultsAsync(nameof FSharpConvertTupleRefactoring)

let caret =
let linePosition = sourceText.Lines.GetLinePosition context.Span.Start
Position.mkPos (Line.fromZ linePosition.Line) linePosition.Character

let hasTupleCandidate =
(tryCaretNode (fun _ -> false) caret parseResults.ParseTree).IsSome

let! found =
if hasTupleCandidate then
cancellableTask {
let! _, checkResults = document.GetFSharpParseAndCheckResultsAsync(nameof FSharpConvertTupleRefactoring)
return tryCaretNode (callsMethod sourceText checkResults) caret parseResults.ParseTree
}
else
CancellableTask.singleton ValueNone

match found with
| ValueSome caretNode when not (isInQuotation caretNode) && canChange sourceText caretNode ->
let! converted = TuplePropagation.tryConvert document caretNode (nameof FSharpConvertTupleRefactoring)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖🕵️ Runs a cross-solution reference search on every caret stop on a tuple; move it to apply time (as Roslyn does) and report problems then.


match converted with
| ValueSome solution ->
let title =
if isStructNode caretNode then
SR.ConvertToReferenceTuple()
else
SR.ConvertToStructTuple()

let action =
CodeAction.Create(title, Func<CancellationToken, Task<Solution>>(fun _ -> Task.FromResult solution), title)

context.RegisterRefactoring action
| ValueNone -> ()
| _ -> ()
}
|> CancellableTask.startAsTask context.CancellationToken
Loading
Loading