on 0336e41 help sign in
102 lines 3.5 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
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.
10--
11module Development.IDE.Core.Service(
12 getIdeOptions,
13 IdeState, initialise, shutdown,
14 runAction, runActions,
15 runActionSync, runActionsSync,
16 getFilesOfInterest, setFilesOfInterest, modifyFilesOfInterest,
17 writeProfile,
18 getDiagnostics, unsafeClearDiagnostics,
19 ideLogger
20 ) where
22import Control.Concurrent.Extra
23import Control.Monad.Except
24import Development.IDE.Types.Options (IdeOptions(..))
25import Development.IDE.Core.FileStore
26import Development.IDE.Core.OfInterest
27import Development.IDE.Types.Logger
28import Development.Shake hiding (Diagnostic, Env, newCache)
29import qualified Language.Haskell.LSP.Messages as LSP
31import Development.IDE.Core.Shake
35newtype GlobalIdeOptions = GlobalIdeOptions IdeOptions
36instance IsIdeGlobal GlobalIdeOptions
38------------------------------------------------------------
39-- Exposed API
41-- | Initialise the Compiler Service.
42initialise :: Rules ()
43 -> (LSP.FromServerMessage -> IO ())
44 -> Logger
45 -> IdeOptions
46 -> VFSHandle
47 -> IO IdeState
48initialise mainRule toDiags logger options vfs =
49 shakeOpen
50 toDiags
51 logger
52 (setProfiling options $
53 shakeOptions { shakeThreads = optThreads options
54 , shakeFiles = "/dev/null"
55 }) $ do
56 addIdeGlobal $ GlobalIdeOptions options
57 fileStoreRules vfs
58 ofInterestRules
59 mainRule
61writeProfile :: IdeState -> FilePath -> IO ()
62writeProfile = shakeProfile
64setProfiling :: IdeOptions -> ShakeOptions -> ShakeOptions
65setProfiling opts shakeOpts =
66 maybe shakeOpts (\p -> shakeOpts { shakeReport = [p], shakeTimings = True }) (optShakeProfiling opts)
68-- | Shutdown the Compiler Service.
69shutdown :: IdeState -> IO ()
70shutdown = shakeShut
72-- | Run a single action using the supplied service. See `runActions`
73-- for more details.
74runAction :: IdeState -> Action a -> IO a
75runAction service action = head <$> runActions service [action]
77-- | Run a list of actions in parallel using the supplied service.
78-- This will return as soon as the results of the actions are
79-- available. There might still be other rules running at this point,
80-- e.g., the ofInterestRule.
81runActions :: IdeState -> [Action a] -> IO [a]
82runActions x acts = do
83 var <- newBarrier
84 _ <- shakeRun x acts (signalBarrier var)
85 waitBarrier var
87-- | This is a synchronous variant of `runAction`. See
88-- `runActionsSync` of more details.
89runActionSync :: IdeState -> Action a -> IO a
90runActionSync s a = head <$> runActionsSync s [a]
92-- | `runActionsSync` is similar to `runActions` but it will
93-- wait for all rules (so in particular the `ofInterestRule`) to
94-- finish running. This is mainly useful in tests, where you want
95-- to wait for all rules to fire so you can check diagnostics.
96runActionsSync :: IdeState -> [Action a] -> IO [a]
97runActionsSync s acts = join $ shakeRun s acts (const $ pure ())
99getIdeOptions :: Action IdeOptions
100getIdeOptions = do
101 GlobalIdeOptions x <- getIdeGlobalAction
102 return x