@@ -50,9 +50,6 @@ module Unison.Cli.Monad
5050 runTransactionWithRollback ,
5151 runTransactionWithRollback2 ,
5252
53- -- * Internal
54- setMostRecentProjectPath ,
55-
5653 -- * Misc types
5754 LoadSourceResult (.. ),
5855 )
@@ -169,6 +166,8 @@ data Env = Env
169166 generateUniqueName :: IO Parser. UniqueName ,
170167 -- | How to load source code.
171168 loadSource :: SourceName -> IO LoadSourceResult ,
169+ -- | Notify the LSP that this ProjectPathIds might be different from the last (e.g. on branch update, switch, etc).
170+ lspCheckForChanges :: PP. ProjectPathIds -> IO () ,
172171 -- | How to write source code. Bool = make new fold?
173172 writeSource :: SourceName -> Text -> Bool -> IO () ,
174173 -- | What to do with output for the user.
@@ -388,19 +387,24 @@ getProjectPathIds = do
388387
389388cd :: Path. Absolute -> Cli ()
390389cd path = do
390+ env <- ask
391391 pp <- getProjectPathIds
392392 let newPP = pp & PP. absPath_ .~ path
393- setMostRecentProjectPath newPP
393+ runTransaction ( Codebase. setCurrentProjectPath newPP)
394394 # projectPathStack %= NonEmpty. cons newPP
395+ liftIO (env. lspCheckForChanges newPP)
395396
396397switchProject :: ProjectAndBranch ProjectId ProjectBranchId -> Cli ()
397398switchProject pab@ (ProjectAndBranch projectId branchId) = do
398- Env {codebase} <- ask
399+ env <- ask
399400 let newPP = PP. ProjectPath projectId branchId Path. absoluteEmpty
400401 # projectPathStack %= NonEmpty. cons newPP
401- runTransaction $ do Q. setMostRecentBranch projectId branchId
402- setMostRecentProjectPath newPP
403- liftIO $ Codebase. preloadProjectBranch codebase pab
402+ runTransaction do
403+ Q. setMostRecentBranch projectId branchId
404+ Codebase. setCurrentProjectPath newPP
405+ liftIO do
406+ Codebase. preloadProjectBranch env. codebase pab
407+ env. lspCheckForChanges newPP
404408
405409-- | Pop the latest path off the stack, if it's not the only path in the stack.
406410--
@@ -411,14 +415,13 @@ popd = do
411415 case List.NonEmpty. uncons (projectPathStack state) of
412416 (_, Nothing ) -> pure False
413417 (_, Just paths) -> do
414- setMostRecentProjectPath (List.NonEmpty. head paths)
418+ let path = List.NonEmpty. head paths
419+ runTransaction (Codebase. setCurrentProjectPath path)
415420 State. put state {projectPathStack = paths}
421+ env <- ask
422+ liftIO (env. lspCheckForChanges path)
416423 pure True
417424
418- setMostRecentProjectPath :: PP. ProjectPathIds -> Cli ()
419- setMostRecentProjectPath loc =
420- runTransaction $ Codebase. setCurrentProjectPath loc
421-
422425respond :: Output -> Cli ()
423426respond output = do
424427 Env {notify} <- ask
0 commit comments