Skip to content

Commit 5c24dea

Browse files
Improve solution explorer
1 parent f6018df commit 5c24dea

File tree

4 files changed

+63
-60
lines changed

4 files changed

+63
-60
lines changed

src/Components/Fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ module Fsi =
377377
|> Promise.suppress // prevent unhandled promise exception
378378
|> ignore
379379

380-
let private referenceAssembly (path : ProjectReferencePath) = path |> sprintf "#r @\"%s\"" |> send
380+
let private referenceAssembly (path : ResolvedReferencePath) = path |> sprintf "#r @\"%s\"" |> send
381381
let private referenceAssemblies = Promise.executeForAll referenceAssembly
382382

383383
let private sendReferences () =

src/Components/SolutionExplorer.fs

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module SolutionExplorer =
1919
| Workspace of Projects : Model list
2020
| Solution of parent : Model option ref * path : string * name : string * items : Model list
2121
| WorkspaceFolder of parent : Model option ref * name : string * items : Model list
22-
| ReferenceList of parent : Model option ref * References : Model list * projectPath : string
22+
| PackageReferenceList of parent : Model option ref * References : Model list * projectPath : string
2323
| ProjectReferencesList of parent : Model option ref * Projects : Model list * ProjectPath : string
2424
| ProjectNotLoaded of parent : Model option ref * path : string * name : string
2525
| ProjectLoading of parent : Model option ref * path : string * name : string
@@ -29,7 +29,7 @@ module SolutionExplorer =
2929
| Project of parent : Model option ref * path : string * name : string * Files : Model list * ProjectReferencesList : Model * ReferenceList : Model * isExe : bool * project : DTO.Project
3030
| Folder of parent : Model option ref * name : string * path : string * Files : Model list * projectPath : string
3131
| File of parent : Model option ref * path : string * name : string * projectPath : string
32-
| Reference of parent : Model option ref * path : string * name : string * projectPath : string
32+
| PackageReference of parent : Model option ref * path : string * name : string * projectPath : string
3333
| ProjectReference of parent : Model option ref * path : string * name : string * projectPath : string
3434

3535
type NodeEntry =
@@ -68,7 +68,7 @@ module SolutionExplorer =
6868
| Workspace _ -> ref None
6969
| Solution (parent, _, _, _) -> parent
7070
| WorkspaceFolder (parent, _, _) -> parent
71-
| ReferenceList (parent, _, _) -> parent
71+
| PackageReferenceList (parent, _, _) -> parent
7272
| ProjectReferencesList (parent, _, _) -> parent
7373
| ProjectNotLoaded (parent, _, _) -> parent
7474
| ProjectLoading (parent, _, _) -> parent
@@ -78,7 +78,7 @@ module SolutionExplorer =
7878
| Project (parent, _, _, _, _, _, _, _) -> parent
7979
| Folder (parent, _, _, _, _) -> parent
8080
| File (parent, _, _, _) -> parent
81-
| Reference (parent, _, _, _) -> parent
81+
| PackageReference (parent, _, _, _) -> parent
8282
| ProjectReference (parent, _, _, _) -> parent
8383

8484
let inline setParentRef (model : Model) (parent : Model) =
@@ -135,31 +135,30 @@ module SolutionExplorer =
135135
|> Seq.toList
136136
|> buildTree proj.Project
137137

138-
let refs =
139-
proj.References
140-
|> Seq.map (fun p -> Reference(ref None, p,node.path.basename p, proj.Project))
138+
let packageRefs =
139+
proj.PackageReferences
140+
|> Seq.distinctBy (fun p -> p.Name)
141+
|> Seq.map (fun p -> PackageReference(ref None, p.FullPath,p.Name + " " + p.Version, proj.Project))
141142
|> Seq.toList
142143
|> fun n ->
143-
let result = ReferenceList(ref None, n, proj.Project)
144+
let result = PackageReferenceList(ref None, n, proj.Project)
144145
setParentRefs n result
145146
result
146147

