diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs index e1cd294ba53..1492cf97d2d 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs @@ -124,6 +124,36 @@ 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 = """ +namespace Lib + +module internal 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", 5, 8, 11 + ]) + } + + [] 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..ee5e2bcb736 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 + 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 diff --git a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs index c5418d5903b..19e446f2d08 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/Symbols.fs @@ -24,13 +24,15 @@ 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