Skip to content

Commit be8ee10

Browse files
committed
WIP
1 parent 11de177 commit be8ee10

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed

src/Components/MSBuild.fs

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ module MSBuild =
399399
let buildTaskListForSolution (s: WorkspacePeekFound) : JS.Promise<MSBuildTask seq> =
400400
promise {
401401
match s with
402+
| WorkspacePeekFound.Fsproj _ -> return Seq.empty
402403
| WorkspacePeekFound.Directory _ -> return Seq.empty
403404
| WorkspacePeekFound.Solution({ Path = p }) ->
404405
let! dotnet = dotnetBinary ()

src/Components/SolutionExplorer.fs

+5
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ module SolutionExplorer =
262262
let result = Workspace items
263263
setParentRefs items result
264264
result
265+
| WorkspacePeekFound.Fsproj proj ->
266+
let result = getProjItem proj.Fsproj
267+
let root = Workspace [ result ]
268+
setParentRef result root
269+
root
265270

266271
let private getSolution () =
267272
Project.getLoadedSolution () |> Option.map getSolutionModel

src/Core/DTO.fs

+3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,11 @@ module DTO =
272272
type WorkspacePeek = { Found: WorkspacePeekFound[] }
273273

274274
and WorkspacePeekFound =
275+
| Fsproj of WorkspacePeekFoundFsproj
275276
| Directory of WorkspacePeekFoundDirectory
276277
| Solution of WorkspacePeekFoundSolution
278+
and WorkspacePeekFoundFsproj =
279+
{ Fsproj: string }
277280

278281
and WorkspacePeekFoundDirectory =
279282
{ Directory: string; Fsprojs: string[] }

src/Core/LanguageService.fs

+9-5
Original file line numberDiff line numberDiff line change
@@ -516,22 +516,26 @@ Consider:
516516
Kind = kind }
517517
| None -> None
518518

519-
let mapFound (f: obj) : WorkspacePeekFound option =
519+
let mapFound (f: obj) : WorkspacePeekFound array =
520520
let data = f?Data
521521

522522
match f?Type |> unbox with
523-
| "directory" -> Some(WorkspacePeekFound.Directory(data |> unbox))
523+
| "directory" ->
524+
let folderPeek = [|WorkspacePeekFound.Directory(data |> unbox)|]
525+
let projectPeeks = data?Fsprojs |> unbox |> Array.map (fun p -> WorkspacePeekFound.Fsproj({ Fsproj = p }))
526+
527+
Array.concat [|projectPeeks;folderPeek|]
524528
| "solution" ->
525529
let sln =
526530
{ WorkspacePeekFoundSolution.Path = data?Path |> unbox
527531
Configurations = data?Configurations |> unbox
528532
Items = data?Items |> unbox |> Array.choose mapItem }
529533

530-
Some(WorkspacePeekFound.Solution sln)
531-
| _ -> None
534+
[|WorkspacePeekFound.Solution sln|]
535+
| _ -> [||]
532536

533537
let parse (ws: obj) =
534-
{ WorkspacePeek.Found = ws?Found |> unbox |> Array.choose mapFound }
538+
{ WorkspacePeek.Found = ws?Found |> unbox |> Array.map mapFound |> Array.concat }
535539

536540
match client with
537541
| None -> Promise.empty

src/Core/Project.fs

+55-27
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ module Project =
107107

108108
sln.Items |> Array.collect getProjs |> Array.toList
109109
| Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs |> Array.toList
110+
| Some(WorkspacePeekFound.Fsproj fsproj) -> [ fsproj.Fsproj ]
110111

111112

112113
let getNotLoaded () =
@@ -251,6 +252,7 @@ module Project =
251252
match loadedWorkspace with
252253
| None -> Array.empty
253254
| Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs
255+
| Some(WorkspacePeekFound.Fsproj fsproj) -> [| fsproj.Fsproj |]
254256
| Some(WorkspacePeekFound.Solution sln) -> sln.Items |> Array.collect foldFsproj |> Array.map fst
255257

256258
let loadingInProgress p =
@@ -308,6 +310,7 @@ module Project =
308310
type ConfiguredWorkspace =
309311
| Solution of path: string
310312
| Directory of path: string
313+
| Fsproj of path: string
311314

312315
module private CurrentWorkspaceConfiguration =
313316
let private key = "FSharp.workspacePath"
@@ -322,6 +325,8 @@ module Project =
322325

323326
if value.ToLowerInvariant().EndsWith(".sln") then
324327
ConfiguredWorkspace.Solution fullPath
328+
else if value.ToLowerInvariant().EndsWith(".fsproj") then
329+
ConfiguredWorkspace.Fsproj fullPath
325330
else
326331
ConfiguredWorkspace.Directory fullPath
327332

@@ -333,6 +338,12 @@ module Project =
333338
not (isNull stats) && (stats.isDirectory ())
334339
with _ ->
335340
false
341+
| ConfiguredWorkspace.Fsproj fsproj ->
342+
try
343+
let stats = node.fs.statSync (U2.Case1 fsproj)
344+
not (isNull stats) && (stats.isFile ())
345+
with _ ->
346+
false
336347
| ConfiguredWorkspace.Solution sln ->
337348
try
338349
let stats = node.fs.statSync (U2.Case1 sln)
@@ -373,6 +384,7 @@ module Project =
373384
match value with
374385
| ConfiguredWorkspace.Solution path -> path
375386
| ConfiguredWorkspace.Directory path -> path
387+
| ConfiguredWorkspace.Fsproj path -> path
376388

