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, logInfo, logWarning, logError
22import Control.Concurrent.Extra
23import Control.Monad.Except
24import Development.IDE.Functions.Compile (CompileOpts(..))
25import Development.IDE.State.FileStore
26import qualified Development.IDE.Logger as Logger
29import qualified Data.Set as Set
30import qualified Data.Text as T
31import Development.IDE.Functions.GHCError
32import Development.Shake hiding (Diagnostic, Env, newCache)
33import Development.IDE.Types.LSP as Compiler
35import "ghc-lib-parser" UniqSupply
37import Development.IDE.State.Shake
40-- | Environment threaded through the Shake actions.
42 { envOptions :: CompileOpts
43 -- ^ Compiler options.
44 , envOfInterestVar :: Var (Set FilePath)
45 -- ^ The files of interest.
46 , envUniqSupplyVar :: Var UniqSupply
47 -- ^ The unique supply of names used by the compiler.
49instance IsIdeGlobal Env
52mkEnv :: CompileOpts -> IO Env
54 ofInterestVar <- newVar Set.empty
55 uniqSupplyVar <- mkSplitUniqSupply 'a' >>= newVar
57 { envOptions = options
58 , envOfInterestVar = ofInterestVar
59 , envUniqSupplyVar = uniqSupplyVar
62getDiagnostics :: IdeState -> IO [Diagnostic]
63getDiagnostics = getAllDiagnostics
65unsafeClearDiagnostics :: IdeState -> IO ()
66unsafeClearDiagnostics = unsafeClearAllDiagnostics
69------------------------------------------------------------
72-- | Initialise the Compiler Service.
74 -> Maybe (Event -> IO ())
78initialise mainRule toDiags logger options =
80 (fromMaybe (const $ pure ()) toDiags)
82 (setProfiling options $
83 shakeOptions { shakeThreads = optThreads options
84 , shakeFiles = "/dev/null"
86 addIdeGlobal =<< liftIO (mkEnv options)
90writeProfile :: IdeState -> FilePath -> IO ()
91writeProfile = shakeProfile
93setProfiling :: CompileOpts -> ShakeOptions -> ShakeOptions
94setProfiling opts shakeOpts =
95 maybe shakeOpts (\p -> shakeOpts { shakeReport = [p], shakeTimings = True }) (optShakeProfiling opts)
97-- | Shutdown the Compiler Service.
98shutdown :: IdeState -> IO ()
101-- | Run a single action using the supplied service.
102runAction :: IdeState -> Action a -> IO a
103runAction service action = head <$> runActions service [action]
105-- | Run a list of actions in parallel using the supplied service.
106runActions :: IdeState -> [Action a] -> IO [a]
107runActions x = join . shakeRun x
110-- | Set the files-of-interest which will be built and kept-up-to-date.
111setFilesOfInterest :: IdeState -> Set FilePath -> IO ()
112setFilesOfInterest state files = do
113 Env{..} <- getIdeGlobalState state
114 -- update vars synchronously
115 modifyVar_ envOfInterestVar $ const $ return files
117 -- run shake to update results regarding the files of interest
118 void $ shakeRun state []
120getServiceEnv :: Action Env
121getServiceEnv = getIdeGlobalAction
123logDebug, logInfo, logWarning, logError :: IdeState -> T.Text -> IO ()
124logDebug = shakeLogDebug
125logInfo = shakeLogInfo
126logWarning = shakeLogWarning
127logError = shakeLogError
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