-
Notifications
You must be signed in to change notification settings - Fork 831
Aligning constructor and type for Rename + FindAllReferences #14350
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
Merged
psfinaki
merged 13 commits into
dotnet:main
from
T-Gro:refactor-rename-doesnt-work-for-constructors
Nov 21, 2022
+143
−3
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6e3115e
Issue investigation && repro
T-Gro 5148ce0
Abs filepath remapping for test DSL
T-Gro 84f69ba
itemKeyStore enabled for test workflow
T-Gro 8f53d85
Changing behaviour for FindAllReferences and constructors
T-Gro 9c157ee
tests for strange static init
T-Gro 2f65483
Making tests pass in net70
T-Gro 4983476
Merge branch 'main' into refactor-rename-doesnt-work-for-constructors
T-Gro c4b49b8
Remove debugging code
T-Gro 4e28226
Reflect VS-realistic FsharpChecker settings in ProjectWorkflowBuilder…
T-Gro cbd69b7
Merge branch 'refactor-rename-doesnt-work-for-constructors' of https:…
T-Gro 265b0cf
Fantomas applied
T-Gro 0f0a587
Merge branch 'main' into refactor-rename-doesnt-work-for-constructors
T-Gro 434d807
PR feedback
T-Gro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
98 changes: 98 additions & 0 deletions
98
tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| module FSharp.Compiler.ComponentTests.FSharpChecker.FindReferences | ||
|
|
||
| open FSharp.Compiler.CodeAnalysis | ||
| open Xunit | ||
| open FSharp.Test.ProjectGeneration | ||
|
|
||
| type Occurence = Definition | InType | Use | ||
|
|
||
| let deriveOccurence (su:FSharpSymbolUse) = | ||
| if su.IsFromDefinition | ||
| then Definition | ||
| elif su.IsFromType | ||
| then InType | ||
| elif su.IsFromUse | ||
| then Use | ||
| else failwith $"Unexpected type of occurence (for this test), symbolUse = {su}" | ||
|
|
||
| /// https://github.com/dotnet/fsharp/issues/13199 | ||
| let reproSourceCode = """ | ||
| type MyType() = | ||
| member x.DoNothing(d:MyType) = () | ||
| let a = MyType() | ||
| let b = new MyType() | ||
| a.DoNothing(b) | ||
| """ | ||
| let impFile() = { sourceFile "First" [] with ExtraSource = reproSourceCode } | ||
| let createProject() = SyntheticProject.Create(impFile()) | ||
|
|
||
| [<Fact>] | ||
| let ``Finding usage of type via GetUsesOfSymbolInFile should also find it's constructors`` () = | ||
| createProject().Workflow | ||
| { | ||
| checkFile "First" (fun (typeCheckResult: FSharpCheckFileResults) -> | ||
|
|
||
| let symbolUse = typeCheckResult.GetSymbolUseAtLocation(7, 11, "type MyType() =", ["MyType"]).Value | ||
| let references = | ||
| typeCheckResult.GetUsesOfSymbolInFile(symbolUse.Symbol) | ||
| |> Array.sortBy (fun su -> su.Range.StartLine) | ||
| |> Array.map (fun su -> su.Range.StartLine, su.Range.StartColumn, su.Range.EndColumn, deriveOccurence su) | ||
|
|
||
| Assert.Equal<(int*int*int*Occurence)>( | ||
| [| 7,5,11,Definition | ||
| 8,25,31,InType | ||
| 10,8,14,Use | ||
| 11,12,18,Use | ||
| |],references) ) | ||
| } | ||
|
|
||
|
|
||
| [<Fact>] | ||
| let ``Finding usage of type via FindReference should also find it's constructors`` () = | ||
| createProject().Workflow | ||
| { | ||
| placeCursor "First" 7 11 "type MyType() =" ["MyType"] | ||
| findAllReferences "First" (fun (ranges:list<FSharp.Compiler.Text.range>) -> | ||
| let ranges = | ||
| ranges | ||
| |> List.sortBy (fun r -> r.StartLine) | ||
| |> List.map (fun r -> r.StartLine, r.StartColumn, r.EndColumn) | ||
| |> Array.ofSeq | ||
|
|
||
| Assert.Equal<(int*int*int)>( | ||
| [| 7,5,11 // Typedef itself | ||
| 8,25,31 // Usage within type | ||
| 10,8,14 // "a= ..." constructor | ||
| 11,12,18 // "b= ..." constructor | ||
| |],ranges) ) | ||
|
|
||
| } | ||
|
|
||
| [<Fact>] | ||
| let ``Finding usage of type via FindReference works across files`` () = | ||
| let secondFile = { sourceFile "Second" ["First"] with ExtraSource = """ | ||
| open ModuleFirst | ||
| let secondA = MyType() | ||
| let secondB = new MyType() | ||
| secondA.DoNothing(secondB) | ||
| """} | ||
| let original = createProject() | ||
| let project = {original with SourceFiles = original.SourceFiles @ [secondFile]} | ||
| project.Workflow | ||
| { | ||
| placeCursor "First" 7 11 "type MyType() =" ["MyType"] | ||
| findAllReferences "Second" (fun (ranges:list<FSharp.Compiler.Text.range>) -> | ||
| let ranges = | ||
| ranges | ||
| |> List.sortBy (fun r -> r.StartLine) | ||
| |> List.map (fun r -> r.StartLine, r.StartColumn, r.EndColumn) | ||
| |> Array.ofSeq | ||
|
|
||
| Assert.Equal<(int*int*int)>( | ||
| [| 9,14,20 // "secondA = ..." constructor | ||
| 10,18,24 // "secondB = ..." constructor | ||
| |],ranges) ) | ||
|
|
||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.