147148
let projs =
148-
proj.References
149-
|> Seq.choose (fun r ->
150-
projects
151-
|> Array.tryFind (fun pr -> pr.Output = r))
152-
|> Seq.map (fun p -> ProjectReference(ref None, p.Project, node.path.basename(p.Project, ".fsproj"), proj.Project))
149+
proj.ProjectReferences
150+
|> Seq.distinctBy (fun p -> p.ProjectFileName)
151+
|> Seq.map (fun p -> ProjectReference(ref None, p.ProjectFileName, node.path.basename(p.ProjectFileName, ".fsproj"), proj.Project))
153152
|> Seq.toList
154153
|> fun n ->
155154
let result = ProjectReferencesList(ref None, n, proj.Project)
156155
setParentRefs n result
157156
result
158157

159158
let name = node.path.basename(proj.Project, ".fsproj")
160-
let result = Project(ref None, proj.Project, name,files, projs, refs, Project.isExeProject proj, proj)
159+
let result = Project(ref None, proj.Project, name,files, projs, packageRefs, Project.isExeProject proj, proj)
161160
setParentRefs files result
162-
setParentRef refs result
161+
setParentRef packageRefs result
163162
setParentRef projs result
164163
result
165164

@@ -249,11 +248,11 @@ module SolutionExplorer =
249248
yield projs
250249
yield! files
251250
]
252-
| ReferenceList (_, refs, _) -> refs
251+
| PackageReferenceList (_, refs, _) -> refs
253252
| ProjectReferencesList (_, refs, _) -> refs
254253
| Folder (_, _,_,files, _) -> files
255254
| File _ -> []
256-
| Reference _ -> []
255+
| PackageReference _ -> []
257256
| ProjectReference _ -> []
258257

259258
let private getLabel node =
@@ -267,11 +266,11 @@ module SolutionExplorer =
267266
| ProjectNotRestored (_, _, name, _) -> sprintf "%s (not restored)" name
268267
| ProjectLanguageNotSupported(_, _, name) -> sprintf "%s (language not supported)" name
269268
| Project (_, _, name,_, _,_, _, _) -> name
270-
| ReferenceList _ -> "References"
269+
| PackageReferenceList _ -> "Package References"
271270
| ProjectReferencesList (_, refs, _) -> "Project References"
272271
| Folder (_, n,_, _, _) -> n
273272
| File (_, _, name, _) -> name
274-
| Reference (_, _, name, _) ->
273+
| PackageReference (_, _, name, _) ->
275274
if name.ToLowerInvariant().EndsWith(".dll") then
276275
name.Substring(0, name.Length - 4)
277276
else
@@ -310,7 +309,7 @@ module SolutionExplorer =
310309
member this.getTreeItem(node) =
311310
let collaps =
312311
match node with
313-
| File _ | Reference _ | ProjectReference _ ->
312+
| File _ | PackageReference _ | ProjectReference _ ->
314313
vscode.TreeItemCollapsibleState.None
315314
| ProjectFailedToLoad _ | ProjectLoading _ | ProjectNotLoaded _ | ProjectNotRestored _ | ProjectLanguageNotSupported _
316315
| Workspace _ | Solution _ ->
@@ -329,10 +328,10 @@ module SolutionExplorer =
329328
vscode.TreeItemCollapsibleState.Expanded
330329
else
331330
vscode.TreeItemCollapsibleState.Collapsed
332-
| Folder _ | Project _ | ProjectReferencesList _ | ReferenceList _ ->
331+
| Folder _ | Project _ | ProjectReferencesList _ | PackageReferenceList _ ->
333332
vscode.TreeItemCollapsibleState.Collapsed
334333

335-
let ti = new TreeItem(getLabel node, collaps)
334+
let ti = TreeItem(getLabel node, collaps)
336335

