Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddExplicitReturnType refactoring #16077

Merged
merged 63 commits into from
Dec 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e27012e
First Draft for AddExplicitReturnType (#15562) with exploration test …
SebastianAtWork Oct 4, 2023
b0fbe67
Added Workspace handling and some debug stuff #15562
SebastianAtWork Oct 5, 2023
81d8f0e
Added One Way of getting the changed Solution for ExplicitReturnTypes…
SebastianAtWork Oct 7, 2023
25b901e
added language resource files (not translated) #15562
SebastianAtWork Oct 8, 2023
c9baeda
refactor: Create test context and check return type
SebastianAtWork Oct 19, 2023
42d67f5
refactor: Add explicit return type in FSharp.Editor.Tests/Refactors/A…
SebastianAtWork Oct 19, 2023
493b374
feat: Add function to get return type of symbol
SebastianAtWork Oct 19, 2023
12d76d4
refactor: Remove explicit return type annotation
SebastianAtWork Oct 20, 2023
b22a519
chore: committed resources
SebastianAtWork Oct 20, 2023
a14c048
* test(FSharp.Editor.Tests): finally got a working test for remove e…
SebastianAtWork Oct 23, 2023
7b31775
🚀feat(tests) add F# editor refactoring tests
SebastianAtWork Oct 24, 2023
83bfb1e
fix: formatting
SebastianAtWork Oct 24, 2023
da2dc25
* refactor(FSharp.Editor): improve explicit return type removal
SebastianAtWork Oct 24, 2023
7c4f039
* feat(FSharp.Editor): add RangeOfReturnTypeDefinition and refactor m…
SebastianAtWork Oct 25, 2023
9e31a4e
* refactor(FSharp.Editor.Tests): simplify and improve test code reada…
SebastianAtWork Oct 25, 2023
1df0308
fix: remove debug lines
SebastianAtWork Oct 25, 2023
fefe14b
* refactor(FSharp.Editor.Tests): improve test method names and assert…
SebastianAtWork Oct 29, 2023
7cf8ab0
* feat(FSharp.Editor): add InternalOptionBuilder module
SebastianAtWork Oct 29, 2023
0c306a3
* refactor(FSharp.Editor): simplify async tasks in AddExplicitReturnT…
SebastianAtWork Oct 30, 2023
8335c0b
* feat(FSharp.Editor): update condition for return type hint presence…
SebastianAtWork Oct 30, 2023
0918cfb
* feat(FSharp.Editor.Tests): add new test cases for AddExplicitReturn…
SebastianAtWork Nov 1, 2023
0a8c952
* feat(FSharp.Editor.Tests): add AsyncBugReproduction.fs to test suite
SebastianAtWork Nov 2, 2023
ac3cb24
bug: boiled bug down more
SebastianAtWork Nov 2, 2023
168dc63
* feat(FSharpParseFileResults.fs): add RangeOfReturnTypeDefinition me…
SebastianAtWork Nov 2, 2023
5978ad5
* refactor(FSharp.Editor.Tests): remove async tasks from test cases a…
SebastianAtWork Nov 7, 2023
c6ea3fc
* refactor(FSharp.Editor): simplify refactoring process in AddExplici…
SebastianAtWork Nov 7, 2023
a135896
remove RemoveExplicitReturnType and save for a different PR
SebastianAtWork Nov 7, 2023
e4f849c
test: fixed test formatting
SebastianAtWork Nov 13, 2023
99e3686
* refactor(FSharp.Editor): remove InternalOptionBuilder.fs and update…
SebastianAtWork Nov 13, 2023
7274f3e
* refactor(FSharp.Editor.Tests): rename AddExplicitReturnType.fs to A…
SebastianAtWork Nov 13, 2023
ec5ab97
* refactor(FSharp.Editor): remove unused imports in AddExplicitReturn…
SebastianAtWork Nov 13, 2023
30b5fe7
* refactor(FSharpParseFileResults.fs, FSharpParseFileResults.fsi, Ref…
SebastianAtWork Nov 13, 2023
a3d2ce2
* feat(FSharp.Editor.Tests): add GetLastDocument method in RoslynHelp…
SebastianAtWork Nov 14, 2023
f8bfd0c
* refactor(RefactorTestFramework.fs): simplify TestContext type and r…
SebastianAtWork Nov 15, 2023
3a2257f
* style: add space after colon in type annotations in AddExplicitRetu…
SebastianAtWork Nov 15, 2023
1d24e5a
* refactor(AddExplicitReturnType.fs): remove unused CancellationToken…
SebastianAtWork Nov 16, 2023
c700bf8
* feat(FSharp.Editor): add checks for function or value names in AddE…
SebastianAtWork Nov 20, 2023
9bb4545
* refactor(AddExplicitReturnTypeTests.fs): remove unused System.Linq …
SebastianAtWork Nov 21, 2023
867803d
* refactor(RefactorTestFramework.fs): remove unused import Microsoft.…
SebastianAtWork Nov 21, 2023
77987ca
I dont know this file type
SebastianAtWork Nov 21, 2023
2a6e573
* refactor(AddExplicitReturnType.fs): simplify match expressions and …
SebastianAtWork Nov 21, 2023
5d004eb
fixed: AddExplicitReturnTypeTests
SebastianAtWork Dec 1, 2023
3edc9d0
Automated command ran: fantomas
github-actions[bot] Dec 1, 2023
555ff74
Merge branch 'dotnet:main' into features/codefix-return-type
SebastianAtWork Dec 1, 2023
e59af47
* fix: add space before equals sign in type annotations in AddExplici…
SebastianAtWork Dec 2, 2023
4c48771
* feat(AddExplicitReturnType.fs): add support for generic return type…
SebastianAtWork Dec 2, 2023
79603fb
* refactor(AddExplicitReturnType.fs): improve inferredType calculatio…
SebastianAtWork Dec 2, 2023
d0940c2
fix: remove strange artifact
SebastianAtWork Dec 2, 2023
81623d5
* refactor(FSharp.Editor): rename 'AddExplicitReturnTypeAnnotation' t…
SebastianAtWork Dec 2, 2023
ca88258
* refactor(FSharp.Editor): simplify CancellationToken usage in TestCo…
SebastianAtWork Dec 2, 2023
2590310
Merge branch 'dotnet:main' into features/codefix-return-type
SebastianAtWork Dec 6, 2023
7283db8
refactor: Improve code readability and performance
SebastianAtWork Dec 6, 2023
0a5a193
refactor: Improve code readability and performance
SebastianAtWork Dec 6, 2023
e7d8114
Merge branch 'dotnet:main' into features/codefix-return-type
SebastianAtWork Dec 13, 2023
d9310a3
refactor: Refactored AddExplicitReturnType.fs and AddExplicitReturnTy…
SebastianAtWork Dec 13, 2023
e51805d
Merge branch 'dotnet:main' into features/codefix-return-type
SebastianAtWork Dec 15, 2023
696b930
refactor: Simplify AddExplicitReturnType logic
SebastianAtWork Dec 15, 2023
323c863
refactor: Add explicit return type to sum function
SebastianAtWork Dec 15, 2023
6fb62df
tests: Added new special test cases for already existing opens
SebastianAtWork Dec 15, 2023
8cf85ec
refactor: Update return type annotation in localization files
SebastianAtWork Dec 16, 2023
3a7eac4
refactor: Rename AddExplicitReturnType to AddReturnType
SebastianAtWork Dec 16, 2023
b4ea8b9
Merge branch 'dotnet:main' into features/codefix-return-type
SebastianAtWork Dec 16, 2023
14c2acc
Merge branch 'main' into features/codefix-return-type
SebastianAtWork Dec 19, 2023
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
Prev Previous commit
Next Next commit
* feat(FSharp.Editor.Tests): add AsyncBugReproduction.fs to test suite
* fix(AddExplicitReturnType.fs): remove unnecessary assertion
* fix(RefactorTestFramework.fs): convert symbols sequence to list
SebastianAtWork committed Dec 1, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
aitbw Angel Perez
commit 0a8c9520eda115690b8e12d577c82209cab9c998
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@
<Compile Include="Refactors\RefactorTestFramework.fs" />
<Compile Include="Refactors\AddExplicitReturnType.fs" />
<Compile Include="Refactors\RemoveExplicitReturnType.fs" />
<Compile Include="Refactors\AsyncBugReproduction.fs" />
<Compile Include="Hints\HintTestFramework.fs" />
<Compile Include="Hints\OptionParserTests.fs" />
<Compile Include="Hints\InlineParameterNameHintTests.fs" />
SebastianAtWork marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ let ``Infer explicit return type`` (functionHeader: string) (returnType: string)
let spanStart = code.IndexOf(symbolName)

let! newDoc = tryRefactor code spanStart context (new AddExplicitReturnType())
do Assert.NotNull(code)

do! AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module FSharp.Editor.Tests.Refactors.AsyncBugReproduction

open Microsoft.VisualStudio.FSharp.Editor
open Xunit
open System
open System.Collections.Immutable
open System.Text.RegularExpressions

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.Editor.CancellableTasks

open FSharp.Compiler.Diagnostics
open FSharp.Editor.Tests.Helpers

open Microsoft.CodeAnalysis.CodeRefactorings
open NUnit.Framework
open Microsoft.CodeAnalysis.CodeActions
open System.Collections.Generic
open Microsoft.VisualStudio.LanguageServices
open FSharp.Editor.Tests.Refactors.RefactorTestFramework
open Microsoft.Build.Utilities
open System.Threading
open FSharp.Test.ReflectionHelper
open Microsoft.Build.Utilities
open FSharp.Test.ProjectGeneration.ProjectOperations
open FSharp.Compiler.Symbols
open Xunit
open System.Runtime.InteropServices

[<Theory>]
[<InlineData("(a:float) (b:int)", "float")>]
[<InlineData("(a:float) (b:int)", "float")>]
let ``Reproducing code null spanStart Bug`` (functionHeader: string) (returnType: string) =
task {

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 AddExplicitReturnType())

do! AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
}

[<Theory>]
[<InlineData("(a:float) (b:int)", "float")>]
[<InlineData("(a:float) (b:int)", "float")>]
let ``But works when not async`` (functionHeader: string) (returnType: string) =

let symbolName = "sum"

let code =
$"""
let sum {functionHeader}= a + b
"""

use context = TestContext.CreateWithCode code

let spanStart = code.IndexOf(symbolName)

let newDocTask = tryRefactor code spanStart context (new AddExplicitReturnType())
let newDoc = newDocTask.GetAwaiter().GetResult()

let assertTask =
AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT

do assertTask.GetAwaiter().GetResult()
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ let GetReturnTypeOfSymbol (symbolName: string) (document: Document) ct =
document.GetFSharpParseAndCheckResultsAsync symbolName
|> CancellableTask.start ct

let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct
let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct |> List.ofSeq
let symbolUse = symbols |> Seq.find (fun s -> s.Symbol.DisplayName = symbolName)

return