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

Fix project references in FCS layer #128

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Ionide.ProjInfo.FCS/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module FCS =
|> Array.choose
(fun d ->
if d.ProjectFileName.EndsWith ".fsproj" then
allKnownProjects
allKnownProjects
|> Seq.tryFind (fun n -> n.ProjectFileName = d.ProjectFileName)
|> Option.map (fun p -> FSharpReferencedProject.CreateFSharp(d.ProjectFileName, mapToFSharpProjectOptions p allKnownProjects))
|> Option.map (fun p -> FSharpReferencedProject.CreateFSharp(p.TargetPath, mapToFSharpProjectOptions p allKnownProjects))
else
// TODO: map other project types to references here
None)
Expand Down
52 changes: 52 additions & 0 deletions test/Ionide.ProjInfo.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,55 @@ let testFCSmap toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorksp

)

let testFCSmapManyProj toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorkspaceLoader) =
ftestCase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should unfocus this test

|> withLog (sprintf "can load sample3 with FCS - %s" workspaceLoader) (fun logger fs ->

let rec allFCSProjects (po: FSharpProjectOptions) =
[ yield po
for reference in po.ReferencedProjects do
match internalGetProjectOptions reference with
| Some opts -> yield! allFCSProjects opts
| None -> () ]


let rec allP2P (po: FSharpProjectOptions) =
[ for reference in po.ReferencedProjects do
let opts = internalGetProjectOptions reference |> Option.get
yield reference.FileName, opts
yield! allP2P opts ]

let expectP2PKeyIsTargetPath (pos: Map<string, ProjectOptions>) fcsPo =
for (tar, fcsPO) in allP2P fcsPo do
let dpoPo = pos |> Map.find fcsPo.ProjectFileName
Expect.equal tar dpoPo.TargetPath (sprintf "p2p key is TargetPath, fsc projet options was '%A'" fcsPO)

let testDir = inDir fs "load_sample_fsc"
copyDirFromAssets fs ``sample3 Netsdk projs``.ProjDir testDir

let projPath = testDir / (``sample3 Netsdk projs``.ProjectFile)

dotnet fs [ "restore"; projPath ] |> checkExitCodeZero

let loader = workspaceFactory toolsPath

let parsed = loader.LoadProjects [ projPath ] |> Seq.toList
let mutable pos = Map.empty

loader.Notifications.Add (function | WorkspaceProjectState.Loaded (po, knownProjects, _) -> pos <- Map.add po.ProjectFileName po pos)

let fcsPo = FCS.mapToFSharpProjectOptions parsed.Head parsed
let hasCSharpRef = fcsPo.OtherOptions |> Seq.exists (fun opt -> opt.StartsWith "-r:" && opt.EndsWith "l1.dll")
let hasCSharpProjectRef = fcsPo.ReferencedProjects |> Seq.exists (fun ref -> ref.FileName.EndsWith "l1.dll")
let hasFSharpRef = fcsPo.OtherOptions |> Seq.exists (fun opt -> opt.StartsWith "-r:" && opt.EndsWith "l2.dll")
let hasFSharpProjectRef = fcsPo.ReferencedProjects |> Seq.exists (fun ref -> ref.FileName.EndsWith "l2.dll")
Expect.equal hasCSharpRef true "Should have direct dll reference to C# reference"
Expect.equal hasCSharpProjectRef false "Should NOT have project reference to C# reference"
Expect.equal hasFSharpRef true "Should have direct dll reference to F# reference"
Expect.equal hasFSharpProjectRef true "Should have project reference to F# reference"

)

let testSample2WithBinLog toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorkspaceLoader) =
testCase
|> withLog (sprintf "can load sample2 with bin log - %s" workspaceLoader) (fun logger fs ->
Expand Down Expand Up @@ -991,6 +1040,9 @@ let tests toolsPath =
//FCS tests
testFCSmap toolsPath "WorkspaceLoader" WorkspaceLoader.Create
testFCSmap toolsPath "WorkspaceLoaderViaProjectGraph" WorkspaceLoaderViaProjectGraph.Create
//FCS multi-project tests
testFCSmapManyProj toolsPath "WorkspaceLoader" WorkspaceLoader.Create
testFCSmapManyProj toolsPath "WorkspaceLoaderViaProjectGraph" WorkspaceLoaderViaProjectGraph.Create
//ProjectSystem tests
testProjectSystem toolsPath "WorkspaceLoader" WorkspaceLoader.Create
testProjectSystem toolsPath "WorkspaceLoaderViaProjectGraph" WorkspaceLoaderViaProjectGraph.Create
Expand Down