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,
16 setFilesOfInterest, modifyFilesOfInterest,
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
28import qualified Data.Set as Set
29import qualified Data.Text as T
30import Data.Tuple.Extra
31import Development.IDE.Functions.GHCError
32import Development.IDE.Types.Diagnostics (NormalizedFilePath)
33import Development.Shake hiding (Diagnostic, Env, newCache)
34import qualified Language.Haskell.LSP.Messages as LSP
38import Development.IDE.State.Shake
41-- | Environment threaded through the Shake actions.
43 { envOptions :: IdeOptions
44 -- ^ Compiler options.
45 , envOfInterestVar :: Var (Set NormalizedFilePath)
46 -- ^ The files of interest.
47 , envUniqSupplyVar :: Var UniqSupply
48 -- ^ The unique supply of names used by the compiler.
50instance IsIdeGlobal Env
53mkEnv :: IdeOptions -> IO Env
55 ofInterestVar <- newVar Set.empty
56 uniqSupplyVar <- mkSplitUniqSupply 'a' >>= newVar
58 { envOptions = options
59 , envOfInterestVar = ofInterestVar
60 , envUniqSupplyVar = uniqSupplyVar
63getDiagnostics :: IdeState -> IO [FileDiagnostic]
64getDiagnostics = getAllDiagnostics
66unsafeClearDiagnostics :: IdeState -> IO ()
67unsafeClearDiagnostics = unsafeClearAllDiagnostics
70------------------------------------------------------------
73-- | Initialise the Compiler Service.
75 -> (LSP.FromServerMessage -> IO ())
80initialise mainRule toDiags logger options vfs =
84 (setProfiling options $
85 shakeOptions { shakeThreads = optThreads options
86 , shakeFiles = "/dev/null"
88 addIdeGlobal =<< liftIO (mkEnv options)
92writeProfile :: IdeState -> FilePath -> IO ()
93writeProfile = shakeProfile
95setProfiling :: IdeOptions -> ShakeOptions -> ShakeOptions
96setProfiling opts shakeOpts =
97 maybe shakeOpts (\p -> shakeOpts { shakeReport = [p], shakeTimings = True }) (optShakeProfiling opts)
99-- | Shutdown the Compiler Service.
100shutdown :: IdeState -> IO ()
103-- | Run a single action using the supplied service.
104runAction :: IdeState -> Action a -> IO a
105runAction service action = head <$> runActions service [action]
107-- | Run a list of actions in parallel using the supplied service.
108runActions :: IdeState -> [Action a] -> IO [a]
109runActions x = join . shakeRun x
112-- | Set the files-of-interest which will be built and kept-up-to-date.
113setFilesOfInterest :: IdeState -> Set NormalizedFilePath -> IO ()
114setFilesOfInterest state files = modifyFilesOfInterest state (const files)
116modifyFilesOfInterest :: IdeState -> (Set NormalizedFilePath -> Set NormalizedFilePath) -> IO ()
117modifyFilesOfInterest state f = do
118 Env{..} <- getIdeGlobalState state
119 files <- modifyVar envOfInterestVar $ pure . dupe . f
120 logDebug state $ "Set files of interest to: " <> T.pack (show $ Set.toList files)
121 void $ shakeRun state []
123getServiceEnv :: Action Env
124getServiceEnv = 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