@@ -344,9 +344,9 @@ getDiagnosticProvidersConfig c = Map.fromList [("applyrefact",hlintOn c)
344344type IdeGhcM = GhcT IdeM
345345
346346-- | Run an IdeGhcM with Cradle found from the current directory
347- runIdeGhcM :: Maybe FilePath -> IdePlugins -> Maybe ( Core. LspFuncs Config ) -> TVar IdeState -> IdeGhcM a -> IO a
348- runIdeGhcM mlibdir plugins mlf stateVar f = do
349- env <- IdeEnv <$> pure mlf <*> getProcessID <*> pure plugins
347+ runIdeGhcM :: Maybe FilePath -> IdePlugins -> Core. LspFuncs Config -> TVar IdeState -> IdeGhcM a -> IO a
348+ runIdeGhcM mlibdir plugins lf stateVar f = do
349+ env <- IdeEnv <$> pure lf <*> getProcessID <*> pure plugins
350350 flip runReaderT stateVar $ flip runReaderT env $ runGhcT mlibdir f
351351
352352-- | A computation that is deferred until the module is cached.
@@ -357,14 +357,14 @@ type IdeDeferM = FreeT Defer IdeM
357357type IdeM = ReaderT IdeEnv (MultiThreadState IdeState )
358358
359359-- | Run an IdeM
360- runIdeM :: IdePlugins -> Maybe ( Core. LspFuncs Config ) -> TVar IdeState -> IdeM a -> IO a
361- runIdeM plugins mlf stateVar f = do
362- env <- IdeEnv <$> pure mlf <*> getProcessID <*> pure plugins
360+ runIdeM :: IdePlugins -> Core. LspFuncs Config -> TVar IdeState -> IdeM a -> IO a
361+ runIdeM plugins lf stateVar f = do
362+ env <- IdeEnv <$> pure lf <*> getProcessID <*> pure plugins
363363 -- TODO: AZ run a single ReaderT, with a composite R.
364364 flip runReaderT stateVar $ runReaderT f env
365365
366366data IdeEnv = IdeEnv
367- { ideEnvLspFuncs :: Maybe ( Core. LspFuncs Config )
367+ { ideEnvLspFuncs :: Core. LspFuncs Config
368368 -- | The pid of this instance of hie
369369 , ideEnvPidCache :: Int
370370 , idePlugins :: IdePlugins
@@ -384,18 +384,12 @@ instance MonadIde IdeGhcM where
384384 getIdeEnv = lift ask
385385
386386getRootPath :: MonadIde m => m (Maybe FilePath )
387- getRootPath = do
388- mlf <- ideEnvLspFuncs <$> getIdeEnv
389- case mlf of
390- Just lf -> return (Core. rootPath lf)
391- Nothing -> return Nothing
387+ getRootPath = Core. rootPath . ideEnvLspFuncs <$> getIdeEnv
392388
393389getVirtualFile :: (MonadIde m , MonadIO m ) => Uri -> m (Maybe VirtualFile )
394390getVirtualFile uri = do
395- mlf <- ideEnvLspFuncs <$> getIdeEnv
396- case mlf of
397- Just lf -> liftIO $ Core. getVirtualFileFunc lf (toNormalizedUri uri)
398- Nothing -> return Nothing
391+ lf <- ideEnvLspFuncs <$> getIdeEnv
392+ liftIO $ Core. getVirtualFileFunc lf (toNormalizedUri uri)
399393
400394-- | Worker function for persistVirtualFile without monad constraints.
401395--
@@ -407,19 +401,15 @@ persistVirtualFile' lf uri = Core.persistVirtualFileFunc lf (toNormalizedUri uri
407401
408402reverseFileMap :: (MonadIde m , MonadIO m ) => m (FilePath -> FilePath )
409403reverseFileMap = do
410- mlf <- ideEnvLspFuncs <$> getIdeEnv
411- case mlf of
412- Just lf -> liftIO $ Core. reverseFileMapFunc lf
413- Nothing -> return id
404+ lf <- ideEnvLspFuncs <$> getIdeEnv
405+ liftIO $ Core. reverseFileMapFunc lf
414406
415407-- | Get the location of the virtual file persisted to the file system associated
416408-- to the given Uri.
417409getPersistedFile :: (MonadIde m , MonadIO m ) => Uri -> m (Maybe FilePath )
418410getPersistedFile uri = do
419- mlf <- ideEnvLspFuncs <$> getIdeEnv
420- case mlf of
421- Just lf -> liftIO $ persistVirtualFile' lf uri
422- Nothing -> return $ uriToFilePath uri
411+ lf <- ideEnvLspFuncs <$> getIdeEnv
412+ liftIO $ persistVirtualFile' lf uri
423413
424414-- | Execute an action on the temporary file associated to the given FilePath.
425415-- If the file is not in the current Virtual File System, the given action is not executed
@@ -433,17 +423,11 @@ withMappedFile fp m k = do
433423
434424getConfig :: (MonadIde m , MonadIO m ) => m Config
435425getConfig = do
436- mlf <- ideEnvLspFuncs <$> getIdeEnv
437- case mlf of
438- Just lf -> fromMaybe def <$> liftIO (Core. config lf)
439- Nothing -> return def
426+ lf <- ideEnvLspFuncs <$> getIdeEnv
427+ fromMaybe def <$> liftIO (Core. config lf)
440428
441429getClientCapabilities :: MonadIde m => m ClientCapabilities
442- getClientCapabilities = do
443- mlf <- ideEnvLspFuncs <$> getIdeEnv
444- case mlf of
445- Just lf -> return (Core. clientCapabilities lf)
446- Nothing -> return def
430+ getClientCapabilities = Core. clientCapabilities . ideEnvLspFuncs <$> getIdeEnv
447431
448432getPlugins :: MonadIde m => m IdePlugins
449433getPlugins = idePlugins <$> getIdeEnv
@@ -456,10 +440,7 @@ withProgress :: (MonadIde m , MonadIO m, MonadBaseControl IO m)
456440 -> ((Core. Progress -> IO () ) -> m a ) -> m a
457441withProgress t c f = do
458442 lf <- ideEnvLspFuncs <$> getIdeEnv
459- let mWp = Core. withProgress <$> lf
460- case mWp of
461- Nothing -> f (const $ return () )
462- Just wp -> control $ \ run -> wp t c $ \ update -> run (f update)
443+ control $ \ run -> Core. withProgress lf t c $ \ update -> run (f update)
463444
464445
465446-- | 'withIndefiniteProgress' @title cancellable f@ is the same as the 'withProgress' but for tasks
@@ -468,10 +449,7 @@ withIndefiniteProgress :: (MonadIde m, MonadBaseControl IO m)
468449 => T. Text -> Core. ProgressCancellable -> m a -> m a
469450withIndefiniteProgress t c f = do
470451 lf <- ideEnvLspFuncs <$> getIdeEnv
471- let mWp = Core. withIndefiniteProgress <$> lf
472- case mWp of
473- Nothing -> f
474- Just wp -> control $ \ run -> wp t c (run f)
452+ control $ \ run -> Core. withIndefiniteProgress lf t c (run f)
475453
476454data IdeState = IdeState
477455 { moduleCache :: ! GhcModuleCache
0 commit comments