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
24import Development.IDE.Types.Options (IdeOptions(..))
26import Development.IDE.Core.Debouncer
27import Development.IDE.Core.FileStore (VFSHandle, fileStoreRules)
28import Development.IDE.Core.FileExists (fileExistsRules)
29import Development.IDE.Core.OfInterest
30import Development.IDE.Types.Logger
31import Development.Shake
32import Data.Either.Extra
33import qualified Language.Haskell.LSP.Messages as LSP
34import qualified Language.Haskell.LSP.Types as LSP
35import qualified Language.Haskell.LSP.Types.Capabilities as LSP
37import Development.IDE.Core.Shake
41newtype GlobalIdeOptions = GlobalIdeOptions IdeOptions
42instance IsIdeGlobal GlobalIdeOptions
44------------------------------------------------------------
47-- | Initialise the Compiler Service.
48initialise :: LSP.ClientCapabilities
51 -> (LSP.FromServerMessage -> IO ())
53 -> Debouncer LSP.NormalizedUri
57initialise caps mainRule getLspId toDiags logger debouncer options vfs =
63 (optShakeProfiling options)
64 (optReportProgress options)
66 { shakeThreads = optThreads options
67 , shakeFiles = fromMaybe "/dev/null" (optShakeFiles options)
69 addIdeGlobal $ GlobalIdeOptions options
72 fileExistsRules getLspId caps vfs
75writeProfile :: IdeState -> FilePath -> IO ()
76writeProfile = shakeProfile
78-- | Shutdown the Compiler Service.
79shutdown :: IdeState -> IO ()
82-- This will return as soon as the result of the action is
83-- available. There might still be other rules running at this point,
84-- e.g., the ofInterestRule.
85runAction :: IdeState -> Action a -> IO a
86runAction ide action = do
88 res <- shakeRun ide [do v <- action; liftIO $ signalBarrier bar v; return v]
89 -- shakeRun might throw an exception (either through action or a default rule),
90 -- in which case action may not complete successfully, and signalBarrier might not be called.
91 -- Therefore we wait for either res (which propagates the exception) or the barrier.
92 -- Importantly, if the barrier does finish, cancelling res only kills waiting for the result,
93 -- it doesn't kill the actual work
94 fmap fromEither $ race (head <$> res) $ waitBarrier bar
97-- | `runActionSync` is similar to `runAction` but it will
98-- wait for all rules (so in particular the `ofInterestRule`) to
99-- finish running. This is mainly useful in tests, where you want
100-- to wait for all rules to fire so you can check diagnostics.
101runActionSync :: IdeState -> Action a -> IO a
102runActionSync s act = fmap head $ join $ shakeRun s [act]
104getIdeOptions :: Action IdeOptions
106 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