-
Notifications
You must be signed in to change notification settings - Fork 66
Draft: Change API to emit multiple ComponentOptions if available #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| {-# LANGUAGE FlexibleInstances #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
| {-# LANGUAGE DeriveFunctor #-} | ||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
|
|
||
| {-# LANGUAGE DeriveFoldable #-} | ||
| {-# LANGUAGE DeriveTraversable #-} | ||
| {-# LANGUAGE PatternSynonyms #-} | ||
| {-# LANGUAGE ViewPatterns #-} | ||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
|
|
||
| module HIE.Bios.Types where | ||
|
|
||
| import System.Exit | ||
| import Control.Exception ( Exception ) | ||
|
|
||
| data BIOSVerbosity = Silent | Verbose | ||
|
|
||
| ---------------------------------------------------------------- | ||
|
|
||
| -- | The environment of a single 'Cradle'. | ||
|
|
@@ -44,21 +44,60 @@ data ActionName a | |
| | Other a | ||
| deriving (Show, Eq, Ord, Functor) | ||
|
|
||
| data CradleAction a = CradleAction { | ||
| actionName :: ActionName a | ||
| -- ^ Name of the action. | ||
| , runCradle :: LoggingFunction -> FilePath -> IO (CradleLoadResult ComponentOptions) | ||
| -- ^ Options to compile the given file with. | ||
| , runGhcCmd :: [String] -> IO (CradleLoadResult String) | ||
| -- ^ Executes the @ghc@ binary that is usually used to | ||
| -- build the cradle. E.g. for a cabal cradle this should be | ||
| -- equivalent to @cabal exec ghc -- args@ | ||
| } | ||
| data CradleAction a = CradleAction | ||
| { actionName :: ActionName a | ||
| -- ^ Name of the action. | ||
| , runCradle :: LoggingFunction -> FilePath -> IO (CradleLoadResult LoadResult) | ||
| -- ^ Options to compile the given file with. | ||
| -- | ||
| -- The given FilePath /must/ be part of 'LoadResult.loadResultComponent' if | ||
| -- the loading operation succeeds. | ||
| , runGhcCmd :: [String] -> IO (CradleLoadResult String) | ||
| -- ^ Executes the @ghc@ binary that is usually used to | ||
| -- build the cradle. E.g. for a cabal cradle this should be | ||
| -- equivalent to @cabal exec ghc -- args@ | ||
| } | ||
| deriving (Functor) | ||
|
|
||
| instance Show a => Show (CradleAction a) where | ||
| show CradleAction { actionName = name } = "CradleAction: " ++ show name | ||
|
|
||
| type LoadResult = LoadResult' ComponentOptions | ||
|
|
||
| -- | Record for expressing successful loading. | ||
| -- Can express partial success. | ||
| data LoadResult' a = LoadResult | ||
| { loadResultComponent :: Maybe a | ||
| -- ^ Component options for the FilePath that produced this 'LoadResult'. | ||
| -- See 'CradleAction.runCradle' for information on how to produce a 'LoadResult'. | ||
| -- | ||
| -- This field can be 'Nothing' to indicate that loading partially failed/succeeded. | ||
| , loadResultDependencies :: [a] | ||
| -- ^ Direct or indirect dependencies from the component from above. | ||
| -- Indirect means that it is not required that 'ComponentOptions' in this list | ||
| -- are required dependencies of 'loadResultComponent'. It is specifically allowed | ||
|
Comment on lines
+77
to
+78
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sentence makes no sense, what I mean is, that items here are either local dependencies in some form, or completely independent but can be loaded, too. |
||
| -- to list 'ComponentOptions' that have no relation with 'loadResultComponent'. | ||
| -- | ||
| -- Example: | ||
| -- | ||
| -- Assume we load an executable component, then its options must be located | ||
| -- in 'loadResultComponent' and its local dependencies in 'loadResultDependencies', | ||
| -- but additionally it is possible to list other executable component's | ||
| -- options in 'loadResultDependencies'. | ||
| } deriving (Eq, Ord, Show, Functor, Foldable, Traversable) | ||
|
|
||
| -- | Create a simple LoadResult from a single 'ComponentOptions' record. | ||
| -- Sets the 'ComponentOptions' as 'loadResultComponent'. | ||
| mkSimpleLoadResult :: ComponentOptions -> LoadResult | ||
| mkSimpleLoadResult opts = LoadResult | ||
| { loadResultComponent = Just opts | ||
| , loadResultDependencies = [] | ||
| } | ||
|
|
||
| -- | Helper to access the main component if there is one. | ||
| pattern Main :: a -> LoadResult' a | ||
| pattern Main opts <- (loadResultComponent -> Just opts) | ||
|
Comment on lines
+98
to
+99
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have more of these such as: for typesafe pattern matching.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if we need patterns, we might just introduce a more elaborated datatype |
||
|
|
||
| -- | Result of an attempt to set up a GHC session for a 'Cradle'. | ||
| -- This is the go-to error handling mechanism. When possible, this | ||
| -- should be preferred over throwing exceptions. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about somethin like
It would be generic enough to allow add more component information afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe we can drop the prefix somehow to be less "Component"-y? However, since the record field prefix will probably still be required, probably pointless.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah,
Infosounds good too, maybe too generic but whatever