generated from srid/ema-template
/
Source.hs
38 lines (35 loc) · 1.2 KB
/
Source.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE TypeApplications #-}
-- | Emanote.Source is responsible for managing the source files and its
-- changes, and communicating them to `Emanote.Model`.
module Emanote.Source
( emanate,
)
where
import Control.Monad.Logger (MonadLogger)
import Data.LVar (LVar)
import qualified Data.LVar as LVar
import qualified Ema.Helper.FileSystem as EmaFS
import Emanote.Model (Model)
import Emanote.Prelude (log)
import Emanote.Source.Loc
import Emanote.Source.Patch (transformActions)
import Emanote.Source.Pattern (filePatterns, ignorePatterns)
import Relude
import UnliftIO (MonadUnliftIO)
-- | Emanate on-disk sources onto an in-memory `Model` (stored in a LVar)
emanate :: (MonadUnliftIO m, MonadLogger m) => NonEmpty FilePath -> LVar Model -> Model -> m ()
emanate paths modelLvar initialModel = do
defaultLayer <- liftIO emanoteDefaultLayer
let layers = one defaultLayer <> userLayers paths
mcmd <-
EmaFS.unionMountOnLVar
layers
filePatterns
ignorePatterns
modelLvar
initialModel
transformActions
whenJust mcmd $ \EmaFS.Cmd_Remount -> do
log "!! Remount suggested !!"
LVar.set modelLvar initialModel -- Reset the model
emanate paths modelLvar initialModel