Skip to content

Commit b44f328

Browse files
committed
Rename to IdeDurableState
1 parent b1e4b01 commit b44f328

2 files changed

Lines changed: 27 additions & 21 deletions

File tree

src/Language/PureScript/Ide/State.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ import System.Directory (getModificationTime)
6565
resetIdeState :: Ide m => m ()
6666
resetIdeState = do
6767
ideVar <- ideStateVar <$> ask
68-
liftIO (atomically (writeTVar ideVar emptyIdeState))
68+
durableState <- getDurableState
69+
liftIO (atomically (writeTVar ideVar (emptyIdeState { ideDurableState = durableState })))
6970

7071
getOutputDirectory :: Ide m => m FilePath
7172
getOutputDirectory = do
@@ -145,21 +146,21 @@ setVolatileStateSTM ref vs = do
145146
x {ideVolatileState = vs}
146147
pure ()
147148

148-
-- | Retrieves the ModifierState from the State.
149-
getModifierState :: Ide m => m IdeModifierState
150-
getModifierState = do
149+
-- | Retrieves the DurableState from the State.
150+
getDurableState :: Ide m => m IdeDurableState
151+
getDurableState = do
151152
st <- ideStateVar <$> ask
152-
liftIO (atomically (getModifierStateSTM st))
153+
liftIO (atomically (getDurableStateSTM st))
153154

154-
-- | STM version of getModifierState
155-
getModifierStateSTM :: TVar IdeState -> STM IdeModifierState
156-
getModifierStateSTM ref = ideModifierState <$> readTVar ref
155+
-- | STM version of getDurableState
156+
getDurableStateSTM :: TVar IdeState -> STM IdeDurableState
157+
getDurableStateSTM ref = ideDurableState <$> readTVar ref
157158

158-
-- | Sets the ModifierState inside Ide's state
159-
setModifierStateSTM :: TVar IdeState -> IdeModifierState -> STM ()
160-
setModifierStateSTM ref md = do
159+
-- | Sets the DurableState inside Ide's state
160+
setDurableStateSTM :: TVar IdeState -> IdeDurableState -> STM ()
161+
setDurableStateSTM ref md = do
161162
modifyTVar ref $ \x ->
162-
x {ideModifierState = md}
163+
x {ideDurableState = md}
163164
pure ()
164165

165166
-- | Checks if the given ModuleName matches the last rebuild cache and if it
@@ -474,7 +475,7 @@ resolveDataConstructorsForModule decls =
474475

475476
getFocusedModules :: Ide m => m (Set P.ModuleName)
476477
getFocusedModules = do
477-
IdeModifierState{mdFocusedModules = focusedModules} <- getModifierState
478+
IdeDurableState{drFocusedModules = focusedModules} <- getDurableState
478479
pure focusedModules
479480

480481
setFocusedModules :: Ide m => [P.ModuleName] -> m ()
@@ -484,5 +485,4 @@ setFocusedModules modulesToFocus = do
484485

485486
setFocusedModulesSTM :: TVar IdeState -> [P.ModuleName] -> STM ()
486487
setFocusedModulesSTM ref modulesToFocus = do
487-
IdeModifierState{} <- getModifierStateSTM ref
488-
setModifierStateSTM ref (IdeModifierState (Set.fromList modulesToFocus))
488+
setDurableStateSTM ref (IdeDurableState (Set.fromList modulesToFocus))

src/Language/PureScript/Ide/Types.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Data.Aeson qualified as Aeson
1515
import Data.IORef (IORef)
1616
import Data.Time.Clock (UTCTime)
1717
import Data.Map.Lazy qualified as M
18+
import Data.Set qualified as S
1819
import Language.PureScript qualified as P
1920
import Language.PureScript.Errors.JSON qualified as P
2021
import Language.PureScript.Ide.Filter.Declaration (DeclarationType(..))
@@ -178,20 +179,20 @@ type Ide m = (MonadIO m, MonadReader IdeEnvironment m)
178179
data IdeState = IdeState
179180
{ ideFileState :: IdeFileState
180181
, ideVolatileState :: IdeVolatileState
181-
, ideModifierState :: IdeModifierState
182+
, ideDurableState :: IdeDurableState
182183
} deriving (Show)
183184

184185
emptyIdeState :: IdeState
185-
emptyIdeState = IdeState emptyFileState emptyVolatileState emptyModifierState
186+
emptyIdeState = IdeState emptyFileState emptyVolatileState emptyDurableState
186187

187188
emptyFileState :: IdeFileState
188189
emptyFileState = IdeFileState M.empty M.empty
189190

190191
emptyVolatileState :: IdeVolatileState
191192
emptyVolatileState = IdeVolatileState (AstData M.empty) M.empty Nothing
192193

193-
emptyModifierState :: IdeModifierState
194-
emptyModifierState = IdeModifierState mempty
194+
emptyDurableState :: IdeDurableState
195+
emptyDurableState = IdeDurableState S.empty
195196

196197
-- | @IdeFileState@ holds data that corresponds 1-to-1 to an entity on the
197198
-- filesystem. Externs correspond to the ExternsFiles the compiler emits into
@@ -216,8 +217,13 @@ data IdeVolatileState = IdeVolatileState
216217
, vsCachedRebuild :: Maybe (P.ModuleName, P.ExternsFile)
217218
} deriving (Show)
218219

219-
data IdeModifierState = IdeModifierState
220-
{ mdFocusedModules :: Set P.ModuleName
220+
-- | @IdeDurableState@ holds data that persists across resets of the @IdeState@.
221+
-- This is particularly useful for configuration variables that can be modified
222+
-- during runtime. For instance, the module names for the "focus" feature are
223+
-- stored in the drFocusedModules field, which the client populates using the
224+
-- @Focus@ command to specify only which modules to load.
225+
data IdeDurableState = IdeDurableState
226+
{ drFocusedModules :: Set P.ModuleName
221227
} deriving (Show)
222228

223229
newtype Match a = Match (P.ModuleName, a)

0 commit comments

Comments
 (0)