@@ -28,7 +28,7 @@ import Data.ByteString.Char8 qualified as BS8
2828import Data.ByteString.Lazy.Char8 qualified as BSL8
2929import GHC.IO.Exception (IOErrorType (.. ), IOException (.. ))
3030import Language.PureScript.Ide (handleCommand )
31- import Language.PureScript.Ide.Command (Command (.. ), commandName )
31+ import Language.PureScript.Ide.Command (commandName , Command (.. ))
3232import Language.PureScript.Ide.Util (decodeT , displayTimeSpec , encodeT , logPerf , runLogger )
3333import Language.PureScript.Ide.Error (IdeError (.. ))
3434import Language.PureScript.Ide.State (updateCacheTimestamp )
@@ -199,14 +199,22 @@ startServer port env = Network.withSocketsDo $ do
199199 logPerf message $ do
200200 result <- runExceptT $ do
201201 updateCacheTimestamp >>= \ case
202- Nothing -> pure ()
202+ Nothing ->
203+ handleCommand cmd'
203204 Just (before, after) -> do
204205 -- If the cache db file was changed outside of the IDE
205206 -- we trigger a reset before processing the command
206207 $ (logInfo) (" cachedb was changed from: " <> show before <> " , to: " <> show after)
207- unless (isLoadAll cmd') $
208- void (handleCommand Reset *> handleCommand (LoadSync [] ))
209- handleCommand cmd'
208+ let doReload = handleCommand Reset *> handleCommand (LoadSync [] )
209+ case cmd' of
210+ -- handleCommand on Load [] already resets the state.
211+ Load [] -> handleCommand cmd'
212+ -- Focus needs to fire before doReload, because we
213+ -- want to set the focused modules first before
214+ -- loading everything with LoadSync [].
215+ Focus _ -> handleCommand cmd' <* doReload
216+ -- Otherwise, just doReload and then handle.
217+ _ -> doReload *> handleCommand cmd'
210218 liftIO $ catchGoneHandle $ BSL8. hPutStrLn h $ case result of
211219 Right r -> Aeson. encode r
212220 Left err -> Aeson. encode err
@@ -219,11 +227,6 @@ startServer port env = Network.withSocketsDo $ do
219227 hFlush stdout
220228 liftIO $ catchGoneHandle (hClose h)
221229
222- isLoadAll :: Command -> Bool
223- isLoadAll = \ case
224- Load [] -> True
225- _ -> False
226-
227230catchGoneHandle :: IO () -> IO ()
228231catchGoneHandle =
229232 handle (\ e -> case e of
0 commit comments