Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A Shake implementation of the compiler service.
There are two primary locations where data lives, and both of these contain much the same data:
- The Shake database (inside
$sel:shakeDb:IdeState
) stores a map of shake keys to shake values. In our case, these are all of typeQ
toA
. During a single run all the values in the Shake database are consistent so are used in conjunction with each other, e.g. inuses
. - The
Values
type stores a map of keys to values. These values are always stored as real Haskell values, whereas Shake serialises allA
values between runs. To deserialise a Shake value, we just consult Values.
Synopsis
- data IdeState
- shakeSessionInit :: Recorder (WithPriority Log) -> IdeState -> IO ()
- $sel:shakeExtras:IdeState :: IdeState -> ShakeExtras
- $sel:shakeDb:IdeState :: IdeState -> ShakeDatabase
- data ShakeExtras = ShakeExtras {
- lspEnv :: Maybe (LanguageContextEnv Config)
- debouncer :: Debouncer NormalizedUri
- logger :: Logger
- idePlugins :: IdePlugins IdeState
- globals :: TVar (HashMap TypeRep Dynamic)
- state :: Values
- diagnostics :: STMDiagnosticStore
- hiddenDiagnostics :: STMDiagnosticStore
- publishedDiagnostics :: Map NormalizedUri [Diagnostic]
- positionMapping :: Map NormalizedUri (EnumMap Int32 (PositionDelta, PositionMapping))
- progress :: ProgressReporting
- ideTesting :: IdeTesting
- restartShakeSession :: VFSModified -> String -> [DelayedAction ()] -> IO ()
- ideNc :: IORef NameCache
- knownTargetsVar :: TVar (Hashed KnownTargets)
- exportsMap :: TVar ExportsMap
- actionQueue :: ActionQueue
- clientCapabilities :: ClientCapabilities
- withHieDb :: WithHieDb
- hiedbWriter :: HieDbWriter
- persistentKeys :: TVar (KeyMap GetStalePersistent)
- vfsVar :: TVar VFS
- defaultConfig :: Config
- dirtyKeys :: TVar KeySet
- getShakeExtras :: Action ShakeExtras
- getShakeExtrasRules :: Rules ShakeExtras
- type KnownTargets = HashMap Target (HashSet NormalizedFilePath)
- data Target
- toKnownFiles :: KnownTargets -> HashSet NormalizedFilePath
- type IdeRule k v = (RuleResult k ~ v, ShakeValue k, Show v, Typeable v, NFData v)
- type IdeResult v = ([FileDiagnostic], Maybe v)
- newtype GetModificationTime where
- GetModificationTime_ { }
- pattern GetModificationTime :: GetModificationTime
- shakeOpen :: Recorder (WithPriority Log) -> Maybe (LanguageContextEnv Config) -> Config -> IdePlugins IdeState -> Logger -> Debouncer NormalizedUri -> Maybe FilePath -> IdeReportProgress -> IdeTesting -> WithHieDb -> IndexQueue -> ShakeOptions -> Monitoring -> Rules () -> IO IdeState
- shakeShut :: IdeState -> IO ()
- shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a)
- newSession :: Recorder (WithPriority Log) -> ShakeExtras -> VFSModified -> ShakeDatabase -> [DelayedActionInternal] -> String -> IO ShakeSession
- use :: IdeRule k v => k -> NormalizedFilePath -> Action (Maybe v)
- useNoFile :: IdeRule k v => k -> Action (Maybe v)
- uses :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (Maybe v))
- useWithStaleFast :: IdeRule k v => k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping))
- useWithStaleFast' :: IdeRule k v => k -> NormalizedFilePath -> IdeAction (FastResult v)
- delayedAction :: DelayedAction a -> IdeAction (IO a)
- data FastResult a = FastResult {}
- use_ :: IdeRule k v => k -> NormalizedFilePath -> Action v
- useNoFile_ :: IdeRule k v => k -> Action v
- uses_ :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f v)
- useWithStale :: IdeRule k v => k -> NormalizedFilePath -> Action (Maybe (v, PositionMapping))
- usesWithStale :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (Maybe (v, PositionMapping)))
- useWithStale_ :: IdeRule k v => k -> NormalizedFilePath -> Action (v, PositionMapping)
- usesWithStale_ :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (v, PositionMapping))
- newtype BadDependency = BadDependency String
- data RuleBody k v
- = Rule (k -> NormalizedFilePath -> Action (Maybe ByteString, IdeResult v))
- | RuleNoDiagnostics (k -> NormalizedFilePath -> Action (Maybe ByteString, Maybe v))
- | RuleWithCustomNewnessCheck {
- newnessCheck :: ByteString -> ByteString -> Bool
- build :: k -> NormalizedFilePath -> Action (Maybe ByteString, Maybe v)
- | RuleWithOldValue (k -> NormalizedFilePath -> Value v -> Action (Maybe ByteString, IdeResult v))
- define :: IdeRule k v => Recorder (WithPriority Log) -> (k -> NormalizedFilePath -> Action (IdeResult v)) -> Rules ()
- defineNoDiagnostics :: IdeRule k v => Recorder (WithPriority Log) -> (k -> NormalizedFilePath -> Action (Maybe v)) -> Rules ()
- defineEarlyCutoff :: IdeRule k v => Recorder (WithPriority Log) -> RuleBody k v -> Rules ()
- defineNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action v) -> Rules ()
- defineEarlyCutOffNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action (ByteString, v)) -> Rules ()
- getDiagnostics :: IdeState -> STM [FileDiagnostic]
- mRunLspT :: Applicative m => Maybe (LanguageContextEnv c) -> LspT c m () -> m ()
- mRunLspTCallback :: Monad m => Maybe (LanguageContextEnv c) -> (LspT c m a -> LspT c m a) -> m a -> m a
- getHiddenDiagnostics :: IdeState -> STM [FileDiagnostic]
- class Typeable a => IsIdeGlobal a
- addIdeGlobal :: IsIdeGlobal a => a -> Rules ()
- addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO ()
- getIdeGlobalState :: forall a. IsIdeGlobal a => IdeState -> IO a
- getIdeGlobalAction :: forall a. (HasCallStack, IsIdeGlobal a) => Action a
- getIdeGlobalExtras :: forall a. (HasCallStack, IsIdeGlobal a) => ShakeExtras -> IO a
- getIdeOptions :: Action IdeOptions
- getIdeOptionsIO :: ShakeExtras -> IO IdeOptions
- newtype GlobalIdeOptions = GlobalIdeOptions IdeOptions
- getClientConfig :: MonadLsp Config m => m Config
- getPluginConfigAction :: PluginId -> Action PluginConfig
- knownTargets :: Action (Hashed KnownTargets)
- setPriority :: Priority -> Action ()
- ideLogger :: IdeState -> Logger
- actionLogger :: Action Logger
- getVirtualFile :: NormalizedFilePath -> Action (Maybe VirtualFile)
- data FileVersion
- newtype Priority = Priority Double
- updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> [TextDocumentContentChangeEvent] -> STM ()
- deleteValue :: ShakeValue k => ShakeExtras -> k -> NormalizedFilePath -> STM ()
- recordDirtyKeys :: ShakeValue k => ShakeExtras -> k -> [NormalizedFilePath] -> STM (IO ())
- type WithProgressFunc = forall a. Text -> ProgressCancellable -> ((ProgressAmount -> IO ()) -> IO a) -> IO a
- type WithIndefiniteProgressFunc = forall a. Text -> ProgressCancellable -> IO a -> IO a
- data ProgressEvent
- data DelayedAction a
- mkDelayedAction :: String -> Priority -> Action a -> DelayedAction a
- newtype IdeAction a = IdeAction {}
- runIdeAction :: String -> ShakeExtras -> IdeAction a -> IO a
- mkUpdater :: IORef NameCache -> NameCacheUpdater
- newtype Q k = Q (k, NormalizedFilePath)
- type IndexQueue = TQueue (((HieDb -> IO ()) -> IO ()) -> IO ())
- data HieDb
- data HieDbWriter = HieDbWriter {}
- addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v, PositionDelta, Maybe Int32))) -> Rules ()
- garbageCollectDirtyKeys :: Action [Key]
- garbageCollectDirtyKeysOlderThan :: Int -> CheckParents -> Action [Key]
- data Log
- = LogCreateHieDbExportsMapStart
- | LogCreateHieDbExportsMapFinish !Int
- | LogBuildSessionRestart !String ![DelayedActionInternal] !KeySet !Seconds !(Maybe FilePath)
- | LogBuildSessionRestartTakingTooLong !Seconds
- | LogDelayedAction !(DelayedAction ()) !Seconds
- | LogBuildSessionFinish !(Maybe SomeException)
- | LogDiagsDiffButNoLspEnv ![FileDiagnostic]
- | LogDefineEarlyCutoffRuleNoDiagHasDiag !FileDiagnostic
- | LogDefineEarlyCutoffRuleCustomNewnessHasDiag !FileDiagnostic
- data VFSModified
- getClientConfigAction :: Action Config
Documentation
A Shake database plus persistent store. Can be thought of as storing
mappings from (FilePath, k)
to RuleResult k
.
Instances
MonadReader (ReactorChan, IdeState) (ServerM c) Source # | |
Defined in Development.IDE.LSP.Server ask :: ServerM c (ReactorChan, IdeState) # local :: ((ReactorChan, IdeState) -> (ReactorChan, IdeState)) -> ServerM c a -> ServerM c a # reader :: ((ReactorChan, IdeState) -> a) -> ServerM c a # |
shakeSessionInit :: Recorder (WithPriority Log) -> IdeState -> IO () Source #
Must be called in the Initialized
handler and only once
data ShakeExtras Source #
ShakeExtras | |
|
Instances
MonadReader ShakeExtras IdeAction Source # | |
Defined in Development.IDE.Core.Shake ask :: IdeAction ShakeExtras # local :: (ShakeExtras -> ShakeExtras) -> IdeAction a -> IdeAction a # reader :: (ShakeExtras -> a) -> IdeAction a # |
type KnownTargets = HashMap Target (HashSet NormalizedFilePath) Source #
A mapping of module name to known files
Instances
Generic Target Source # | |
Show Target Source # | |
NFData Target Source # | |
Defined in Development.IDE.Types.KnownTargets | |
Eq Target Source # | |
Hashable Target Source # | |
Defined in Development.IDE.Types.KnownTargets | |
type Rep Target Source # | |
Defined in Development.IDE.Types.KnownTargets type Rep Target = D1 ('MetaData "Target" "Development.IDE.Types.KnownTargets" "ghcide-2.5.0.0-FXD8of4zg5MGRRhTNvOFwl" 'False) (C1 ('MetaCons "TargetModule" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ModuleName)) :+: C1 ('MetaCons "TargetFile" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NormalizedFilePath))) |
type IdeRule k v = (RuleResult k ~ v, ShakeValue k, Show v, Typeable v, NFData v) Source #
type IdeResult v = ([FileDiagnostic], Maybe v) Source #
The result of an IDE operation. Warnings and errors are in the Diagnostic, and a value is in the Maybe. For operations that throw an error you expect a non-empty list of diagnostics, at least one of which is an error, and a Nothing. For operations that succeed you expect perhaps some warnings and a Just. For operations that depend on other failing operations you may get empty diagnostics and a Nothing, to indicate this phase throws no fresh errors but still failed.
A rule on a file should only return diagnostics for that given file. It should not propagate diagnostic errors through multiple phases.
newtype GetModificationTime Source #
GetModificationTime_ | |
|
pattern GetModificationTime :: GetModificationTime |
Instances
shakeOpen :: Recorder (WithPriority Log) -> Maybe (LanguageContextEnv Config) -> Config -> IdePlugins IdeState -> Logger -> Debouncer NormalizedUri -> Maybe FilePath -> IdeReportProgress -> IdeTesting -> WithHieDb -> IndexQueue -> ShakeOptions -> Monitoring -> Rules () -> IO IdeState Source #
shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a) Source #
Enqueue an action in the existing ShakeSession
.
Returns a computation to block until the action is run, propagating exceptions.
Assumes a ShakeSession
is available.
Appropriate for user actions other than edits.
newSession :: Recorder (WithPriority Log) -> ShakeExtras -> VFSModified -> ShakeDatabase -> [DelayedActionInternal] -> String -> IO ShakeSession Source #
Set up a new ShakeSession
with a set of initial actions
Will crash if there is an existing ShakeSession
running.
use :: IdeRule k v => k -> NormalizedFilePath -> Action (Maybe v) Source #
Request a Rule result if available
uses :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (Maybe v)) Source #
Plural version of use
useWithStaleFast :: IdeRule k v => k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping)) Source #
Lookup value in the database and return with the stale value immediately Will queue an action to refresh the value. Might block the first time the rule runs, but never blocks after that.
useWithStaleFast' :: IdeRule k v => k -> NormalizedFilePath -> IdeAction (FastResult v) Source #
Same as useWithStaleFast but lets you wait for an up to date result
delayedAction :: DelayedAction a -> IdeAction (IO a) Source #
These actions are run asynchronously after the current action is finished running. For example, to trigger a key build after a rule has already finished as is the case with useWithStaleFast
useNoFile_ :: IdeRule k v => k -> Action v Source #
uses_ :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f v) Source #
Plural version of use_
Throws an BadDependency
exception which is caught by the rule system if
none available.
WARNING: Not suitable for PluginHandlers. Use usesE
instead.
useWithStale :: IdeRule k v => k -> NormalizedFilePath -> Action (Maybe (v, PositionMapping)) Source #
Request a Rule result, it not available return the last computed result, if any, which may be stale
usesWithStale :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (Maybe (v, PositionMapping))) Source #
Return the last computed result which might be stale.
useWithStale_ :: IdeRule k v => k -> NormalizedFilePath -> Action (v, PositionMapping) Source #
Request a Rule result, it not available return the last computed result which may be stale.
Throws an BadDependency
exception which is caught by the rule system if
none available.
WARNING: Not suitable for PluginHandlers. Use useWithStaleE
instead.
usesWithStale_ :: (Traversable f, IdeRule k v) => k -> f NormalizedFilePath -> Action (f (v, PositionMapping)) Source #
Plural version of useWithStale_
Throws an BadDependency
exception which is caught by the rule system if
none available.
WARNING: Not suitable for PluginHandlers.
newtype BadDependency Source #
When we depend on something that reported an error, and we fail as a direct result, throw BadDependency which short-circuits the rest of the action
Instances
Exception BadDependency Source # | |
Defined in Development.IDE.Types.Shake | |
Show BadDependency Source # | |
Defined in Development.IDE.Types.Shake showsPrec :: Int -> BadDependency -> ShowS # show :: BadDependency -> String # showList :: [BadDependency] -> ShowS # |
Rule (k -> NormalizedFilePath -> Action (Maybe ByteString, IdeResult v)) | |
RuleNoDiagnostics (k -> NormalizedFilePath -> Action (Maybe ByteString, Maybe v)) | |
RuleWithCustomNewnessCheck | |
| |
RuleWithOldValue (k -> NormalizedFilePath -> Value v -> Action (Maybe ByteString, IdeResult v)) |
define :: IdeRule k v => Recorder (WithPriority Log) -> (k -> NormalizedFilePath -> Action (IdeResult v)) -> Rules () Source #
Define a new Rule without early cutoff
defineNoDiagnostics :: IdeRule k v => Recorder (WithPriority Log) -> (k -> NormalizedFilePath -> Action (Maybe v)) -> Rules () Source #
defineEarlyCutoff :: IdeRule k v => Recorder (WithPriority Log) -> RuleBody k v -> Rules () Source #
Define a new Rule with early cutoff
defineNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action v) -> Rules () Source #
defineEarlyCutOffNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action (ByteString, v)) -> Rules () Source #
getDiagnostics :: IdeState -> STM [FileDiagnostic] Source #
mRunLspT :: Applicative m => Maybe (LanguageContextEnv c) -> LspT c m () -> m () Source #
mRunLspTCallback :: Monad m => Maybe (LanguageContextEnv c) -> (LspT c m a -> LspT c m a) -> m a -> m a Source #
getHiddenDiagnostics :: IdeState -> STM [FileDiagnostic] Source #
class Typeable a => IsIdeGlobal a Source #
Instances
IsIdeGlobal GlobalIdeOptions Source # | |
Defined in Development.IDE.Core.Shake | |
IsIdeGlobal OfInterestVar Source # | |
Defined in Development.IDE.Core.OfInterest | |
IsIdeGlobal CompiledLinkables Source # | |
Defined in Development.IDE.Core.Rules | |
IsIdeGlobal DisplayTHWarning Source # | |
Defined in Development.IDE.Core.Rules |
addIdeGlobal :: IsIdeGlobal a => a -> Rules () Source #
addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO () Source #
getIdeGlobalState :: forall a. IsIdeGlobal a => IdeState -> IO a Source #
getIdeGlobalAction :: forall a. (HasCallStack, IsIdeGlobal a) => Action a Source #
getIdeGlobalExtras :: forall a. (HasCallStack, IsIdeGlobal a) => ShakeExtras -> IO a Source #
newtype GlobalIdeOptions Source #
Instances
IsIdeGlobal GlobalIdeOptions Source # | |
Defined in Development.IDE.Core.Shake |
getClientConfig :: MonadLsp Config m => m Config #
Returns the current client configuration. It is not wise to permanently cache the returned value of this function, as clients can at runtime change their configuration.
knownTargets :: Action (Hashed KnownTargets) Source #
Get all the files in the project
setPriority :: Priority -> Action () Source #
getVirtualFile :: NormalizedFilePath -> Action (Maybe VirtualFile) Source #
Read a virtual file from the current snapshot
data FileVersion Source #
Either the mtime from disk or an LSP version LSP versions always compare as greater than on disk versions
Instances
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> [TextDocumentContentChangeEvent] -> STM () Source #
deleteValue :: ShakeValue k => ShakeExtras -> k -> NormalizedFilePath -> STM () Source #
Delete the value stored for a given ide build key
recordDirtyKeys :: ShakeValue k => ShakeExtras -> k -> [NormalizedFilePath] -> STM (IO ()) Source #
type WithProgressFunc = forall a. Text -> ProgressCancellable -> ((ProgressAmount -> IO ()) -> IO a) -> IO a Source #
type WithIndefiniteProgressFunc = forall a. Text -> ProgressCancellable -> IO a -> IO a Source #
data DelayedAction a Source #
Instances
Functor DelayedAction Source # | |
Defined in Development.IDE.Types.Action fmap :: (a -> b) -> DelayedAction a -> DelayedAction b # (<$) :: a -> DelayedAction b -> DelayedAction a # | |
Show (DelayedAction a) Source # | |
Defined in Development.IDE.Types.Action showsPrec :: Int -> DelayedAction a -> ShowS # show :: DelayedAction a -> String # showList :: [DelayedAction a] -> ShowS # | |
Eq (DelayedAction a) Source # | |
Defined in Development.IDE.Types.Action (==) :: DelayedAction a -> DelayedAction a -> Bool # (/=) :: DelayedAction a -> DelayedAction a -> Bool # | |
Hashable (DelayedAction a) Source # | |
Defined in Development.IDE.Types.Action hashWithSalt :: Int -> DelayedAction a -> Int # hash :: DelayedAction a -> Int # |
mkDelayedAction :: String -> Priority -> Action a -> DelayedAction a Source #
IdeActions are used when we want to return a result immediately, even if it is stale Useful for UI actions like hover, completion where we don't want to block.
Run via runIdeAction
.
Instances
MonadIO IdeAction Source # | |
Defined in Development.IDE.Core.Shake | |
Applicative IdeAction Source # | |
Functor IdeAction Source # | |
Monad IdeAction Source # | |
MonadReader ShakeExtras IdeAction Source # | |
Defined in Development.IDE.Core.Shake ask :: IdeAction ShakeExtras # local :: (ShakeExtras -> ShakeExtras) -> IdeAction a -> IdeAction a # reader :: (ShakeExtras -> a) -> IdeAction a # | |
Semigroup a => Semigroup (IdeAction a) Source # | |
runIdeAction :: String -> ShakeExtras -> IdeAction a -> IO a Source #
Q (k, NormalizedFilePath) |
type IndexQueue = TQueue (((HieDb -> IO ()) -> IO ()) -> IO ()) Source #
Actions to queue up on the index worker thread The inner `(HieDb -> IO ()) -> IO ()` wraps `HieDb -> IO ()` with (currently) retry functionality
data HieDbWriter Source #
We need to serialize writes to the database, so we send any function that needs to write to the database over the channel, where it will be picked up by a worker thread.
HieDbWriter | |
|
addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v, PositionDelta, Maybe Int32))) -> Rules () Source #
Register a function that will be called to get the "stale" result of a rule, possibly from disk
This is called when we don't already have a result, or computing the rule failed.
The result of this function will always be marked as $sel:stale:FastResult
, and a proper
rebuild of the rule will
be queued if the rule hasn't run before.
garbageCollectDirtyKeys :: Action [Key] Source #
Find and release old keys from the state Hashmap For the record, there are other state sources that this process does not release: * diagnostics store (normal, hidden and published) * position mapping store * indexing queue * exports map
garbageCollectDirtyKeysOlderThan :: Int -> CheckParents -> Action [Key] Source #
getClientConfigAction :: Action Config Source #
Returns the client configuration, creating a build dependency. You should always use this function when accessing client configuration from build rules.