1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE FlexibleInstances #-}
7-- | A Shake implementation of the compiler service, built
8-- using the "Shaker" abstraction layer for in-memory use.
10module Development.IDE.Core.Service(
12 IdeState, initialise, shutdown,
16 getDiagnostics, unsafeClearDiagnostics,
18 updatePositionMapping,
21import Control.Concurrent.Extra
22import Control.Concurrent.Async
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
29import Data.Either.Extra
30import qualified Language.Haskell.LSP.Messages as LSP
32import Development.IDE.Core.Shake
36newtype GlobalIdeOptions = GlobalIdeOptions IdeOptions
37instance IsIdeGlobal GlobalIdeOptions
39------------------------------------------------------------
42-- | Initialise the Compiler Service.
44 -> (LSP.FromServerMessage -> IO ())
49initialise mainRule toDiags logger options vfs =
53 (optShakeProfiling options)
54 (optReportProgress options)
55 (shakeOptions { shakeThreads = optThreads options
56 , shakeFiles = "/dev/null"
58 addIdeGlobal $ GlobalIdeOptions options
63writeProfile :: IdeState -> FilePath -> IO ()
64writeProfile = shakeProfile
66-- | Shutdown the Compiler Service.
67shutdown :: IdeState -> IO ()
70-- This will return as soon as the result of the action is
71-- available. There might still be other rules running at this point,
72-- e.g., the ofInterestRule.
73runAction :: IdeState -> Action a -> IO a
74runAction ide action = do
76 res <- shakeRun ide [do v <- action; liftIO $ signalBarrier bar v; return v]
77 -- shakeRun might throw an exception (either through action or a default rule),
78 -- in which case action may not complete successfully, and signalBarrier might not be called.
79 -- Therefore we wait for either res (which propagates the exception) or the barrier.
80 -- Importantly, if the barrier does finish, cancelling res only kills waiting for the result,
81 -- it doesn't kill the actual work
82 fmap fromEither $ race (head <$> res) $ waitBarrier bar
85-- | `runActionSync` is similar to `runAction` but it will
86-- wait for all rules (so in particular the `ofInterestRule`) to
87-- finish running. This is mainly useful in tests, where you want
88-- to wait for all rules to fire so you can check diagnostics.
89runActionSync :: IdeState -> Action a -> IO a
90runActionSync s act = fmap head $ join $ shakeRun s [act]
92getIdeOptions :: Action IdeOptions
94 GlobalIdeOptions x <- 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