1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE FlexibleInstances #-}
8-- | A Shake implementation of the compiler service, built
9-- using the "Shaker" abstraction layer for in-memory use.
11module Development.IDE.State.Service(
14 IdeState, initialise, shutdown,
15 runAction, runActions,
18 getDiagnostics, unsafeClearDiagnostics,
19 logDebug, logSeriousError
22import Control.Concurrent.Extra
23import Control.Monad.Except
24import Development.IDE.Types.Options (IdeOptions(..))
25import Development.IDE.State.FileStore
26import qualified Development.IDE.Logger as Logger
29import qualified Data.Set as Set
30import Development.IDE.Functions.GHCError
31import Development.Shake hiding (Diagnostic, Env, newCache)
32import Development.IDE.Types.LSP as Compiler
36import Development.IDE.State.Shake
39-- | Environment threaded through the Shake actions.
41 { envOptions :: IdeOptions
42 -- ^ Compiler options.
43 , envOfInterestVar :: Var (Set FilePath)
44 -- ^ The files of interest.
45 , envUniqSupplyVar :: Var UniqSupply
46 -- ^ The unique supply of names used by the compiler.
48instance IsIdeGlobal Env
51mkEnv :: IdeOptions -> IO Env
53 ofInterestVar <- newVar Set.empty
54 uniqSupplyVar <- mkSplitUniqSupply 'a' >>= newVar
56 { envOptions = options
57 , envOfInterestVar = ofInterestVar
58 , envUniqSupplyVar = uniqSupplyVar
61getDiagnostics :: IdeState -> IO [FileDiagnostic]
62getDiagnostics = getAllDiagnostics
64unsafeClearDiagnostics :: IdeState -> IO ()
65unsafeClearDiagnostics = unsafeClearAllDiagnostics
68------------------------------------------------------------
71-- | Initialise the Compiler Service.
73 -> Maybe (Event -> IO ())
77initialise mainRule toDiags logger options =
79 (fromMaybe (const $ pure ()) toDiags)
81 (setProfiling options $
82 shakeOptions { shakeThreads = optThreads options
83 , shakeFiles = "/dev/null"
85 addIdeGlobal =<< liftIO (mkEnv options)
89writeProfile :: IdeState -> FilePath -> IO ()
90writeProfile = shakeProfile
92setProfiling :: IdeOptions -> ShakeOptions -> ShakeOptions
93setProfiling opts shakeOpts =
94 maybe shakeOpts (\p -> shakeOpts { shakeReport = [p], shakeTimings = True }) (optShakeProfiling opts)
96-- | Shutdown the Compiler Service.
97shutdown :: IdeState -> IO ()
100-- | Run a single action using the supplied service.
101runAction :: IdeState -> Action a -> IO a
102runAction service action = head <$> runActions service [action]
104-- | Run a list of actions in parallel using the supplied service.
105runActions :: IdeState -> [Action a] -> IO [a]
106runActions x = join . shakeRun x
109-- | Set the files-of-interest which will be built and kept-up-to-date.
110setFilesOfInterest :: IdeState -> Set FilePath -> IO ()
111setFilesOfInterest state files = do
112 Env{..} <- getIdeGlobalState state
113 -- update vars synchronously
114 modifyVar_ envOfInterestVar $ const $ return files
116 -- run shake to update results regarding the files of interest
117 void $ shakeRun state []
119getServiceEnv :: Action Env
120getServiceEnv = getIdeGlobalAction
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list