diff --git a/src/Components/SolutionExplorer.fs b/src/Components/SolutionExplorer.fs index 4528cd0b..0043c001 100644 --- a/src/Components/SolutionExplorer.fs +++ b/src/Components/SolutionExplorer.fs @@ -257,7 +257,7 @@ module SolutionExplorer = setParentRef s result result | WorkspacePeekFound.Directory dir -> - let items = dir.Fsprojs |> Array.map getProjItem |> List.ofArray + let items = dir.Fsprojs |> Array.map (fun f -> getProjItem f.Path) |> List.ofArray let result = Workspace items setParentRefs items result diff --git a/src/Core/DTO.fs b/src/Core/DTO.fs index 4be1a17e..03876239 100644 --- a/src/Core/DTO.fs +++ b/src/Core/DTO.fs @@ -271,12 +271,16 @@ module DTO = type WorkspacePeek = { Found: WorkspacePeekFound[] } + and WorkspacePeekFsproj = + { Path: string; CompileItems: string[] } + and WorkspacePeekFound = | Directory of WorkspacePeekFoundDirectory | Solution of WorkspacePeekFoundSolution and WorkspacePeekFoundDirectory = - { Directory: string; Fsprojs: string[] } + { Directory: string + Fsprojs: WorkspacePeekFsproj[] } and WorkspacePeekFoundSolution = { Path: string diff --git a/src/Core/Project.fs b/src/Core/Project.fs index b99dcb2f..09133f56 100644 --- a/src/Core/Project.fs +++ b/src/Core/Project.fs @@ -108,8 +108,7 @@ module Project = | Folder folder -> folder.Items |> Array.collect getProjs sln.Items |> Array.collect getProjs |> Array.toList - | Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs |> Array.toList - + | Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs |> Array.map (fun f -> f.Path) |> Array.toList let getNotLoaded () = let lst = @@ -252,7 +251,7 @@ module Project = let projs = match loadedWorkspace with | None -> Array.empty - | Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs + | Some(WorkspacePeekFound.Directory dir) -> dir.Fsprojs |> Array.map (fun f -> f.Path) | Some(WorkspacePeekFound.Solution sln) -> sln.Items |> Array.collect foldFsproj |> Array.map fst let loadingInProgress p = @@ -547,7 +546,7 @@ module Project = let wdir = { WorkspacePeekFoundDirectory.Directory = workspace.rootPath.Value - Fsprojs = fsprojs |> Array.ofList } + Fsprojs = fsprojs |> List.map (fun p -> { Path = p; CompileItems = [||] }) |> Array.ofList } return WorkspacePeekFound.Directory wdir } @@ -651,8 +650,8 @@ module Project = let projs = match x with - | WorkspacePeekFound.Directory dir -> dir.Fsprojs - | WorkspacePeekFound.Solution sln -> sln.Items |> Array.collect foldFsproj |> Array.map fst + | WorkspacePeekFound.Directory dir -> dir.Fsprojs |> Array.map (fun f -> (f.Path, f.CompileItems)) + | WorkspacePeekFound.Solution sln -> sln.Items |> Array.collect foldFsproj |> Array.map (fun (p, _) -> (p, [||])) match x with | WorkspacePeekFound.Solution _ -> setAnyProjectContext true @@ -661,17 +660,25 @@ module Project = if lazyLoadWorkspace then //TODO: Register a file open event handler and load the project on demand + let fsFileToProj = Dictionary() + for (proj, compileItems) in projs do + for compileItem in compileItems do + fsFileToProj.[compileItem] <- proj + let openFileHandler (e: TextDocument) = + match tryFindInWorkspace e.uri.path with | Some(ProjectLoadingState.Loaded _) -> () | Some(ProjectLoadingState.Loading _) -> () - | _ -> LanguageService.workspaceLoad [ e.uri.path ] |> ignore - + | _ -> LanguageService.workspaceLoad [ fsFileToProj[e.uri.path] ] |> ignore + // workspace.onDidOpenTextDocument $ (openFileHandler, (), context.subscriptions) |> ignore - workspace.onDidOpenTextDocument.Invoke(unbox openFileHandler)|> context.Subscribe - Promise.lift() + workspace.onDidOpenTextDocument.Invoke(unbox openFileHandler) + |> context.Subscribe + + Promise.lift () else - projs |> List.ofArray |> LanguageService.workspaceLoad |> Promise.map ignore + projs |> Array.map(fun (p, _) -> p) |> List.ofArray |> LanguageService.workspaceLoad |> Promise.map ignore let initWorkspace (context: ExtensionContext) =