2013-05-17 01:00:01 +00:00
|
|
|
module Language.Haskell.GhcMod.Types where
|
2010-04-30 09:36:31 +00:00
|
|
|
|
2014-04-21 05:58:25 +00:00
|
|
|
import Data.List (intercalate)
|
2014-07-11 08:43:51 +00:00
|
|
|
import qualified Data.Map as M
|
2014-08-12 16:08:28 +00:00
|
|
|
import Control.Monad.Error (Error(..))
|
2014-07-11 08:43:51 +00:00
|
|
|
|
|
|
|
import PackageConfig (PackageConfig)
|
2014-04-17 21:40:11 +00:00
|
|
|
|
2014-08-12 16:08:28 +00:00
|
|
|
data GhcModError = GMENoMsg
|
|
|
|
-- ^ Unknown error
|
2014-08-18 06:06:36 +00:00
|
|
|
| GMEString { gmeMsg :: String }
|
2014-08-12 16:08:28 +00:00
|
|
|
-- ^ Some Error with a message. These are produced mostly by
|
|
|
|
-- 'fail' calls on GhcModT.
|
2014-08-18 06:06:36 +00:00
|
|
|
| GMECabalConfigure { gmeMsg :: String }
|
|
|
|
-- ^ Configuring a cabal project failed.
|
2014-08-19 02:28:04 +00:00
|
|
|
deriving (Show)
|
2014-08-12 16:08:28 +00:00
|
|
|
|
|
|
|
instance Error GhcModError where
|
|
|
|
noMsg = GMENoMsg
|
|
|
|
strMsg = GMEString
|
|
|
|
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | Output style.
|
2013-09-05 05:35:28 +00:00
|
|
|
data OutputStyle = LispStyle -- ^ S expression style.
|
|
|
|
| PlainStyle -- ^ Plain textstyle.
|
2012-02-14 01:21:48 +00:00
|
|
|
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | The type for line separator. Historically, a Null string is used.
|
2013-09-03 05:40:51 +00:00
|
|
|
newtype LineSeparator = LineSeparator String
|
|
|
|
|
2010-04-30 09:36:31 +00:00
|
|
|
data Options = Options {
|
2013-09-03 05:40:51 +00:00
|
|
|
outputStyle :: OutputStyle
|
|
|
|
, hlintOpts :: [String]
|
2014-08-13 16:40:01 +00:00
|
|
|
-- | GHC command line options set on the @ghc-mod@ command line
|
|
|
|
, ghcUserOptions:: [GHCOption]
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | If 'True', 'browse' also returns operators.
|
2013-09-03 05:40:51 +00:00
|
|
|
, operators :: Bool
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | If 'True', 'browse' also returns types.
|
2013-09-03 05:40:51 +00:00
|
|
|
, detailed :: Bool
|
2013-11-17 18:31:47 +00:00
|
|
|
-- | If 'True', 'browse' will return fully qualified name
|
|
|
|
, qualified :: Bool
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | Line separator string.
|
2013-09-03 05:40:51 +00:00
|
|
|
, lineSeparator :: LineSeparator
|
2012-02-27 02:23:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | A default 'Options'.
|
2012-02-27 02:23:56 +00:00
|
|
|
defaultOptions :: Options
|
|
|
|
defaultOptions = Options {
|
2013-09-03 05:40:51 +00:00
|
|
|
outputStyle = PlainStyle
|
|
|
|
, hlintOpts = []
|
2014-08-13 16:40:01 +00:00
|
|
|
, ghcUserOptions= []
|
2013-09-03 05:40:51 +00:00
|
|
|
, operators = False
|
|
|
|
, detailed = False
|
2013-11-17 18:31:47 +00:00
|
|
|
, qualified = False
|
2013-09-03 05:40:51 +00:00
|
|
|
, lineSeparator = LineSeparator "\0"
|
2010-04-30 09:36:31 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 02:33:27 +00:00
|
|
|
----------------------------------------------------------------
|
2012-02-14 07:09:53 +00:00
|
|
|
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | The environment where this library is used.
|
2013-03-02 03:18:55 +00:00
|
|
|
data Cradle = Cradle {
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | The directory where this library is executed.
|
2014-03-30 08:28:57 +00:00
|
|
|
cradleCurrentDir :: FilePath
|
|
|
|
-- | The project root directory.
|
|
|
|
, cradleRootDir :: FilePath
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | The file name of the found cabal file.
|
2014-03-30 08:28:57 +00:00
|
|
|
, cradleCabalFile :: Maybe FilePath
|
2014-04-15 03:13:10 +00:00
|
|
|
-- | Package database stack
|
|
|
|
, cradlePkgDbStack :: [GhcPkgDb]
|
2013-03-05 01:22:33 +00:00
|
|
|
} deriving (Eq, Show)
|
2013-03-02 03:18:55 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-04-15 03:13:10 +00:00
|
|
|
-- | GHC package database flags.
|
|
|
|
data GhcPkgDb = GlobalDb | UserDb | PackageDb String deriving (Eq, Show)
|
|
|
|
|
2013-09-19 06:58:50 +00:00
|
|
|
-- | A single GHC command line option.
|
2013-03-01 12:17:52 +00:00
|
|
|
type GHCOption = String
|
2013-08-26 16:28:21 +00:00
|
|
|
|
2013-09-19 06:58:50 +00:00
|
|
|
-- | An include directory for modules.
|
2013-03-01 12:17:52 +00:00
|
|
|
type IncludeDir = FilePath
|
2013-09-16 00:56:08 +00:00
|
|
|
|
2013-09-19 06:58:50 +00:00
|
|
|
-- | A package name.
|
2014-01-30 11:42:25 +00:00
|
|
|
type PackageBaseName = String
|
|
|
|
|
2014-04-17 21:40:11 +00:00
|
|
|
-- | A package version.
|
|
|
|
type PackageVersion = String
|
|
|
|
|
|
|
|
-- | A package id.
|
|
|
|
type PackageId = String
|
|
|
|
|
|
|
|
-- | A package's name, verson and id.
|
|
|
|
type Package = (PackageBaseName, PackageVersion, PackageId)
|
|
|
|
|
|
|
|
pkgName :: Package -> PackageBaseName
|
|
|
|
pkgName (n,_,_) = n
|
|
|
|
|
|
|
|
pkgVer :: Package -> PackageVersion
|
|
|
|
pkgVer (_,v,_) = v
|
|
|
|
|
|
|
|
pkgId :: Package -> PackageId
|
|
|
|
pkgId (_,_,i) = i
|
|
|
|
|
|
|
|
showPkg :: Package -> String
|
|
|
|
showPkg (n,v,_) = intercalate "-" [n,v]
|
|
|
|
|
|
|
|
showPkgId :: Package -> String
|
|
|
|
showPkgId (n,v,i) = intercalate "-" [n,v,i]
|
2013-04-01 05:16:34 +00:00
|
|
|
|
2014-07-11 08:43:51 +00:00
|
|
|
-- | Collection of packages
|
|
|
|
type PkgDb = (M.Map Package PackageConfig)
|
|
|
|
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | Haskell expression.
|
2013-05-20 05:28:56 +00:00
|
|
|
type Expression = String
|
|
|
|
|
2013-09-05 05:35:28 +00:00
|
|
|
-- | Module name.
|
2013-05-20 05:28:56 +00:00
|
|
|
type ModuleString = String
|
|
|
|
|
2014-07-11 03:44:31 +00:00
|
|
|
-- | A Module
|
|
|
|
type Module = [String]
|
|
|
|
|
2013-09-19 06:58:50 +00:00
|
|
|
-- | Option information for GHC
|
|
|
|
data CompilerOptions = CompilerOptions {
|
|
|
|
ghcOptions :: [GHCOption] -- ^ Command line options
|
|
|
|
, includeDirs :: [IncludeDir] -- ^ Include directories for modules
|
|
|
|
, depPackages :: [Package] -- ^ Dependent package names
|
2013-09-20 02:21:31 +00:00
|
|
|
} deriving (Eq, Show)
|