From 8153f152220e0c218928565a45e86d8849a0d42b Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Wed, 30 Aug 2023 17:20:46 +0200 Subject: [PATCH 1/5] Fix finding internal symbols in internals-visible-to projects --- src/Compiler/Service/IncrementalBuild.fs | 2 +- .../FSharpChecker/FindReferences.fs | 28 +++++++++++++++++++ .../ProjectGeneration.fs | 18 +++++++----- .../FSharp.Editor/LanguageService/Symbols.fs | 9 +++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 6dc16fedf0a..91c4caa7123 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -408,7 +408,7 @@ type BoundModel private ( member this.TryPeekTcInfo() = this.TcInfo.TryPeekValue() |> ValueOption.toOption - member this.TryPeekTcInfoWithExtras() = + member this.TryPeekTcInfoWithExtras() = (this.TcInfo.TryPeekValue(), this.TcInfoExtras.TryPeekValue()) ||> ValueOption.map2 (fun a b -> a, b) |> ValueOption.toOption diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs index e1cd294ba53..7b8bb18b169 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs @@ -124,6 +124,34 @@ let ``Finding references in project`` (fastCheck, captureIdentifiersWhenParsing) findAllReferencesToModuleFromFile "File000" fastCheck (expectNumberOfResults 5) } +[] +let ``Find references to internal symbols in other projects`` () = + let library = { + SyntheticProject.Create("Library", + { sourceFile "Library" [] with Source = """ +module internal Lib.Library +let foo x = x + 5 + +[] +do ()""" }) + with AutoAddModules = false } + + let project = + { SyntheticProject.Create("App", + { sourceFile "First" [] with Source = """ +open Lib +let bar x = Library.foo x""" }) + with DependsOn = [library] } + + project.Workflow { + placeCursor "Library" "foo" + findAllReferences (expectToFind [ + "FileFirst.fs", 4, 12, 23 + "FileLibrary.fs", 3, 4, 7 + ]) + } + + [] let ``We find back-ticked identifiers`` () = SyntheticProject.Create( diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 1d4c882a954..284d39e107e 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -441,6 +441,9 @@ let private renderFsProj (p: SyntheticProject) = let version = reference.Version |> Option.map (fun v -> $" Version=\"{v}\"") |> Option.defaultValue "" $"" + for project in p.DependsOn do + $"" + for f in p.SourceFiles do if f.HasSignatureFile then $"" @@ -1019,10 +1022,10 @@ type ProjectWorkflowBuilder member this.FindSymbolUse(ctx: WorkflowContext, fileId, symbolName: string) = async { - let file = ctx.Project.Find fileId - let fileName = ctx.Project.ProjectDir ++ file.FileName - let source = renderSourceFile ctx.Project file - let options= ctx.Project.GetProjectOptions checker + let project, file = ctx.Project.FindInAllProjects fileId + let fileName = project.ProjectDir ++ file.FileName + let source = renderSourceFile project file + let options= project.GetProjectOptions checker return! getSymbolUse fileName source symbolName options checker } @@ -1072,7 +1075,6 @@ type ProjectWorkflowBuilder member this.FindAllReferences(workflow: Async, processResults) = async { let! ctx = workflow - let options = ctx.Project.GetProjectOptions checker let symbolUse = ctx.Cursor @@ -1080,8 +1082,10 @@ type ProjectWorkflowBuilder failwith $"Please place cursor at a valid location via placeCursor first") let! results = - [ for f in options.SourceFiles do - checker.FindBackgroundReferencesInFile(f, options, symbolUse.Symbol, fastCheck = true) ] + [ for p, f in ctx.Project.GetAllFiles() do + let options = p.GetProjectOptions checker + let fileName = getFilePath p f + checker.FindBackgroundReferencesInFile(fileName, options, symbolUse.Symbol, fastCheck = true) ] |> Async.Parallel results |> Seq.collect id |> Seq.toList |> processResults diff --git a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs index c5418d5903b..13ce7416d16 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs @@ -24,13 +24,14 @@ type SymbolUse = type FSharpSymbol with member this.IsInternalToProject = + let publicOrInternal = this.Accessibility.IsPublic || this.Accessibility.IsInternal match this with | :? FSharpParameter -> true - | :? FSharpMemberOrFunctionOrValue as m -> not m.IsModuleValueOrMember || not m.Accessibility.IsPublic - | :? FSharpEntity as m -> not m.Accessibility.IsPublic + | :? FSharpMemberOrFunctionOrValue as m -> not m.IsModuleValueOrMember || not publicOrInternal + | :? FSharpEntity -> not publicOrInternal | :? FSharpGenericParameter -> true - | :? FSharpUnionCase as m -> not m.Accessibility.IsPublic - | :? FSharpField as m -> not m.Accessibility.IsPublic + | :? FSharpUnionCase -> not publicOrInternal + | :? FSharpField -> not publicOrInternal | _ -> false type FSharpSymbolUse with From 262ec4d387e0a2a09ccd79e1202c6269254036f0 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Wed, 30 Aug 2023 17:23:22 +0200 Subject: [PATCH 2/5] undo whitespace change --- src/Compiler/Service/IncrementalBuild.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 91c4caa7123..6dc16fedf0a 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -408,7 +408,7 @@ type BoundModel private ( member this.TryPeekTcInfo() = this.TcInfo.TryPeekValue() |> ValueOption.toOption - member this.TryPeekTcInfoWithExtras() = + member this.TryPeekTcInfoWithExtras() = (this.TcInfo.TryPeekValue(), this.TcInfoExtras.TryPeekValue()) ||> ValueOption.map2 (fun a b -> a, b) |> ValueOption.toOption From c23e8876f7768d58133988561abc5f863e60ef93 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Wed, 30 Aug 2023 20:47:36 +0200 Subject: [PATCH 3/5] f --- vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs index 13ce7416d16..19e446f2d08 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs @@ -25,6 +25,7 @@ type FSharpSymbol with member this.IsInternalToProject = let publicOrInternal = this.Accessibility.IsPublic || this.Accessibility.IsInternal + match this with | :? FSharpParameter -> true | :? FSharpMemberOrFunctionOrValue as m -> not m.IsModuleValueOrMember || not publicOrInternal From e06e7931c811210f818b286556754f17b39f39e7 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Thu, 31 Aug 2023 12:44:34 +0200 Subject: [PATCH 4/5] Fix finding signature files --- tests/FSharp.Test.Utilities/ProjectGeneration.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 284d39e107e..ee5e2bcb736 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -1084,8 +1084,8 @@ type ProjectWorkflowBuilder let! results = [ for p, f in ctx.Project.GetAllFiles() do let options = p.GetProjectOptions checker - let fileName = getFilePath p f - checker.FindBackgroundReferencesInFile(fileName, options, symbolUse.Symbol, fastCheck = true) ] + for fileName in [getFilePath p f; if f.SignatureFile <> No then getSignatureFilePath p f] do + checker.FindBackgroundReferencesInFile(fileName, options, symbolUse.Symbol, fastCheck = true) ] |> Async.Parallel results |> Seq.collect id |> Seq.toList |> processResults From 68788cacdf8fd22f4d3b3a8341479d2bf5dbfb2c Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Tue, 5 Sep 2023 18:38:08 +0200 Subject: [PATCH 5/5] fixed test --- .../FSharpChecker/FindReferences.fs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs index 7b8bb18b169..1492cf97d2d 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs @@ -129,11 +129,13 @@ let ``Find references to internal symbols in other projects`` () = let library = { SyntheticProject.Create("Library", { sourceFile "Library" [] with Source = """ -module internal Lib.Library -let foo x = x + 5 +namespace Lib -[] -do ()""" }) +module internal Library = + let foo x = x + 5 + +[] +do () """ }) with AutoAddModules = false } let project = @@ -147,7 +149,7 @@ let bar x = Library.foo x""" }) placeCursor "Library" "foo" findAllReferences (expectToFind [ "FileFirst.fs", 4, 12, 23 - "FileLibrary.fs", 3, 4, 7 + "FileLibrary.fs", 5, 8, 11 ]) }