Skip to content

Commit

Permalink
FIX: Making ProjectGraphLoader work again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Aug 20, 2022
1 parent 93d7afe commit aae4a7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,18 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath, ?globalProperties: (stri
handleProjectGraphFailures
<| fun () ->
paths |> Seq.iter (fun p -> loadingNotification.Trigger(WorkspaceProjectState.Loading p))

let graph =
match paths |> List.ofSeq with
| [ x ] -> ProjectGraph(x, projectCollection = ProjectCollection.GlobalProjectCollection, projectInstanceFactory = projectInstanceFactory)
| [ x ] ->
let g = ProjectGraph(x, projectCollection = ProjectCollection.GlobalProjectCollection, projectInstanceFactory = projectInstanceFactory)
// When giving ProjectGraph a singular project, g.EntryPointNodes only contains that project.
// To get it to build the Graph with all the dependencies we need to look at all the ProjectNodes
// and tell the graph to use all as potentially an entrypoint
let nodes =
g.ProjectNodes
|> Seq.map(fun pn -> ProjectGraphEntryPoint pn.ProjectInstance.FullPath)
ProjectGraph(nodes, projectCollection = ProjectCollection.GlobalProjectCollection, projectInstanceFactory = projectInstanceFactory)

| xs ->
let entryPoints = paths |> Seq.map ProjectGraphEntryPoint |> List.ofSeq
ProjectGraph(entryPoints, projectCollection = ProjectCollection.GlobalProjectCollection, projectInstanceFactory = projectInstanceFactory)
Expand Down Expand Up @@ -789,23 +797,18 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath, ?globalProperties: (stri
|> Seq.collect (fun (pgn: ProjectGraphNode) ->
seq {
yield pgn.ProjectInstance
yield! Seq.map (fun (pr: ProjectGraphNode) -> pr.ProjectInstance) pgn.ProjectReferences
})
|> Seq.toList

logger.info (
Log.setMessage "{overallCode}, projects built {count} {projects} "
>> Log.addContextDestructured "count" (buildProjs |> Seq.length)
>> Log.addContextDestructured "projects" (buildProjs)
>> Log.addContextDestructured "overallCode" result.OverallResult
>> Log.addExn result.Exception
)

let projects =
buildProjs
|> List.distinctBy (fun (p: ProjectInstance) -> p.FullPath)
|> Seq.map (fun (p: ProjectInstance) ->

|> Seq.map(fun p ->
p.FullPath, ProjectLoader.getLoadedProjectInfo p.FullPath customProperties (ProjectLoader.LoadedProject p))

|> Seq.choose (fun (projectPath, projectOptionResult) ->
Expand Down
22 changes: 16 additions & 6 deletions test/Ionide.ProjInfo.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,10 @@ let testFCSmapManyProj toolsPath workspaceLoader (workspaceFactory: ToolsPath ->

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

let fcsPo = FCS.mapToFSharpProjectOptions parsed.Head parsed
let parsedC1 = parsed |> Seq.find(fun x ->
x.ProjectFileName.EndsWith(``sample3 Netsdk projs``.ProjectFile)
)
let fcsPo = FCS.mapToFSharpProjectOptions parsedC1 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.OutputFile.EndsWith "l1.dll")
let hasFSharpRef = fcsPo.OtherOptions |> Seq.exists (fun opt -> opt.StartsWith "-r:" && opt.EndsWith "l2.dll")
Expand Down Expand Up @@ -1241,13 +1243,21 @@ let debugTests toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorksp
ptestCase
|> withLog (sprintf "debug - %s" workspaceLoader) (fun logger fs ->

let projPath = @"D:\Programowanie\Projekty\Ionide\dotnet-proj-info\src\Ionide.ProjInfo.Sln\Ionide.ProjInfo.Sln.csproj"

let loader = workspaceFactory toolsPath

let parsed = loader.LoadProjects [ projPath ] |> Seq.toList
// let projPath = @"D:\Programowanie\Projekty\Ionide\dotnet-proj-info\src\Ionide.ProjInfo.Sln\Ionide.ProjInfo.Sln.csproj"
// let parsedProjs = loader.LoadProjects [ projPath ] |> Seq.toList

// printfn "%A" parsedProjs

printfn "%A" parsed
let slnPath = @"C:\Users\JimmyByrd\Documents\Repositories\public\TheAngryByrd\FsToolkit.ErrorHandling\FsToolkit.ErrorHandling.sln"
let parsedProjs = loader.LoadSln slnPath |> Seq.toList

// printfn "%A" parsedProjs
parsedProjs
|> Seq.iter(fun p ->
Expect.isGreaterThan p.SourceFiles.Length 0 $"{p.ProjectFileName} Should have SourceFiles"
)
)

let expensiveTests toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) =
Expand Down

0 comments on commit aae4a7a

Please sign in to comment.