{-# LANGUAGE RankNTypes #-}
module Development.IDE.Types.Options
( IdeOptions(..)
, IdePreprocessedSource(..)
, IdeReportProgress(..)
, IdeDefer(..)
, clientSupportsProgress
, IdePkgLocationOptions(..)
, defaultIdeOptions
, IdeResult
) where
import Development.Shake
import Development.IDE.GHC.Util
import GHC hiding (parseModule, typecheckModule)
import GhcPlugins as GHC hiding (fst3, (<>))
import qualified Language.Haskell.LSP.Types.Capabilities as LSP
import qualified Data.Text as T
import Development.IDE.Types.Diagnostics
data IdeOptions = IdeOptions
{ optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
, optGhcSession :: Action (FilePath -> Action (IdeResult HscEnvEq))
, optPkgLocationOpts :: IdePkgLocationOptions
, optExtensions :: [String]
, optThreads :: Int
, optShakeFiles :: Maybe FilePath
, optShakeProfiling :: Maybe FilePath
, optTesting :: Bool
, optReportProgress :: IdeReportProgress
, optLanguageSyntax :: String
, optNewColonConvention :: Bool
, optKeywords :: [T.Text]
, optDefer :: IdeDefer
}
data IdePreprocessedSource = IdePreprocessedSource
{ preprocWarnings :: [(GHC.SrcSpan, String)]
, preprocErrors :: [(GHC.SrcSpan, String)]
, preprocSource :: GHC.ParsedSource
}
newtype IdeReportProgress = IdeReportProgress Bool
newtype IdeDefer = IdeDefer Bool
clientSupportsProgress :: LSP.ClientCapabilities -> IdeReportProgress
clientSupportsProgress caps = IdeReportProgress $ Just True ==
(LSP._workDoneProgress =<< LSP._window (caps :: LSP.ClientCapabilities))
defaultIdeOptions :: Action (FilePath -> Action (IdeResult HscEnvEq)) -> IdeOptions
defaultIdeOptions session = IdeOptions
{optPreprocessor = IdePreprocessedSource [] []
,optGhcSession = session
,optExtensions = ["hs", "lhs"]
,optPkgLocationOpts = defaultIdePkgLocationOptions
,optThreads = 0
,optShakeFiles = Nothing
,optShakeProfiling = Nothing
,optReportProgress = IdeReportProgress False
,optLanguageSyntax = "haskell"
,optNewColonConvention = False
,optKeywords = haskellKeywords
,optDefer = IdeDefer True
,optTesting = False
}
data IdePkgLocationOptions = IdePkgLocationOptions
{ optLocateHieFile :: PackageConfig -> Module -> IO (Maybe FilePath)
, optLocateSrcFile :: PackageConfig -> Module -> IO (Maybe FilePath)
}
defaultIdePkgLocationOptions :: IdePkgLocationOptions
defaultIdePkgLocationOptions = IdePkgLocationOptions f f
where f _ _ = return Nothing
haskellKeywords :: [T.Text]
haskellKeywords =
[ "as"
, "case", "of"
, "class", "instance", "type"
, "data", "family", "newtype"
, "default"
, "deriving"
, "do", "mdo", "proc", "rec"
, "forall"
, "foreign"
, "hiding"
, "if", "then", "else"
, "import", "qualified", "hiding"
, "infix", "infixl", "infixr"
, "let", "in", "where"
, "module"
]