337336
let command =
338337
match node with
@@ -351,11 +350,11 @@ module SolutionExplorer =
351350
match node with
352351
| File _ -> "file"
353352
| ProjectReferencesList _ -> "projectRefList"
354-
| ReferenceList _ -> "referencesList"
353+
| PackageReferenceList _ -> "referencesList"
355354
| Project (_, _, _, _, _, _, false, _) -> "project"
356355
| Project (_, _, _, _, _, _, true, _) -> "projectExe"
357356
| ProjectReference _ -> "projectRef"
358-
| Reference _ -> "reference"
357+
| PackageReference _ -> "reference"
359358
| Folder _ -> "folder"
360359
| ProjectFailedToLoad _ -> "projectLoadFailed"
361360
| ProjectLoading _ -> "projectLoading"
@@ -385,19 +384,19 @@ module SolutionExplorer =
385384
ThemeIcon.Folder |> U4.Case4 |> Some, Uri.file path |> Some
386385
| WorkspaceFolder _ ->
387386
ThemeIcon.Folder |> U4.Case4 |> Some, None
388-
| Reference (_, path, _, _) | ProjectReference (_, path, _, _) ->
387+
| PackageReference (_, path, _, _) | ProjectReference (_, path, _, _) ->
389388
p.light <- (plugPath + "/images/circuit-board-light.svg") |> U3.Case1
390389
p.dark <- (plugPath + "/images/circuit-board-dark.svg") |> U3.Case1
391390
p |> U4.Case3 |> Some, Uri.file path |> Some
392391
| Workspace _
393-
| ReferenceList _
392+
| PackageReferenceList _
394393
| ProjectReferencesList _ ->
395394
None, None
396395
ti.iconPath <- icon
397396
ti.resourceUri <- resourceUri
398397
ti.id <-
399398
match node with
400-
| ReferenceList (_, _, pp) | ProjectReferencesList (_, _,pp) | Reference (_, _, _, pp) | ProjectReference (_, _, _, pp) ->
399+
| PackageReferenceList (_, _, pp) | ProjectReferencesList (_, _,pp) | PackageReference (_, _, _, pp) | ProjectReference (_, _, _, pp) ->
401400
Some ((defaultArg ti.label "") + "||" + pp)
402401
| Folder (_, _,_, _, pp) | File (_, _, _, pp) ->
403402
(resourceUri |> Option.map(fun u -> (defaultArg ti.label "") + "||" + u.toString() + "||" + pp))
@@ -480,9 +479,9 @@ module SolutionExplorer =
480479
| WorkspaceFolder (_, _, children)
481480
| Workspace children ->
482481
children |> List.collect getModelPerFile
483-
| Reference _
482+
| PackageReference _
484483
| ProjectReference _
485-
| ReferenceList _
484+
| PackageReferenceList _
486485
| ProjectReferencesList _->
487486
[]
488487

@@ -684,36 +683,26 @@ module SolutionExplorer =
684683

685684
let viewParsed (proj: Project) =
686685
match getProjectModel proj with
687-
| (Project(_,_,_, files, ProjectReferencesList(_,projRefs,_), ReferenceList(_, refs,_), _, _)) ->
686+
| (Project(_,_,_, files, ProjectReferencesList(_,projRefs,_), PackageReferenceList(_, refs,_), _, project)) ->
688687
let files =
689-
files
690-
|> List.filter (function
691-
| File _ -> true
692-
| _ -> false)
693-
|> List.map (function
694-
| File(_,p, _, _) -> p
695-
| _ -> failwith "Should not happend, we filtered the `files` list before"
696-
)
688+
project.Files
697689

698690
let projRefs =
699-
projRefs
700-
|> List.filter (function
701-
| ProjectReference _ -> true
702-
| _ -> false
703-
)
704-
|> List.map (function
705-
| ProjectReference(_,p, _, _) -> p
706-
| _ -> failwith "Should not happend, we filtered the `projRefs` list before"
707-
)
691+
project.ProjectReferences
692+
|> Array.map (fun n -> n.ProjectFileName)
693+
694+
let packageRefs =
695+
project.PackageReferences
696+
|> Array.map (fun n -> n.Name + " " + n.Version)
708697

