From 69f3e1136685bb98e2256430d980546db4da0b0b Mon Sep 17 00:00:00 2001 From: SebastianAtWork Date: Tue, 7 Nov 2023 14:23:17 +0100 Subject: [PATCH] remove RemoveExplicitReturnType and save for a different PR --- .../src/FSharp.Editor/FSharp.Editor.fsproj | 1 - .../src/FSharp.Editor/FSharp.Editor.resx | 3 - .../Refactor/RemoveExplicitReturnType.fs | 136 ------------------ .../FSharp.Editor/xlf/FSharp.Editor.cs.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.de.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.es.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.fr.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.it.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.ja.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.ko.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.pl.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.ru.xlf | 5 - .../FSharp.Editor/xlf/FSharp.Editor.tr.xlf | 5 - .../xlf/FSharp.Editor.zh-Hans.xlf | 5 - .../xlf/FSharp.Editor.zh-Hant.xlf | 5 - .../FSharp.Editor.Tests.fsproj | 1 - .../Refactors/RemoveExplicitReturnType.fs | 128 ----------------- 18 files changed, 334 deletions(-) delete mode 100644 vsintegration/src/FSharp.Editor/Refactor/RemoveExplicitReturnType.fs delete mode 100644 vsintegration/tests/FSharp.Editor.Tests/Refactors/RemoveExplicitReturnType.fs diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 8862d7432a4c..2f84e60c4fa8 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -101,7 +101,6 @@ - diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx index 27374b00a285..9c12f2a6519f 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -355,9 +355,6 @@ Use live (unsaved) buffers for analysis Add explicit return type annotation - - Remove explicit return type annotation - Remove unnecessary parentheses diff --git a/vsintegration/src/FSharp.Editor/Refactor/RemoveExplicitReturnType.fs b/vsintegration/src/FSharp.Editor/Refactor/RemoveExplicitReturnType.fs deleted file mode 100644 index 1ad3aa39495f..000000000000 --- a/vsintegration/src/FSharp.Editor/Refactor/RemoveExplicitReturnType.fs +++ /dev/null @@ -1,136 +0,0 @@ -// 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 FSharp.Compiler -open FSharp.Compiler.CodeAnalysis -open FSharp.Compiler.Symbols -open FSharp.Compiler.Text -open FSharp.Compiler.Syntax - -open Microsoft.CodeAnalysis.Text -open Microsoft.CodeAnalysis.CodeRefactorings -open Microsoft.CodeAnalysis.CodeActions -open CancellableTasks -open System.Diagnostics -open Microsoft.CodeAnalysis.Text -open InternalOptionBuilder - -[] -type internal RemoveExplicitReturnType [] () = - inherit CodeRefactoringProvider() - - static member RangeIncludingColon(range: TextSpan, sourceText: SourceText) = - - let lineUntilType = TextSpan.FromBounds(0, range.Start) - - let colonText = sourceText.GetSubText(lineUntilType).ToString() - let newSpan = TextSpan.FromBounds(colonText.LastIndexOf(':'), range.End) - newSpan - - static member isValidMethodWithoutTypeAnnotation - (symbolUse: FSharpSymbolUse) - (parseFileResults: FSharpParseFileResults) - (funcOrValue: FSharpMemberOrFunctionOrValue) - = - let returnTypeHintAlreadyPresent = - parseFileResults.RangeOfReturnTypeDefinition(symbolUse.Range.Start, false) - |> Option.isSome - - let isLambdaIfFunction = - funcOrValue.IsFunction - && parseFileResults.IsBindingALambdaAtPosition symbolUse.Range.Start - - let res = - (not funcOrValue.IsValue || not isLambdaIfFunction) - && returnTypeHintAlreadyPresent - - match res with - | true -> Some funcOrValue - | false -> None - - static member refactor - (context: CodeRefactoringContext) - (_: FSharpMemberOrFunctionOrValue) - (parseFileResults: FSharpParseFileResults) - (symbolUse: FSharpSymbolUse) - = - let title = SR.RemoveExplicitReturnTypeAnnotation() - - let getChangedText (sourceText: SourceText) = - - let newSourceText = - parseFileResults.RangeOfReturnTypeDefinition(symbolUse.Range.Start, false) - |> Option.map (fun range -> RoslynHelpers.FSharpRangeToTextSpan(sourceText, range)) - |> Option.map (fun textSpan -> RemoveExplicitReturnType.RangeIncludingColon(textSpan, sourceText)) - |> Option.map (fun textSpan -> sourceText.Replace(textSpan, "")) - - match newSourceText with - | Some t -> t - | None -> sourceText - - let codeActionFunc = - (fun (cancellationToken: CancellationToken) -> - task { - let! sourceText = context.Document.GetTextAsync(cancellationToken) - let changedText = getChangedText sourceText - - let newDocument = context.Document.WithText(changedText) - return newDocument - }) - - let codeAction = CodeAction.Create(title, codeActionFunc, title) - - do context.RegisterRefactoring(codeAction) - - static member ofFSharpMemberOrFunctionOrValue(symbol: FSharpSymbol) = - match symbol with - | :? FSharpMemberOrFunctionOrValue as v -> Some v - | _ -> None - - override _.ComputeRefactoringsAsync context = - let ct = context.CancellationToken - - cancellableTask { - let document = context.Document - let position = context.Span.Start - let! sourceText = document.GetTextAsync() - let textLine = sourceText.Lines.GetLineFromPosition position - let textLinePos = sourceText.Lines.GetLinePosition position - let fcsTextLineNumber = Line.fromZ textLinePos.Line - - let! lexerSymbol = - document.TryFindFSharpLexerSymbolAsync(position, SymbolLookupKind.Greedy, false, false, nameof (RemoveExplicitReturnType)) - - let! (parseFileResults, checkFileResults) = document.GetFSharpParseAndCheckResultsAsync(nameof (RemoveExplicitReturnType)) - - let res = - internalOption { - let! lexerSymbol = lexerSymbol - - let! symbolUse = - checkFileResults.GetSymbolUseAtLocation( - fcsTextLineNumber, - lexerSymbol.Ident.idRange.EndColumn, - textLine.ToString(), - lexerSymbol.FullIsland - ) - - let! memberFunc = - symbolUse.Symbol |> RemoveExplicitReturnType.ofFSharpMemberOrFunctionOrValue - |>! RemoveExplicitReturnType.isValidMethodWithoutTypeAnnotation symbolUse parseFileResults - - let res = - RemoveExplicitReturnType.refactor context memberFunc parseFileResults symbolUse - - return res - } - - return res - } - |> CancellableTask.startAsTask ct diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index d5a236b63aad..b80a2c6ac403 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -211,11 +211,6 @@ Tečkované podtržení; Přerušované podtržení; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Odebrat return diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index b44197256c12..b1abace993e6 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -211,11 +211,6 @@ Punkt unterstrichen; Strich unterstrichen; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' "return" entfernen diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index 1ad994254cb7..2be2317bbf92 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -213,11 +213,6 @@ Subrayado de punto; Subrayado de guion; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Quitar "return" diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index 6236bb341a88..02c7d4c78b48 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -211,11 +211,6 @@ Soulignement pointé ; Soulignement en tirets ; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Supprimer 'return' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index d97f7bf8d2ae..dcedb50b4262 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -211,11 +211,6 @@ Sottolineatura a punto; Sottolineatura a trattini; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Rimuovi 'return' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index 266151256875..22923fa1f765 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -211,11 +211,6 @@ F# 構文規則に準拠するよう、改行を追加して指定された幅 ダッシュ下線; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' 'return' の削除 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index 8e36f8e1d2cd..591df2ccb6ab 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -212,11 +212,6 @@ F# 구문 규칙에 맞는 줄바꿈을 추가하여 지정된 너비에 서명 대시 밑줄; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' 'return' 제거 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index 8e0e80a04eb2..863bf742b2fe 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -211,11 +211,6 @@ Podkreślenie kropką; Podkreślenie kreską; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Usuń element „return” diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf index 1f1c8cd33058..24b5cf709fa3 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -211,11 +211,6 @@ Ponto sublinhado; Traço sublinhado; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Remover 'return' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index 2e0db61f66ec..29bd87400b6b 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -211,11 +211,6 @@ Dash underline; Штриховое подчеркивание; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' Удалить "return" diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index d3db21d34269..ef5ee782c321 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -211,11 +211,6 @@ Nokta alt çizgi; Tire alt çizgisi; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' 'return' öğesini kaldır diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf index bba7765c2214..0820f856e7eb 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -211,11 +211,6 @@ Dash underline; 短划线下划线; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' 删除 "return" diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf index 71df9aa5c887..484be626cdd7 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -211,11 +211,6 @@ Dash underline; 虛線底線; - - Remove explicit return type annotation - Remove explicit return type annotation - - Remove 'return' 移除 'return' diff --git a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj index 0b598e9ab81c..b9c4f7b47a04 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj +++ b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj @@ -72,7 +72,6 @@ - diff --git a/vsintegration/tests/FSharp.Editor.Tests/Refactors/RemoveExplicitReturnType.fs b/vsintegration/tests/FSharp.Editor.Tests/Refactors/RemoveExplicitReturnType.fs deleted file mode 100644 index e915e1f4a007..000000000000 --- a/vsintegration/tests/FSharp.Editor.Tests/Refactors/RemoveExplicitReturnType.fs +++ /dev/null @@ -1,128 +0,0 @@ -module FSharp.Editor.Tests.Refactors.RemoveExplicitReturnType - -open Microsoft.VisualStudio.FSharp.Editor -open Xunit -open NUnit.Framework -open FSharp.Editor.Tests.Refactors.RefactorTestFramework -open Microsoft.CodeAnalysis.Text -open Xunit -open System.Runtime.InteropServices - -[] -[] -[] -let ``Removes explicit return type`` (toRemove: string) = - let symbolName = "sum" - - let code = - $""" - let sum a b {toRemove}= a + b - """ - - use context = TestContext.CreateWithCode code - let spanStart = code.IndexOf symbolName - - let newDoc = tryRefactor code spanStart context (new RemoveExplicitReturnType()) - - AssertHasNoExplicitReturnType symbolName newDoc context.CT |> GetTaskResult - -[] -[] -[] -[] -let ``Empty Space doesnt matter`` (toRemove: string) = - let symbolName = "sum" - - let code = - $""" - let sum a b {toRemove}= a + b - """ - - use context = TestContext.CreateWithCode code - let spanStart = code.IndexOf symbolName - - let newDoc = tryRefactor code spanStart context (new RemoveExplicitReturnType()) - - AssertHasNoExplicitReturnType symbolName newDoc context.CT |> GetTaskResult - -[] -[] -[] -let ``Different Formatting`` (functionHeader: string) = - let symbolName = "sum" - - let code = - $""" - let sum {functionHeader}= - a + b - """ - - use context = TestContext.CreateWithCode code - let spanStart = code.IndexOf symbolName - - let newDoc = tryRefactor code spanStart context (new RemoveExplicitReturnType()) - - AssertHasNoExplicitReturnType symbolName newDoc context.CT |> GetTaskResult - -[] -let ``Refactor should not be suggested if theres nothing to remove`` () = - let symbolName = "sum" - - let code = - $""" - let sum a b = a + b - """ - - use context = TestContext.CreateWithCode code - - let spanStart = code.IndexOf symbolName - - let actions = - tryGetRefactoringActions code spanStart context (new RemoveExplicitReturnType()) - - Assert.Empty(actions) - -[] -let ``Refactor should not be suggested if it changes the return type`` () = - let symbolName = "sum" - - let code = - """ - type A = { X:int } - type B = { X:int } - - let f (i: int) : A = { X = i } - let sum a b = a + b - """ - - use context = TestContext.CreateWithCode code - - let spanStart = code.IndexOf symbolName - - let actions = - tryGetRefactoringActions code spanStart context (new RemoveExplicitReturnType()) - - Assert.Empty(actions) - -[] -let ``Refactor should be suggested if it does not changes the return type`` () = - let symbolName = "sum" - - let code = - """ - - type B = { X:int } - type A = { X:int } - - let f (i: int) : A = { X = i } - let sum a b = a + b - """ - - use context = TestContext.CreateWithCode code - - let spanStart = code.IndexOf symbolName - - let actions = - tryGetRefactoringActions code spanStart context (new RemoveExplicitReturnType()) - - Assert.NotEmpty(actions)