@@ -125,9 +125,8 @@ import Data.Typeable ( Typeable )
125125
126126import System.Directory
127127import GhcMonad
128- import qualified HIE.Bios.Ghc.Api as BIOS
129128import GHC.Generics
130- import GHC ( HscEnv )
129+ import GHC ( HscEnv , runGhcT )
131130import Exception
132131
133132import Haskell.Ide.Engine.Compat
@@ -350,10 +349,10 @@ getDiagnosticProvidersConfig c = Map.fromList [("applyrefact",hlintOn c)
350349type IdeGhcM = GhcT IdeM
351350
352351-- | Run an IdeGhcM with Cradle found from the current directory
353- runIdeGhcM :: IdePlugins -> Maybe ( Core. LspFuncs Config ) -> TVar IdeState -> IdeGhcM a -> IO a
354- runIdeGhcM plugins mlf stateVar f = do
355- env <- IdeEnv <$> pure mlf <*> getProcessID <*> pure plugins
356- flip runReaderT stateVar $ flip runReaderT env $ BIOS. withGhcT f
352+ runIdeGhcM :: Maybe FilePath -> IdePlugins -> Core. LspFuncs Config -> TVar IdeState -> IdeGhcM a -> IO a
353+ runIdeGhcM mlibdir plugins lf stateVar f = do
354+ env <- IdeEnv <$> pure lf <*> getProcessID <*> pure plugins
355+ flip runReaderT stateVar $ flip runReaderT env $ runGhcT mlibdir f
357356
358357-- | A computation that is deferred until the module is cached.
359358-- Note that the module may not typecheck, in which case 'UriCacheFailed' is passed
@@ -363,14 +362,14 @@ type IdeDeferM = FreeT Defer IdeM
363362type IdeM = ReaderT IdeEnv (MultiThreadState IdeState )
364363
365364-- | Run an IdeM
366- runIdeM :: IdePlugins -> Maybe ( Core. LspFuncs Config ) -> TVar IdeState -> IdeM a -> IO a
367- runIdeM plugins mlf stateVar f = do
368- env <- IdeEnv <$> pure mlf <*> getProcessID <*> pure plugins
365+ runIdeM :: IdePlugins -> Core. LspFuncs Config -> TVar IdeState -> IdeM a -> IO a
366+ runIdeM plugins lf stateVar f = do
367+ env <- IdeEnv <$> pure lf <*> getProcessID <*> pure plugins
369368 -- TODO: AZ run a single ReaderT, with a composite R.
370369 flip runReaderT stateVar $ runReaderT f env
371370
372371data IdeEnv = IdeEnv
373- { ideEnvLspFuncs :: Maybe ( Core. LspFuncs Config )
372+ { ideEnvLspFuncs :: Core. LspFuncs Config
374373 -- | The pid of this instance of hie
375374 , ideEnvPidCache :: Int
376375 , idePlugins :: IdePlugins
@@ -390,18 +389,12 @@ instance MonadIde IdeGhcM where
390389 getIdeEnv = lift ask
391390
392391getRootPath :: MonadIde m => m (Maybe FilePath )
393- getRootPath = do
394- mlf <- ideEnvLspFuncs <$> getIdeEnv
395- case mlf of
396- Just lf -> return (Core. rootPath lf)
397- Nothing -> return Nothing
392+ getRootPath = Core. rootPath . ideEnvLspFuncs <$> getIdeEnv
398393
399394getVirtualFile :: (MonadIde m , MonadIO m ) => Uri -> m (Maybe VirtualFile )
400395getVirtualFile uri = do
401- mlf <- ideEnvLspFuncs <$> getIdeEnv
402- case mlf of
403- Just lf -> liftIO $ Core. getVirtualFileFunc lf (toNormalizedUri uri)
404- Nothing -> return Nothing
396+ lf <- ideEnvLspFuncs <$> getIdeEnv
397+ liftIO $ Core. getVirtualFileFunc lf (toNormalizedUri uri)
405398
406399-- | Worker function for persistVirtualFile without monad constraints.
407400--
@@ -413,19 +406,15 @@ persistVirtualFile' lf uri = Core.persistVirtualFileFunc lf (toNormalizedUri uri
413406
414407reverseFileMap :: (MonadIde m , MonadIO m ) => m (FilePath -> FilePath )
415408reverseFileMap = do
416- mlf <- ideEnvLspFuncs <$> getIdeEnv
417- case mlf of
418- Just lf -> liftIO $ Core. reverseFileMapFunc lf
419- Nothing -> return id
409+ lf <- ideEnvLspFuncs <$> getIdeEnv
410+ liftIO $ Core. reverseFileMapFunc lf
420411
421412-- | Get the location of the virtual file persisted to the file system associated
422413-- to the given Uri.
423414getPersistedFile :: (MonadIde m , MonadIO m ) => Uri -> m (Maybe FilePath )
424415getPersistedFile uri = do
425- mlf <- ideEnvLspFuncs <$> getIdeEnv
426- case mlf of
427- Just lf -> liftIO $ persistVirtualFile' lf uri
428- Nothing -> return $ uriToFilePath uri
416+ lf <- ideEnvLspFuncs <$> getIdeEnv
417+ liftIO $ persistVirtualFile' lf uri
429418
430419-- | Execute an action on the temporary file associated to the given FilePath.
431420-- If the file is not in the current Virtual File System, the given action is not executed
@@ -439,17 +428,11 @@ withMappedFile fp m k = do
439428
440429getConfig :: (MonadIde m , MonadIO m ) => m Config
441430getConfig = do
442- mlf <- ideEnvLspFuncs <$> getIdeEnv
443- case mlf of
444- Just lf -> fromMaybe def <$> liftIO (Core. config lf)
445- Nothing -> return def
431+ lf <- ideEnvLspFuncs <$> getIdeEnv
432+ fromMaybe def <$> liftIO (Core. config lf)
446433
447434getClientCapabilities :: MonadIde m => m ClientCapabilities
448- getClientCapabilities = do
449- mlf <- ideEnvLspFuncs <$> getIdeEnv
450- case mlf of
451- Just lf -> return (Core. clientCapabilities lf)
452- Nothing -> return def
435+ getClientCapabilities = Core. clientCapabilities . ideEnvLspFuncs <$> getIdeEnv
453436
454437getPlugins :: MonadIde m => m IdePlugins
455438getPlugins = idePlugins <$> getIdeEnv
@@ -462,10 +445,7 @@ withProgress :: (MonadIde m , MonadIO m, MonadBaseControl IO m)
462445 -> ((Core. Progress -> IO () ) -> m a ) -> m a
463446withProgress t c f = do
464447 lf <- ideEnvLspFuncs <$> getIdeEnv
465- let mWp = Core. withProgress <$> lf
466- case mWp of
467- Nothing -> f (const $ return () )
468- Just wp -> control $ \ run -> wp t c $ \ update -> run (f update)
448+ control $ \ run -> Core. withProgress lf t c $ \ update -> run (f update)
469449
470450
471451-- | 'withIndefiniteProgress' @title cancellable f@ is the same as the 'withProgress' but for tasks
@@ -474,10 +454,7 @@ withIndefiniteProgress :: (MonadIde m, MonadBaseControl IO m)
474454 => T. Text -> Core. ProgressCancellable -> m a -> m a
475455withIndefiniteProgress t c f = do
476456 lf <- ideEnvLspFuncs <$> getIdeEnv
477- let mWp = Core. withIndefiniteProgress <$> lf
478- case mWp of
479- Nothing -> f
480- Just wp -> control $ \ run -> wp t c (run f)
457+ control $ \ run -> Core. withIndefiniteProgress lf t c (run f)
481458
482459data IdeState = IdeState
483460 { moduleCache :: ! GhcModuleCache
0 commit comments