377389
let private isConfiguredInWorkspace () =
378390
match getStringFromWorkspaceConfig () with
@@ -400,6 +412,7 @@ module Project =
400412
let setFromPeek (value: WorkspacePeekFound) =
401413
match value with
402414
| WorkspacePeekFound.Directory dir -> ConfiguredWorkspace.Directory dir.Directory
415+
| WorkspacePeekFound.Fsproj fsproj -> ConfiguredWorkspace.Fsproj fsproj.Fsproj
403416
| WorkspacePeekFound.Solution sln -> ConfiguredWorkspace.Solution sln.Path
404417
|> set
405418

@@ -419,6 +432,7 @@ module Project =
419432
| ConfiguredWorkspace.Directory valueDir, WorkspacePeekFound.Directory peekDir ->
420433
removeEndSlash valueDir = removeEndSlash peekDir.Directory
421434
| ConfiguredWorkspace.Solution valueSln, WorkspacePeekFound.Solution peekSln -> valueSln = peekSln.Path
435+
| ConfiguredWorkspace.Fsproj valueFsproj, WorkspacePeekFound.Fsproj peekFsproj -> valueFsproj = peekFsproj.Fsproj
422436
| _ -> false
423437

424438
let tryFind (value: ConfiguredWorkspace option) (found: WorkspacePeekFound list) =
@@ -444,6 +458,12 @@ module Project =
444458
item.label <- sprintf "%s%s" check dir.Directory
445459
item.description <- Some(sprintf "Directory with %i projects" dir.Fsprojs.Length)
446460
item
461+
| WorkspacePeekFound.Fsproj fsproj ->
462+
let relative = node.path.relative (workspace.rootPath.Value, fsproj.Fsproj)
463+
let item = createEmpty<QuickPickItem>
464+
item.label <- sprintf "%s%s" check relative
465+
item.description <- Some(sprintf "Single project")
466+
item
447467
| WorkspacePeekFound.Solution sln ->
448468
let relative = node.path.relative (workspace.rootPath.Value, sln.Path)
449469
let item = createEmpty<QuickPickItem>
@@ -556,12 +576,12 @@ module Project =
556576
return []
557577
else
558578
let! ws = LanguageService.workspacePeek workspace.rootPath.Value deepLevel (excluded |> List.ofArray)
559-
560579
return
561580
ws.Found
562581
|> Array.sortBy (fun x ->
563582
match x with
564583
| WorkspacePeekFound.Solution sln -> countProjectsInSln sln
584+
| WorkspacePeekFound.Fsproj _ -> 0
565585
| WorkspacePeekFound.Directory _ -> -1)
566586
|> Array.rev
567587
|> List.ofArray
@@ -572,33 +592,39 @@ module Project =
572592
let! ws = workspacePeek ()
573593
let configured = CurrentWorkspaceConfiguration.get ()
574594
let configuredPeek = CurrentWorkspaceConfiguration.tryFind configured ws
575-
576-
match configuredPeek with
577-
| Some peek ->
578-
// If a workspace is configured, use it
579-
return Some peek
580-
| None ->
595+
let! choosen = pickFSACWorkspace ws None
596+
return choosen
597+
598+
// TODO: Rewrite this so that the sln isn't always chosen, maybe add a config?
599+
600+
// match configuredPeek with
601+
// | Some peek ->
602+
// // If a workspace is configured, use it
603+
// return Some peek
604+
// | None ->
605+
581606
// prefer the sln, load directly the first one, otherwise ask
582-
let slns =
583-
ws
584-
|> List.choose (fun x ->
585-
match x with
586-
| WorkspacePeekFound.Solution _ -> Some x
587-
| _ -> None)
588-
589-
let! choosen =
590-
match slns with
591-
| [] ->
592-
ws
593-
|> List.tryPick (fun x ->
594-
match x with
595-
| WorkspacePeekFound.Directory _ -> Some x
596-
| _ -> None)
597-
|> Promise.lift
598-
| [ sln ] -> Promise.lift (Some sln)
599-
| _ -> pickFSACWorkspace ws None
600-
601-
return choosen
607+
// let slns =
608+
// ws
609+
// |> List.choose (fun x ->
610+
// match x with
611+
// | WorkspacePeekFound.Solution _ -> Some x
612+
// | _ -> None)
613+
614+
// let! choosen =
615+
// match slns with
616+
// | [] ->
617+
// ws
618+
// |> List.tryPick (fun x ->
619+
// match x with
620+
// | WorkspacePeekFound.Directory _ -> Some x
621+
// | _ -> None)
622+
// |> Promise.lift
623+
// | [ sln ] -> Promise.lift (Some sln)
624+
// | _ -> pickFSACWorkspace ws None
625+
626+
// let! choosen = pickFSACWorkspace ws None
627+
// return choosen
602628
}
603629

604630
let handleProjectParsedNotification res =
@@ -650,10 +676,12 @@ module Project =
650676
let projs =
651677
match x with
652678
| WorkspacePeekFound.Directory dir -> dir.Fsprojs
679+
| WorkspacePeekFound.Fsproj fsproj -> [| fsproj.Fsproj |]
653680
| WorkspacePeekFound.Solution sln -> sln.Items |> Array.collect foldFsproj |> Array.map fst
654681

655682
match x with
656683
| WorkspacePeekFound.Solution _ -> setAnyProjectContext true
684+
| WorkspacePeekFound.Fsproj _ -> setAnyProjectContext false
657685
| WorkspacePeekFound.Directory _ when not (projs |> Array.isEmpty) -> setAnyProjectContext true
658686
| _ -> ()
659687

0 commit comments

Comments
 (0)