ghcide-2.4.0.0: The core of an IDE

Safe Haskell | Safe-Inferred
Language | Haskell2010

Development.IDE.Core.Rules

Contents

- Types
- Functions
- Rules

Description

A Shake implementation of the compiler service, built using the Shaker abstraction layer for in-memory use.

Synopsis

- data IdeState
- data GetParsedModule = GetParsedModule
- newtype TransitiveDependencies = TransitiveDependencies {
  - transitiveModuleDeps :: [NormalizedFilePath]
  }
- newtype Priority = Priority Double
- data GhcSessionIO = GhcSessionIO
- data GetClientSettings = GetClientSettings
- priorityTypeCheck :: Priority
- priorityGenerateCore :: Priority
- priorityFilesOfInterest :: Priority
- runAction :: String -> IdeState -> Action a -> IO a
- toIdeResult :: Either [FileDiagnostic] v -> IdeResult v
- defineNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action v) -> Rules ()
- defineEarlyCutOffNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action (ByteString, v)) -> Rules ()
- mainRule :: Recorder (WithPriority Log) -> RulesConfig -> Rules ()
- data RulesConfig = RulesConfig {
  - fullModuleGraph :: Bool
  - enableTemplateHaskell :: Bool
  - templateHaskellWarning :: LspT Config IO ()
  }
- getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule)
- getParsedModuleWithComments :: NormalizedFilePath -> Action (Maybe ParsedModule)
- getClientConfigAction :: Action Config
- usePropertyAction :: HasProperty s k t r => KeyNameProxy s -> PluginId -> Properties r -> Action (ToHsType t)
- getHieFile :: NormalizedFilePath -> Action (Maybe HieFile)
- newtype CompiledLinkables = CompiledLinkables {
  - getCompiledLinkables :: Var (ModuleEnv UTCTime)
  }
- getParsedModuleRule :: Recorder (WithPriority Log) -> Rules ()
- getParsedModuleWithCommentsRule :: Recorder (WithPriority Log) -> Rules ()
- getLocatedImportsRule :: Recorder (WithPriority Log) -> Rules ()
- reportImportCyclesRule :: Recorder (WithPriority Log) -> Rules ()
- typeCheckRule :: Recorder (WithPriority Log) -> Rules ()
- getDocMapRule :: Recorder (WithPriority Log) -> Rules ()
- loadGhcSession :: Recorder (WithPriority Log) -> GhcSessionDepsConfig -> Rules ()
- getModIfaceFromDiskRule :: Recorder (WithPriority Log) -> Rules ()
- getModIfaceRule :: Recorder (WithPriority Log) -> Rules ()
- getModSummaryRule :: LspT Config IO () -> Recorder (WithPriority Log) -> Rules ()
- getModuleGraphRule :: Recorder (WithPriority Log) -> Rules ()
- knownFilesRule :: Recorder (WithPriority Log) -> Rules ()
- getClientSettingsRule :: Recorder (WithPriority Log) -> Rules ()
- getHieAstsRule :: Recorder (WithPriority Log) -> Rules ()
- getBindingsRule :: Recorder (WithPriority Log) -> Rules ()
- needsCompilationRule :: NormalizedFilePath -> Action (IdeResultNoDiagnosticsEarlyCutoff (Maybe LinkableType))
- computeLinkableTypeForDynFlags :: DynFlags -> LinkableType
- generateCoreRule :: Recorder (WithPriority Log) -> Rules ()
- getImportMapRule :: Recorder (WithPriority Log) -> Rules ()
- regenerateHiFile :: HscEnvEq -> NormalizedFilePath -> ModSummary -> Maybe LinkableType -> Action ([FileDiagnostic], Maybe HiFileResult)
- ghcSessionDepsDefinition :: Bool -> GhcSessionDepsConfig -> HscEnvEq -> NormalizedFilePath -> Action (Maybe HscEnvEq)
- getParsedModuleDefinition :: HscEnv -> IdeOptions -> NormalizedFilePath -> ModSummary -> IO ([FileDiagnostic], Maybe ParsedModule)
- typeCheckRuleDefinition :: HscEnv -> ParsedModule -> Action (IdeResult TcModuleResult)
- getRebuildCount :: Action Int
- getSourceFileSource :: NormalizedFilePath -> Action ByteString
- currentLinkables :: Action (ModuleEnv UTCTime)
- newtype GhcSessionDepsConfig = GhcSessionDepsConfig {
  - fullModuleGraph :: Bool
  }
- data Log
  - = LogShake Log
  - | LogReindexingHieFile !NormalizedFilePath
  - | LogLoadingHieFile !NormalizedFilePath
  - | LogLoadingHieFileFail !FilePath !SomeException
  - | LogLoadingHieFileSuccess !FilePath
  - | LogTypecheckedFOI !NormalizedFilePath
