on 855c18e help sign in
ghcide/src/Development/IDE/Core/OfInterest.hs
80 lines 2.7 kB history raw
1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE FlexibleInstances #-}
8-- | A Shake implementation of the compiler service, built
9-- using the "Shaker" abstraction layer for in-memory use.
10--
11module Development.IDE.Core.OfInterest(
12 ofInterestRules,
13 getFilesOfInterest, setFilesOfInterest, modifyFilesOfInterest,
14 ) where
16import Control.Concurrent.Extra
17import Control.Monad.Except
18import Data.Hashable
19import Control.DeepSeq
20import GHC.Generics
21import Data.Typeable
22import qualified Data.ByteString.UTF8 as BS
23import Control.Exception
24import Development.IDE.Types.Location
25import Development.IDE.Types.Logger
26import Data.Set (Set)
27import qualified Data.Set as Set
28import qualified Data.Text as T
29import Data.Tuple.Extra
30import Development.Shake
32import Development.IDE.Core.Shake
36newtype OfInterestVar = OfInterestVar (Var (Set NormalizedFilePath))
37instance IsIdeGlobal OfInterestVar
40type instance RuleResult GetFilesOfInterest = Set NormalizedFilePath
43data GetFilesOfInterest = GetFilesOfInterest
44 deriving (Eq, Show, Typeable, Generic)
45instance Hashable GetFilesOfInterest
46instance NFData GetFilesOfInterest
49ofInterestRules :: Rules ()
50ofInterestRules = do
51 addIdeGlobal . OfInterestVar =<< liftIO (newVar Set.empty)
52 defineEarlyCutoff $ \GetFilesOfInterest _file -> assert (null $ fromNormalizedFilePath _file) $ do
53 alwaysRerun
54 filesOfInterest <- getFilesOfInterestUntracked
55 pure (Just $ BS.fromString $ show filesOfInterest, ([], Just filesOfInterest))
58getFilesOfInterest :: Action (Set NormalizedFilePath)
59getFilesOfInterest = useNoFile_ GetFilesOfInterest
63------------------------------------------------------------
64-- Exposed API
66-- | Set the files-of-interest which will be built and kept-up-to-date.
67setFilesOfInterest :: IdeState -> Set NormalizedFilePath -> IO ()
68setFilesOfInterest state files = modifyFilesOfInterest state (const files)
70getFilesOfInterestUntracked :: Action (Set NormalizedFilePath)
71getFilesOfInterestUntracked = do
72 OfInterestVar var <- getIdeGlobalAction
73 liftIO $ readVar var
75modifyFilesOfInterest :: IdeState -> (Set NormalizedFilePath -> Set NormalizedFilePath) -> IO ()
76modifyFilesOfInterest state f = do
77 OfInterestVar var <- getIdeGlobalState state
78 files <- modifyVar var $ pure . dupe . f
79 logDebug (ideLogger state) $ "Set files of interest to: " <> T.pack (show $ Set.toList files)
80 void $ shakeRun state []