Skip to content

Commit e95ca9e

Browse files
committed
add an option to control progress reporting
1 parent e16833e commit e95ca9e

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

ghcide/src/Development/IDE/Core/FileExists.hs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ where
1313
import Control.Concurrent.Extra
1414
import Control.Exception
1515
import Control.Monad.Extra
16-
import Data.Binary
1716
import qualified Data.ByteString as BS
1817
import Data.HashMap.Strict (HashMap)
1918
import qualified Data.HashMap.Strict as HashMap
2019
import Data.Maybe
2120
import Development.IDE.Core.FileStore
2221
import Development.IDE.Core.IdeConfiguration
22+
import Development.IDE.Core.RuleTypes
2323
import Development.IDE.Core.Shake
2424
import Development.IDE.Types.Location
2525
import Development.IDE.Types.Options
2626
import Development.Shake
27-
import Development.Shake.Classes
28-
import GHC.Generics
2927
import Language.LSP.Server hiding (getVirtualFile)
3028
import Language.LSP.Types
3129
import Language.LSP.Types.Capabilities
@@ -112,15 +110,6 @@ fromChange FcChanged = Nothing
112110

113111
-------------------------------------------------------------------------------------
114112

115-
type instance RuleResult GetFileExists = Bool
116-
117-
data GetFileExists = GetFileExists
118-
deriving (Eq, Show, Typeable, Generic)
119-
120-
instance NFData GetFileExists
121-
instance Hashable GetFileExists
122-
instance Binary GetFileExists
123-
124113
-- | Returns True if the file exists
125114
-- Note that a file is not considered to exist unless it is saved to disk.
126115
-- In particular, VFS existence is not enough.

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Data.Text (Text)
4343
import Development.IDE.Import.FindImports (ArtifactsLocation)
4444
import Development.IDE.Spans.Common
4545
import Development.IDE.Spans.LocalBindings
46-
import Development.IDE.Types.Options (IdeGhcSession)
46+
import Development.IDE.Types.Diagnostics
4747
import Fingerprint
4848
import GHC.Serialized (Serialized)
4949
import Language.LSP.Types (NormalizedFilePath)
@@ -254,6 +254,9 @@ type instance RuleResult GetModIfaceWithoutLinkable = HiFileResult
254254
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
255255
type instance RuleResult GetFileContents = (FileVersion, Maybe Text)
256256

257+
type instance RuleResult GetFileExists = Bool
258+
259+
257260
-- The Shake key type for getModificationTime queries
258261
newtype GetModificationTime = GetModificationTime_
259262
{ missingFileDiagnostics :: Bool
@@ -299,6 +302,12 @@ instance Hashable GetFileContents
299302
instance NFData GetFileContents
300303
instance Binary GetFileContents
301304

305+
data GetFileExists = GetFileExists
306+
deriving (Eq, Show, Typeable, Generic)
307+
308+
instance NFData GetFileExists
309+
instance Hashable GetFileExists
310+
instance Binary GetFileExists
302311

303312
data FileOfInterestStatus
304313
= OnDisk
@@ -478,6 +487,16 @@ type instance RuleResult GetClientSettings = Hashed (Maybe Value)
478487
-- https://github.com/digital-asset/daml/pull/2808#issuecomment-529639547
479488
type instance RuleResult GhcSessionIO = IdeGhcSession
480489

490+
data IdeGhcSession = IdeGhcSession
491+
{ loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
492+
-- ^ Returns the Ghc session and the cradle dependencies
493+
, sessionVersion :: !Int
494+
-- ^ Used as Shake key, versions must be unique and not reused
495+
}
496+
497+
instance Show IdeGhcSession where show _ = "IdeGhcSession"
498+
instance NFData IdeGhcSession where rnf !_ = ()
499+
481500
data GhcSessionIO = GhcSessionIO deriving (Eq, Show, Typeable, Generic)
482501
instance Hashable GhcSessionIO
483502
instance NFData GhcSessionIO

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ defineEarlyCutoff'
939939
-> Action (RunResult (A (RuleResult k)))
940940
defineEarlyCutoff' doDiagnostics key file old mode action = do
941941
extras@ShakeExtras{state, inProgress} <- getShakeExtras
942-
-- don't do progress for GetFileExists, as there are lots of non-nodes for just that one key
943-
(if show key == "GetFileExists" then id else withProgressVar inProgress file) $ do
942+
options <- getIdeOptions
943+
(if optSkipProgress options key then id else withProgressVar inProgress file) $ do
944944
val <- case old of
945945
Just old | mode == RunDependenciesSame -> do
946946
v <- liftIO $ getValues state key file

ghcide/src/Development/IDE/Types/Options.hs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-- SPDX-License-Identifier: Apache-2.0
33

44
-- | Options
5+
{-# LANGUAGE RankNTypes #-}
56
module Development.IDE.Types.Options
67
( IdeOptions(..)
78
, IdePreprocessedSource(..)
@@ -17,27 +18,17 @@ module Development.IDE.Types.Options
1718
, OptHaddockParse(..)
1819
,optShakeFiles) where
1920

20-
import Control.DeepSeq (NFData (..))
2121
import qualified Data.Text as T
22+
import Data.Typeable
23+
import Development.IDE.Core.RuleTypes
2224
import Development.IDE.Types.Diagnostics
23-
import Development.IDE.Types.HscEnvEq (HscEnvEq)
2425
import Development.Shake
2526
import GHC hiding (parseModule,
2627
typecheckModule)
2728
import GhcPlugins as GHC hiding (fst3, (<>))
2829
import Ide.Plugin.Config
2930
import qualified Language.LSP.Types.Capabilities as LSP
3031

31-
data IdeGhcSession = IdeGhcSession
32-
{ loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
33-
-- ^ Returns the Ghc session and the cradle dependencies
34-
, sessionVersion :: !Int
35-
-- ^ Used as Shake key, versions must be unique and not reused
36-
}
37-
38-
instance Show IdeGhcSession where show _ = "IdeGhcSession"
39-
instance NFData IdeGhcSession where rnf !_ = ()
40-
4132
data IdeOptions = IdeOptions
4233
{ optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
4334
-- ^ Preprocessor to run over all parsed source trees, generating a list of warnings
@@ -85,6 +76,8 @@ data IdeOptions = IdeOptions
8576
-- ^ Will be called right after setting up a new cradle,
8677
-- allowing to customize the Ghc options used
8778
, optShakeOptions :: ShakeOptions
79+
, optSkipProgress :: forall a. Typeable a => a -> Bool
80+
-- ^ Predicate to select which rule keys to exclude from progress reporting.
8881
}
8982

9083
optShakeFiles :: IdeOptions -> Maybe FilePath
@@ -137,8 +130,16 @@ defaultIdeOptions session = IdeOptions
137130
,optCheckParents = pure CheckOnSaveAndClose
138131
,optHaddockParse = HaddockParse
139132
,optCustomDynFlags = id
133+
,optSkipProgress = defaultSkipProgress
140134
}
141135

136+
defaultSkipProgress :: Typeable a => a -> Bool
137+
defaultSkipProgress key = case () of
138+
_ | Just GetFileContents <- cast key -> True
139+
_ | Just GetFileExists <- cast key -> True
140+
_ | Just GetModificationTime_{} <- cast key -> True
141+
_ -> False
142+
142143

143144
-- | The set of options used to locate files belonging to external packages.
144145
data IdePkgLocationOptions = IdePkgLocationOptions

0 commit comments

Comments
 (0)