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