709698
let refs =
710699
refs
711700
|> List.filter (function
712-
| Reference _ -> true
701+
| PackageReference _ -> true
713702
| _ -> false
714703
)
715704
|> List.map (function
716-
| Reference(_,p, _, _) -> p
705+
| PackageReference(_,p, _, _) -> p
717706
| _ -> failwith "Should not happend, we filtered the `refs` list before"
718707
)
719708
let info = proj.Info
@@ -740,18 +729,21 @@ module SolutionExplorer =
740729
if crossgen then
741730
yield "<b>NOTE: You're using multiple target frameworks. As of now you can't choose which target framework should be used by FSAC. Instead, the first target framework from the list is selected. To change the target framework used by FSAC, simply place it on the first position on the &lt;TargetFrameworks&gt; list.</b>"
742731
yield "For more info see this issue: https://github.com/ionide/ionide-vscode-fsharp/issues/278"
743-
yield "<ul>"
744-
for tfm in info.TargetFrameworks do
745-
yield sprintf "<li>%s</li>" tfm
746-
yield "</ul>"
732+
yield "<ul>"
733+
for tfm in info.TargetFrameworks do
734+
yield sprintf "<li>%s</li>" tfm
735+
yield "</ul>"
747736
yield ""
748737
yield "<b>Files</b>:"
749738
yield! files
750739
yield ""
751740
yield "<b>Project References</b>:"
752741
yield! projRefs
753742
yield ""
754-
yield "<b>References</b>:"
743+
yield "<b>Package References</b>:"
744+
yield! packageRefs
745+
yield ""
746+
yield "<b>Resolved References</b>:"
755747
yield! refs
756748
]
757749
|> String.concat "<br />"

src/Core/DTO.fs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ module DTO =
203203

204204
type ProjectFilePath = string
205205
type SourceFilePath = string
206-
type ProjectReferencePath = string
206+
type ResolvedReferencePath = string
207207

208208
type ProjectLoading = { Project : ProjectFilePath }
209209

@@ -230,11 +230,22 @@ module DTO =
230230
Metadata: Map<string, string>
231231
}
232232

233+
type ProjectReference =
234+
{ RelativePath: string
235+
ProjectFileName: string }
236+
237+
type PackageReference =
238+
{ Name: string
239+
Version: string
240+
FullPath: string }
241+
233242
type Project =
234243
{ Project : ProjectFilePath
235244
Files : SourceFilePath array
236245
Output : string
237-
References : ProjectReferencePath array
246+
References : ResolvedReferencePath array
247+
ProjectReferences: ProjectReference array
248+
PackageReferences: PackageReference array
238249
Logs : Map<string, string>
239250
OutputType : string
240251
Info : ProjectResponseInfoDotnetSdk

src/Core/Utils.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Json =
99

1010
/// Previously `Fable.Core.JsInterop.ofJson`
1111
/// Instantiate F# objects from JSON
12-
let inline ofJson<'a> json : 'a =
12+
let inline ofJson<'a> json : 'a =
1313
// see https://fable.io/blog/Migration-to-Fable2.html#breaking-changes
1414
Decode.Auto.unsafeFromString<'a>(json)
1515

@@ -229,8 +229,8 @@ module Promise =
229229
// source: https://github.com/ionide/ionide-vscode-helpers/blob/5e4c28c79ed565497cd481fac2f22ee2d8d28406/src/Helpers.fs#L92
230230
let onFail a (pr: JS.Promise<_>) : JS.Promise<_> =
231231
pr
232-
|> Promise.catchBind (fun reason ->
233-
a reason |> ignore
232+
|> Promise.catchBind (fun reason ->
233+
a reason |> ignore
234234
Promise.reject reason
235235
)
236236

0 commit comments

Comments
 (0)