- newtype DisplayTHWarning = DisplayTHWarning (IO ())

# Types

data IdeState #

A Shake database plus persistent store. Can be thought of as storing mappings from `(FilePath, k)` to `RuleResult k`.

#### Instances

Instances details

MonadReader (ReactorChan, IdeState) (ServerM c) # |
Instance details Defined in Development.IDE.LSP.Server Methods ask :: ServerM c (ReactorChan, IdeState) # local :: ((ReactorChan, IdeState) -> (ReactorChan, IdeState)) -> ServerM c a -> ServerM c a # reader :: ((ReactorChan, IdeState) -> a) -> ServerM c a #

data GetParsedModule #

Constructors

GetParsedModule |

#### Instances

Instances details

Generic GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes Associated Types type Rep GetParsedModule :: Type -> Type Methods from :: GetParsedModule -> Rep GetParsedModule x to :: Rep GetParsedModule x -> GetParsedModule
Show GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods showsPrec :: Int -> GetParsedModule -> ShowS # show :: GetParsedModule -> String # showList :: [GetParsedModule] -> ShowS #
NFData GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods rnf :: GetParsedModule -> () #
Eq GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods (==) :: GetParsedModule -> GetParsedModule -> Bool # (/=) :: GetParsedModule -> GetParsedModule -> Bool #
Hashable GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods hashWithSalt :: Int -> GetParsedModule -> Int # hash :: GetParsedModule -> Int #
type Rep GetParsedModule # |
Instance details Defined in Development.IDE.Core.RuleTypes type Rep GetParsedModule = D1 ('MetaData "GetParsedModule" "Development.IDE.Core.RuleTypes" "ghcide-2.4.0.0-2GLANXY6yWhIRmLZNYhiFQ" 'False) (C1 ('MetaCons "GetParsedModule" 'PrefixI 'False) (U1 :: Type -> Type))
type RuleResult GetParsedModule # | The parse tree for the file using GetFileContents
Instance details Defined in Development.IDE.Core.RuleTypes type RuleResult GetParsedModule = ParsedModule

newtype TransitiveDependencies #

Constructors

TransitiveDependencies |
Fields transitiveModuleDeps :: [NormalizedFilePath] Transitive module dependencies in topological order. The module itself is not included.

#### Instances

Instances details

Generic TransitiveDependencies # |
Instance details Defined in Development.IDE.Import.DependencyInformation Associated Types type Rep TransitiveDependencies :: Type -> Type Methods from :: TransitiveDependencies -> Rep TransitiveDependencies x to :: Rep TransitiveDependencies x -> TransitiveDependencies
Show TransitiveDependencies # |
Instance details Defined in Development.IDE.Import.DependencyInformation Methods showsPrec :: Int -> TransitiveDependencies -> ShowS # show :: TransitiveDependencies -> String # showList :: [TransitiveDependencies] -> ShowS #
NFData TransitiveDependencies # |
Instance details Defined in Development.IDE.Import.DependencyInformation Methods rnf :: TransitiveDependencies -> () #
Eq TransitiveDependencies # |
Instance details Defined in Development.IDE.Import.DependencyInformation Methods (==) :: TransitiveDependencies -> TransitiveDependencies -> Bool # (/=) :: TransitiveDependencies -> TransitiveDependencies -> Bool #
type Rep TransitiveDependencies # |
Instance details Defined in Development.IDE.Import.DependencyInformation type Rep TransitiveDependencies = D1 ('MetaData "TransitiveDependencies" "Development.IDE.Import.DependencyInformation" "ghcide-2.4.0.0-2GLANXY6yWhIRmLZNYhiFQ" 'True) (C1 ('MetaCons "TransitiveDependencies" 'PrefixI 'True) (S1 ('MetaSel ('Just "transitiveModuleDeps") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [NormalizedFilePath])))

newtype Priority #

Constructors

Priority Double |

data GhcSessionIO #

Constructors

GhcSessionIO |

#### Instances

Instances details

Generic GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes Associated Types type Rep GhcSessionIO :: Type -> Type Methods from :: GhcSessionIO -> Rep GhcSessionIO x to :: Rep GhcSessionIO x -> GhcSessionIO
Show GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods showsPrec :: Int -> GhcSessionIO -> ShowS # show :: GhcSessionIO -> String # showList :: [GhcSessionIO] -> ShowS #
NFData GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods rnf :: GhcSessionIO -> () #
Eq GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods (==) :: GhcSessionIO -> GhcSessionIO -> Bool # (/=) :: GhcSessionIO -> GhcSessionIO -> Bool #
Hashable GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods hashWithSalt :: Int -> GhcSessionIO -> Int # hash :: GhcSessionIO -> Int #
type Rep GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes type Rep GhcSessionIO = D1 ('MetaData "GhcSessionIO" "Development.IDE.Core.RuleTypes" "ghcide-2.4.0.0-2GLANXY6yWhIRmLZNYhiFQ" 'False) (C1 ('MetaCons "GhcSessionIO" 'PrefixI 'False) (U1 :: Type -> Type))
type RuleResult GhcSessionIO # |
Instance details Defined in Development.IDE.Core.RuleTypes type RuleResult GhcSessionIO = IdeGhcSession

data GetClientSettings #

Get the client config stored in the ide state

Constructors

GetClientSettings |

#### Instances

Instances details

Generic GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes Associated Types type Rep GetClientSettings :: Type -> Type Methods from :: GetClientSettings -> Rep GetClientSettings x to :: Rep GetClientSettings x -> GetClientSettings
Show GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods showsPrec :: Int -> GetClientSettings -> ShowS # show :: GetClientSettings -> String # showList :: [GetClientSettings] -> ShowS #
NFData GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods rnf :: GetClientSettings -> () #
Eq GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods (==) :: GetClientSettings -> GetClientSettings -> Bool # (/=) :: GetClientSettings -> GetClientSettings -> Bool #
Hashable GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes Methods hashWithSalt :: Int -> GetClientSettings -> Int # hash :: GetClientSettings -> Int #
type Rep GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes type Rep GetClientSettings = D1 ('MetaData "GetClientSettings" "Development.IDE.Core.RuleTypes" "ghcide-2.4.0.0-2GLANXY6yWhIRmLZNYhiFQ" 'False) (C1 ('MetaCons "GetClientSettings" 'PrefixI 'False) (U1 :: Type -> Type))
type RuleResult GetClientSettings # |
Instance details Defined in Development.IDE.Core.RuleTypes type RuleResult GetClientSettings = Hashed (Maybe Value)

# Functions

priorityTypeCheck :: Priority #

priorityGenerateCore :: Priority #

priorityFilesOfInterest :: Priority #

runAction :: String -> IdeState -> Action a -> IO a #

toIdeResult :: Either [FileDiagnostic] v -> IdeResult v #

This is useful for rules to convert rules that can only produce errors or a result into the more general IdeResult type that supports producing warnings while also producing a result.

defineNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action v) -> Rules () #

defineEarlyCutOffNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action (ByteString, v)) -> Rules () #

mainRule :: Recorder (WithPriority Log) -> RulesConfig -> Rules () #

A rule that wires per-file rules together

data RulesConfig #

Constructors

RulesConfig |
Fields fullModuleGraph :: Bool Share the computation for the entire module graph We usually compute the full module graph for the project and share it for all files. However, in large projects it might not be desirable to wait for computing the entire module graph before starting to typecheck a particular file. Disabling this drastically decreases sharing and is likely to increase memory usage if you have multiple files open Disabling this also disables checking for import cycles enableTemplateHaskell :: Bool Disable TH for improved performance in large codebases templateHaskellWarning :: LspT Config IO () Warning to show when TH is not supported by the current HLS binary

#### Instances

Instances details

Default RulesConfig # |
Instance details Defined in Development.IDE.Core.Rules Methods def :: RulesConfig #

getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule) #

Parse the contents of a haskell file.

getParsedModuleWithComments :: NormalizedFilePath -> Action (Maybe ParsedModule) #

Parse the contents of a haskell file, ensuring comments are preserved in annotations

getClientConfigAction :: Action Config #

Returns the client configuration, creating a build dependency. You should always use this function when accessing client configuration from build rules.

usePropertyAction :: HasProperty s k t r => KeyNameProxy s -> PluginId -> Properties r -> Action (ToHsType t) #

getHieFile :: NormalizedFilePath -> Action (Maybe HieFile) #

Get HieFile for haskell file on NormalizedFilePath

# Rules

newtype CompiledLinkables #

Tracks which linkables are current, so we don't need to unload them

Constructors

CompiledLinkables |
Fields getCompiledLinkables :: Var (ModuleEnv UTCTime)

#### Instances

Instances details

IsIdeGlobal CompiledLinkables # |
Instance details Defined in Development.IDE.Core.Rules

getParsedModuleRule :: Recorder (WithPriority Log) -> Rules () #

WARNING: We currently parse the module both with and without Opt_Haddock, and return the one with Haddocks if it -- succeeds. However, this may not work for hlint or any client code that might need the parsed source with all annotations, including comments. For that use case you might want to use `getParsedModuleWithCommentsRule` See https://github.com/haskell/ghcide/pull/350#discussion_r370878197 and https://github.com/mpickering/ghcide/pull/22#issuecomment-625070490 GHC wiki about: https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations

getParsedModuleWithCommentsRule :: Recorder (WithPriority Log) -> Rules () #

This rule provides a ParsedModule preserving all annotations, including keywords, punctuation and comments. So it is suitable for use cases where you need a perfect edit.

getLocatedImportsRule :: Recorder (WithPriority Log) -> Rules () #

reportImportCyclesRule :: Recorder (WithPriority Log) -> Rules () #

typeCheckRule :: Recorder (WithPriority Log) -> Rules () #

Typechecks a module.

getDocMapRule :: Recorder (WithPriority Log) -> Rules () #

loadGhcSession :: Recorder (WithPriority Log) -> GhcSessionDepsConfig -> Rules () #

getModIfaceFromDiskRule :: Recorder (WithPriority Log) -> Rules () #

Load a iface from disk, or generate it if there isn't one or it is out of date This rule also ensures that the `.hie` and `.o` (if needed) files are written out.

getModIfaceRule :: Recorder (WithPriority Log) -> Rules () #

getModSummaryRule :: LspT Config IO () -> Recorder (WithPriority Log) -> Rules () #

getModuleGraphRule :: Recorder (WithPriority Log) -> Rules () #

knownFilesRule :: Recorder (WithPriority Log) -> Rules () #

getClientSettingsRule :: Recorder (WithPriority Log) -> Rules () #

getHieAstsRule :: Recorder (WithPriority Log) -> Rules () #

getBindingsRule :: Recorder (WithPriority Log) -> Rules () #

needsCompilationRule :: NormalizedFilePath -> Action (IdeResultNoDiagnosticsEarlyCutoff (Maybe LinkableType)) #

computeLinkableTypeForDynFlags :: DynFlags -> LinkableType #

How should we compile this module? (assuming we do in fact need to compile it). Depends on whether it uses unboxed tuples or sums

generateCoreRule :: Recorder (WithPriority Log) -> Rules () #

getImportMapRule :: Recorder (WithPriority Log) -> Rules () #

regenerateHiFile :: HscEnvEq -> NormalizedFilePath -> ModSummary -> Maybe LinkableType -> Action ([FileDiagnostic], Maybe HiFileResult) #

Also generates and indexes the `.hie` file, along with the `.o` file if needed Invariant maintained is that if the `.hi` file was successfully written, then the `.hie` and `.o` file (if needed) were also successfully written

ghcSessionDepsDefinition #

Arguments

:: Bool | full mod summary
-> GhcSessionDepsConfig |
-> HscEnvEq |
-> NormalizedFilePath |
-> Action (Maybe HscEnvEq) |

Note [GhcSessionDeps] For a file `Foo`, GhcSessionDeps "Foo.hs" results in an HscEnv which includes 1. HomeModInfo's (in the HUG/HPT) for all modules in the transitive closure of Foo, **NOT** including Foo itself. 2. ModSummary's (in the ModuleGraph) for all modules in the transitive closure of Foo, including Foo itself. 3. ModLocation's (in the FinderCache) all modules in the transitive closure of Foo, including Foo itself.

getParsedModuleDefinition :: HscEnv -> IdeOptions -> NormalizedFilePath -> ModSummary -> IO ([FileDiagnostic], Maybe ParsedModule) #

typeCheckRuleDefinition :: HscEnv -> ParsedModule -> Action (IdeResult TcModuleResult) #

getRebuildCount :: Action Int #

getSourceFileSource :: NormalizedFilePath -> Action ByteString #

currentLinkables :: Action (ModuleEnv UTCTime) #

Get all the linkables stored in the graph, i.e. the ones we *do not* need to unload. Doesn't actually contain the code, since we don't need it to unload

newtype GhcSessionDepsConfig #

Constructors

GhcSessionDepsConfig |
Fields fullModuleGraph :: Bool

#### Instances

Instances details

Default GhcSessionDepsConfig # |
Instance details Defined in Development.IDE.Core.Rules Methods def :: GhcSessionDepsConfig #

data Log #

Constructors

LogShake Log |
LogReindexingHieFile !NormalizedFilePath |
LogLoadingHieFile !NormalizedFilePath |
LogLoadingHieFileFail !FilePath !SomeException |
LogLoadingHieFileSuccess !FilePath |
LogTypecheckedFOI !NormalizedFilePath |

#### Instances

Instances details

Show Log # |
Instance details Defined in Development.IDE.Core.Rules Methods showsPrec :: Int -> Log -> ShowS # show :: Log -> String # showList :: [Log] -> ShowS #
Pretty Log # |
Instance details Defined in Development.IDE.Core.Rules Methods pretty :: Log -> Doc ann # prettyList :: [Log] -> Doc ann #

newtype DisplayTHWarning #

Constructors

DisplayTHWarning (IO ()) |

#### Instances

Instances details

IsIdeGlobal DisplayTHWarning # |
Instance details Defined in Development.IDE.Core.Rules