-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}

{- HLINT ignore "Avoid restricted extensions" -}

-- | Options
module Development.IDE.Types.Options
  ( IdeOptions(..)
  , IdePreprocessedSource(..)
  , IdeReportProgress(..)
  , IdeDefer(..)
  , IdeTesting(..)
  , IdeOTMemoryProfiling(..)
  , clientSupportsProgress
  , IdePkgLocationOptions(..)
  , defaultIdeOptions
  , IdeResult
  , IdeGhcSession(..)
  , LspConfig(..)
  , defaultLspConfig
  , CheckProject(..)
  , CheckParents(..)
  , OptHaddockParse(..)
  ) 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
import Control.DeepSeq (NFData(..))
import Data.Aeson
import GHC.Generics

data IdeGhcSession = IdeGhcSession
  { IdeGhcSession -> FilePath -> IO (IdeResult HscEnvEq, [FilePath])
loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
  -- ^ Returns the Ghc session and the cradle dependencies
  , IdeGhcSession -> Int
sessionVersion :: !Int
  -- ^ Used as Shake key, versions must be unique and not reused
  }

instance Show IdeGhcSession where show :: IdeGhcSession -> FilePath
show IdeGhcSession
_ = FilePath
"IdeGhcSession"
instance NFData IdeGhcSession where rnf :: IdeGhcSession -> ()
rnf !IdeGhcSession
_ = ()

data IdeOptions = IdeOptions
  { IdeOptions -> ParsedSource -> IdePreprocessedSource
optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
    -- ^ Preprocessor to run over all parsed source trees, generating a list of warnings
    --   and a list of errors, along with a new parse tree.
  , IdeOptions -> Action IdeGhcSession
optGhcSession :: Action IdeGhcSession
    -- ^ Setup a GHC session for a given file, e.g. @Foo.hs@.
    --   For the same 'ComponentOptions' from hie-bios, the resulting function will be applied once per file.
    --   It is desirable that many files get the same 'HscEnvEq', so that more IDE features work.
  , IdeOptions -> IdePkgLocationOptions
optPkgLocationOpts :: IdePkgLocationOptions
    -- ^ How to locate source and @.hie@ files given a module name.
  , IdeOptions -> [FilePath]
optExtensions :: [String]
    -- ^ File extensions to search for code, defaults to Haskell sources (including @.hs@)

  , IdeOptions -> Int
optThreads :: Int
    -- ^ Number of threads to use. Use 0 for number of threads on the machine.
  , IdeOptions -> Maybe FilePath
optShakeFiles :: Maybe FilePath
  -- ^ Directory where the shake database should be stored. For ghcide this is always set to `Nothing` for now
  -- meaning we keep everything in memory but the daml CLI compiler uses this for incremental builds.
  , IdeOptions -> Maybe FilePath
optShakeProfiling :: Maybe FilePath
    -- ^ Set to 'Just' to create a directory of profiling reports.
  , IdeOptions -> IdeOTMemoryProfiling
optOTMemoryProfiling :: IdeOTMemoryProfiling
    -- ^ Whether to record profiling information with OpenTelemetry. You must
    --   also enable the -l RTS flag for this to have any effect
  , IdeOptions -> IdeTesting
optTesting :: IdeTesting
    -- ^ Whether to enable additional lsp messages used by the test suite for checking invariants
  , IdeOptions -> IdeReportProgress
optReportProgress :: IdeReportProgress
    -- ^ Whether to report progress during long operations.
  , IdeOptions -> FilePath
optLanguageSyntax :: String
    -- ^ the ```language to use
  , IdeOptions -> Bool
optNewColonConvention :: Bool
    -- ^ whether to use new colon convention
  , IdeOptions -> [Text]
optKeywords :: [T.Text]
    -- ^ keywords used for completions. These are customizable
    -- since DAML has a different set of keywords than Haskell.
  , IdeOptions -> IdeDefer
optDefer :: IdeDefer
    -- ^ Whether to defer type errors, typed holes and out of scope
    --   variables. Deferral allows the IDE to continue to provide
    --   features such as diagnostics and go-to-definition, in
    --   situations in which they would become unavailable because of
    --   the presence of type errors, holes or unbound variables.
  , IdeOptions -> CheckProject
optCheckProject :: CheckProject
    -- ^ Whether to typecheck the entire project on load
  , IdeOptions -> CheckParents
optCheckParents :: CheckParents
    -- ^ When to typecheck reverse dependencies of a file
  , IdeOptions -> OptHaddockParse
optHaddockParse :: OptHaddockParse
    -- ^ Whether to return result of parsing module with Opt_Haddock.
    --   Otherwise, return the result of parsing without Opt_Haddock, so
    --   that the parsed module contains the result of Opt_KeepRawTokenStream,
    --   which might be necessary for hlint.
  , IdeOptions -> DynFlags -> DynFlags
optCustomDynFlags :: DynFlags -> DynFlags
    -- ^ Will be called right after setting up a new cradle,
    --   allowing to customize the Ghc options used
  }

data OptHaddockParse = HaddockParse | NoHaddockParse
  deriving (OptHaddockParse -> OptHaddockParse -> Bool
(OptHaddockParse -> OptHaddockParse -> Bool)
-> (OptHaddockParse -> OptHaddockParse -> Bool)
-> Eq OptHaddockParse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OptHaddockParse -> OptHaddockParse -> Bool
$c/= :: OptHaddockParse -> OptHaddockParse -> Bool
== :: OptHaddockParse -> OptHaddockParse -> Bool
$c== :: OptHaddockParse -> OptHaddockParse -> Bool
Eq,Eq OptHaddockParse
Eq OptHaddockParse
-> (OptHaddockParse -> OptHaddockParse -> Ordering)
-> (OptHaddockParse -> OptHaddockParse -> Bool)
-> (OptHaddockParse -> OptHaddockParse -> Bool)
-> (OptHaddockParse -> OptHaddockParse -> Bool)
-> (OptHaddockParse -> OptHaddockParse -> Bool)
-> (OptHaddockParse -> OptHaddockParse -> OptHaddockParse)
-> (OptHaddockParse -> OptHaddockParse -> OptHaddockParse)
-> Ord OptHaddockParse
OptHaddockParse -> OptHaddockParse -> Bool
OptHaddockParse -> OptHaddockParse -> Ordering
OptHaddockParse -> OptHaddockParse -> OptHaddockParse
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OptHaddockParse -> OptHaddockParse -> OptHaddockParse
$cmin :: OptHaddockParse -> OptHaddockParse -> OptHaddockParse
max :: OptHaddockParse -> OptHaddockParse -> OptHaddockParse
$cmax :: OptHaddockParse -> OptHaddockParse -> OptHaddockParse
>= :: OptHaddockParse -> OptHaddockParse -> Bool
$c>= :: OptHaddockParse -> OptHaddockParse -> Bool
> :: OptHaddockParse -> OptHaddockParse -> Bool
$c> :: OptHaddockParse -> OptHaddockParse -> Bool
<= :: OptHaddockParse -> OptHaddockParse -> Bool
$c<= :: OptHaddockParse -> OptHaddockParse -> Bool
< :: OptHaddockParse -> OptHaddockParse -> Bool
$c< :: OptHaddockParse -> OptHaddockParse -> Bool
compare :: OptHaddockParse -> OptHaddockParse -> Ordering
$ccompare :: OptHaddockParse -> OptHaddockParse -> Ordering
$cp1Ord :: Eq OptHaddockParse
Ord,Int -> OptHaddockParse -> ShowS
[OptHaddockParse] -> ShowS
OptHaddockParse -> FilePath
(Int -> OptHaddockParse -> ShowS)
-> (OptHaddockParse -> FilePath)
-> ([OptHaddockParse] -> ShowS)
-> Show OptHaddockParse
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [OptHaddockParse] -> ShowS
$cshowList :: [OptHaddockParse] -> ShowS
show :: OptHaddockParse -> FilePath
$cshow :: OptHaddockParse -> FilePath
showsPrec :: Int -> OptHaddockParse -> ShowS
$cshowsPrec :: Int -> OptHaddockParse -> ShowS
Show,Int -> OptHaddockParse
OptHaddockParse -> Int
OptHaddockParse -> [OptHaddockParse]
OptHaddockParse -> OptHaddockParse
OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
OptHaddockParse
-> OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
(OptHaddockParse -> OptHaddockParse)
-> (OptHaddockParse -> OptHaddockParse)
-> (Int -> OptHaddockParse)
-> (OptHaddockParse -> Int)
-> (OptHaddockParse -> [OptHaddockParse])
-> (OptHaddockParse -> OptHaddockParse -> [OptHaddockParse])
-> (OptHaddockParse -> OptHaddockParse -> [OptHaddockParse])
-> (OptHaddockParse
    -> OptHaddockParse -> OptHaddockParse -> [OptHaddockParse])
-> Enum OptHaddockParse
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: OptHaddockParse
-> OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
$cenumFromThenTo :: OptHaddockParse
-> OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
enumFromTo :: OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
$cenumFromTo :: OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
enumFromThen :: OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
$cenumFromThen :: OptHaddockParse -> OptHaddockParse -> [OptHaddockParse]
enumFrom :: OptHaddockParse -> [OptHaddockParse]
$cenumFrom :: OptHaddockParse -> [OptHaddockParse]
fromEnum :: OptHaddockParse -> Int
$cfromEnum :: OptHaddockParse -> Int
toEnum :: Int -> OptHaddockParse
$ctoEnum :: Int -> OptHaddockParse
pred :: OptHaddockParse -> OptHaddockParse
$cpred :: OptHaddockParse -> OptHaddockParse
succ :: OptHaddockParse -> OptHaddockParse
$csucc :: OptHaddockParse -> OptHaddockParse
Enum)

newtype CheckProject = CheckProject { CheckProject -> Bool
shouldCheckProject :: Bool }
  deriving stock (CheckProject -> CheckProject -> Bool
(CheckProject -> CheckProject -> Bool)
-> (CheckProject -> CheckProject -> Bool) -> Eq CheckProject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CheckProject -> CheckProject -> Bool
$c/= :: CheckProject -> CheckProject -> Bool
== :: CheckProject -> CheckProject -> Bool
$c== :: CheckProject -> CheckProject -> Bool
Eq, Eq CheckProject
Eq CheckProject
-> (CheckProject -> CheckProject -> Ordering)
-> (CheckProject -> CheckProject -> Bool)
-> (CheckProject -> CheckProject -> Bool)
-> (CheckProject -> CheckProject -> Bool)
-> (CheckProject -> CheckProject -> Bool)
-> (CheckProject -> CheckProject -> CheckProject)
-> (CheckProject -> CheckProject -> CheckProject)
-> Ord CheckProject
CheckProject -> CheckProject -> Bool
CheckProject -> CheckProject -> Ordering
CheckProject -> CheckProject -> CheckProject
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CheckProject -> CheckProject -> CheckProject
$cmin :: CheckProject -> CheckProject -> CheckProject
max :: CheckProject -> CheckProject -> CheckProject
$cmax :: CheckProject -> CheckProject -> CheckProject
>= :: CheckProject -> CheckProject -> Bool
$c>= :: CheckProject -> CheckProject -> Bool
> :: CheckProject -> CheckProject -> Bool
$c> :: CheckProject -> CheckProject -> Bool
<= :: CheckProject -> CheckProject -> Bool
$c<= :: CheckProject -> CheckProject -> Bool
< :: CheckProject -> CheckProject -> Bool
$c< :: CheckProject -> CheckProject -> Bool
compare :: CheckProject -> CheckProject -> Ordering
$ccompare :: CheckProject -> CheckProject -> Ordering
$cp1Ord :: Eq CheckProject
Ord, Int -> CheckProject -> ShowS
[CheckProject] -> ShowS
CheckProject -> FilePath
(Int -> CheckProject -> ShowS)
-> (CheckProject -> FilePath)
-> ([CheckProject] -> ShowS)
-> Show CheckProject
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [CheckProject] -> ShowS
$cshowList :: [CheckProject] -> ShowS
show :: CheckProject -> FilePath
$cshow :: CheckProject -> FilePath
showsPrec :: Int -> CheckProject -> ShowS
$cshowsPrec :: Int -> CheckProject -> ShowS
Show)
  deriving newtype (Value -> Parser [CheckProject]
Value -> Parser CheckProject
(Value -> Parser CheckProject)
-> (Value -> Parser [CheckProject]) -> FromJSON CheckProject
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CheckProject]
$cparseJSONList :: Value -> Parser [CheckProject]
parseJSON :: Value -> Parser CheckProject
$cparseJSON :: Value -> Parser CheckProject
FromJSON,[CheckProject] -> Encoding
[CheckProject] -> Value
CheckProject -> Encoding
CheckProject -> Value
(CheckProject -> Value)
-> (CheckProject -> Encoding)
-> ([CheckProject] -> Value)
-> ([CheckProject] -> Encoding)
-> ToJSON CheckProject
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CheckProject] -> Encoding
$ctoEncodingList :: [CheckProject] -> Encoding
toJSONList :: [CheckProject] -> Value
$ctoJSONList :: [CheckProject] -> Value
toEncoding :: CheckProject -> Encoding
$ctoEncoding :: CheckProject -> Encoding
toJSON :: CheckProject -> Value
$ctoJSON :: CheckProject -> Value
ToJSON)
data CheckParents
    -- Note that ordering of constructors is meaningful and must be monotonically
    -- increasing in the scenarios where parents are checked
    = NeverCheck
    | CheckOnClose
    | CheckOnSaveAndClose
    | AlwaysCheck
  deriving stock (CheckParents -> CheckParents -> Bool
(CheckParents -> CheckParents -> Bool)
-> (CheckParents -> CheckParents -> Bool) -> Eq CheckParents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CheckParents -> CheckParents -> Bool
$c/= :: CheckParents -> CheckParents -> Bool
== :: CheckParents -> CheckParents -> Bool
$c== :: CheckParents -> CheckParents -> Bool
Eq, Eq CheckParents
Eq CheckParents
-> (CheckParents -> CheckParents -> Ordering)
-> (CheckParents -> CheckParents -> Bool)
-> (CheckParents -> CheckParents -> Bool)
-> (CheckParents -> CheckParents -> Bool)
-> (CheckParents -> CheckParents -> Bool)
-> (CheckParents -> CheckParents -> CheckParents)
-> (CheckParents -> CheckParents -> CheckParents)
-> Ord CheckParents
CheckParents -> CheckParents -> Bool
CheckParents -> CheckParents -> Ordering
CheckParents -> CheckParents -> CheckParents
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CheckParents -> CheckParents -> CheckParents
$cmin :: CheckParents -> CheckParents -> CheckParents
max :: CheckParents -> CheckParents -> CheckParents
$cmax :: CheckParents -> CheckParents -> CheckParents
>= :: CheckParents -> CheckParents -> Bool
$c>= :: CheckParents -> CheckParents -> Bool
> :: CheckParents -> CheckParents -> Bool
$c> :: CheckParents -> CheckParents -> Bool
<= :: CheckParents -> CheckParents -> Bool
$c<= :: CheckParents -> CheckParents -> Bool
< :: CheckParents -> CheckParents -> Bool
$c< :: CheckParents -> CheckParents -> Bool
compare :: CheckParents -> CheckParents -> Ordering
$ccompare :: CheckParents -> CheckParents -> Ordering
$cp1Ord :: Eq CheckParents
Ord, Int -> CheckParents -> ShowS
[CheckParents] -> ShowS
CheckParents -> FilePath
(Int -> CheckParents -> ShowS)
-> (CheckParents -> FilePath)
-> ([CheckParents] -> ShowS)
-> Show CheckParents
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [CheckParents] -> ShowS
$cshowList :: [CheckParents] -> ShowS
show :: CheckParents -> FilePath
$cshow :: CheckParents -> FilePath
showsPrec :: Int -> CheckParents -> ShowS
$cshowsPrec :: Int -> CheckParents -> ShowS
Show, (forall x. CheckParents -> Rep CheckParents x)
-> (forall x. Rep CheckParents x -> CheckParents)
-> Generic CheckParents
forall x. Rep CheckParents x -> CheckParents
forall x. CheckParents -> Rep CheckParents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CheckParents x -> CheckParents
$cfrom :: forall x. CheckParents -> Rep CheckParents x
Generic)
  deriving anyclass (Value -> Parser [CheckParents]
Value -> Parser CheckParents
(Value -> Parser CheckParents)
-> (Value -> Parser [CheckParents]) -> FromJSON CheckParents
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CheckParents]
$cparseJSONList :: Value -> Parser [CheckParents]
parseJSON :: Value -> Parser CheckParents
$cparseJSON :: Value -> Parser CheckParents
FromJSON, [CheckParents] -> Encoding
[CheckParents] -> Value
CheckParents -> Encoding
CheckParents -> Value
(CheckParents -> Value)
-> (CheckParents -> Encoding)
-> ([CheckParents] -> Value)
-> ([CheckParents] -> Encoding)
-> ToJSON CheckParents
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CheckParents] -> Encoding
$ctoEncodingList :: [CheckParents] -> Encoding
toJSONList :: [CheckParents] -> Value
$ctoJSONList :: [CheckParents] -> Value
toEncoding :: CheckParents -> Encoding
$ctoEncoding :: CheckParents -> Encoding
toJSON :: CheckParents -> Value
$ctoJSON :: CheckParents -> Value
ToJSON)

data LspConfig
  = LspConfig
  { LspConfig -> CheckParents
checkParents :: CheckParents
  , LspConfig -> CheckProject
checkProject :: CheckProject
  } deriving stock (LspConfig -> LspConfig -> Bool
(LspConfig -> LspConfig -> Bool)
-> (LspConfig -> LspConfig -> Bool) -> Eq LspConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LspConfig -> LspConfig -> Bool
$c/= :: LspConfig -> LspConfig -> Bool
== :: LspConfig -> LspConfig -> Bool
$c== :: LspConfig -> LspConfig -> Bool
Eq, Eq LspConfig
Eq LspConfig
-> (LspConfig -> LspConfig -> Ordering)
-> (LspConfig -> LspConfig -> Bool)
-> (LspConfig -> LspConfig -> Bool)
-> (LspConfig -> LspConfig -> Bool)
-> (LspConfig -> LspConfig -> Bool)
-> (LspConfig -> LspConfig -> LspConfig)
-> (LspConfig -> LspConfig -> LspConfig)
-> Ord LspConfig
LspConfig -> LspConfig -> Bool
LspConfig -> LspConfig -> Ordering
LspConfig -> LspConfig -> LspConfig
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LspConfig -> LspConfig -> LspConfig
$cmin :: LspConfig -> LspConfig -> LspConfig
max :: LspConfig -> LspConfig -> LspConfig
$cmax :: LspConfig -> LspConfig -> LspConfig
>= :: LspConfig -> LspConfig -> Bool
$c>= :: LspConfig -> LspConfig -> Bool
> :: LspConfig -> LspConfig -> Bool
$c> :: LspConfig -> LspConfig -> Bool
<= :: LspConfig -> LspConfig -> Bool
$c<= :: LspConfig -> LspConfig -> Bool
< :: LspConfig -> LspConfig -> Bool
$c< :: LspConfig -> LspConfig -> Bool
compare :: LspConfig -> LspConfig -> Ordering
$ccompare :: LspConfig -> LspConfig -> Ordering
$cp1Ord :: Eq LspConfig
Ord, Int -> LspConfig -> ShowS
[LspConfig] -> ShowS
LspConfig -> FilePath
(Int -> LspConfig -> ShowS)
-> (LspConfig -> FilePath)
-> ([LspConfig] -> ShowS)
-> Show LspConfig
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [LspConfig] -> ShowS
$cshowList :: [LspConfig] -> ShowS
show :: LspConfig -> FilePath
$cshow :: LspConfig -> FilePath
showsPrec :: Int -> LspConfig -> ShowS
$cshowsPrec :: Int -> LspConfig -> ShowS
Show, (forall x. LspConfig -> Rep LspConfig x)
-> (forall x. Rep LspConfig x -> LspConfig) -> Generic LspConfig
forall x. Rep LspConfig x -> LspConfig
forall x. LspConfig -> Rep LspConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LspConfig x -> LspConfig
$cfrom :: forall x. LspConfig -> Rep LspConfig x
Generic)
    deriving anyclass (Value -> Parser [LspConfig]
Value -> Parser LspConfig
(Value -> Parser LspConfig)
-> (Value -> Parser [LspConfig]) -> FromJSON LspConfig
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [LspConfig]
$cparseJSONList :: Value -> Parser [LspConfig]
parseJSON :: Value -> Parser LspConfig
$cparseJSON :: Value -> Parser LspConfig
FromJSON, [LspConfig] -> Encoding
[LspConfig] -> Value
LspConfig -> Encoding
LspConfig -> Value
(LspConfig -> Value)
-> (LspConfig -> Encoding)
-> ([LspConfig] -> Value)
-> ([LspConfig] -> Encoding)
-> ToJSON LspConfig
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [LspConfig] -> Encoding
$ctoEncodingList :: [LspConfig] -> Encoding
toJSONList :: [LspConfig] -> Value
$ctoJSONList :: [LspConfig] -> Value
toEncoding :: LspConfig -> Encoding
$ctoEncoding :: LspConfig -> Encoding
toJSON :: LspConfig -> Value
$ctoJSON :: LspConfig -> Value
ToJSON)

defaultLspConfig :: LspConfig
defaultLspConfig :: LspConfig
defaultLspConfig = CheckParents -> CheckProject -> LspConfig
LspConfig CheckParents
CheckOnSaveAndClose (Bool -> CheckProject
CheckProject Bool
True)

data IdePreprocessedSource = IdePreprocessedSource
  { IdePreprocessedSource -> [(SrcSpan, FilePath)]
preprocWarnings :: [(GHC.SrcSpan, String)]
    -- ^ Warnings emitted by the preprocessor.
  , IdePreprocessedSource -> [(SrcSpan, FilePath)]
preprocErrors :: [(GHC.SrcSpan, String)]
    -- ^ Errors emitted by the preprocessor.
  , IdePreprocessedSource -> ParsedSource
preprocSource :: GHC.ParsedSource
    -- ^ New parse tree emitted by the preprocessor.
  }

newtype IdeReportProgress    = IdeReportProgress Bool
newtype IdeDefer             = IdeDefer          Bool
newtype IdeTesting           = IdeTesting        Bool
newtype IdeOTMemoryProfiling = IdeOTMemoryProfiling    Bool

clientSupportsProgress :: LSP.ClientCapabilities -> IdeReportProgress
clientSupportsProgress :: ClientCapabilities -> IdeReportProgress
clientSupportsProgress ClientCapabilities
caps = Bool -> IdeReportProgress
IdeReportProgress (Bool -> IdeReportProgress) -> Bool -> IdeReportProgress
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
==
    (WindowClientCapabilities -> Maybe Bool
LSP._workDoneProgress (WindowClientCapabilities -> Maybe Bool)
-> Maybe WindowClientCapabilities -> Maybe Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ClientCapabilities -> Maybe WindowClientCapabilities
LSP._window (ClientCapabilities
caps :: LSP.ClientCapabilities))

defaultIdeOptions :: Action IdeGhcSession -> IdeOptions
defaultIdeOptions :: Action IdeGhcSession -> IdeOptions
defaultIdeOptions Action IdeGhcSession
session = IdeOptions :: (ParsedSource -> IdePreprocessedSource)
-> Action IdeGhcSession
-> IdePkgLocationOptions
-> [FilePath]
-> Int
-> Maybe FilePath
-> Maybe FilePath
-> IdeOTMemoryProfiling
-> IdeTesting
-> IdeReportProgress
-> FilePath
-> Bool
-> [Text]
-> IdeDefer
-> CheckProject
-> CheckParents
-> OptHaddockParse
-> (DynFlags -> DynFlags)
-> IdeOptions
IdeOptions
    {optPreprocessor :: ParsedSource -> IdePreprocessedSource
optPreprocessor = [(SrcSpan, FilePath)]
-> [(SrcSpan, FilePath)] -> ParsedSource -> IdePreprocessedSource
IdePreprocessedSource [] []
    ,optGhcSession :: Action IdeGhcSession
optGhcSession = Action IdeGhcSession
session
    ,optExtensions :: [FilePath]
optExtensions = [FilePath
"hs", FilePath
"lhs"]
    ,optPkgLocationOpts :: IdePkgLocationOptions
optPkgLocationOpts = IdePkgLocationOptions
defaultIdePkgLocationOptions
    ,optThreads :: Int
optThreads = Int
0
    ,optShakeFiles :: Maybe FilePath
optShakeFiles = Maybe FilePath
forall a. Maybe a
Nothing
    ,optShakeProfiling :: Maybe FilePath
optShakeProfiling = Maybe FilePath
forall a. Maybe a
Nothing
    ,optOTMemoryProfiling :: IdeOTMemoryProfiling
optOTMemoryProfiling = Bool -> IdeOTMemoryProfiling
IdeOTMemoryProfiling Bool
False
    ,optReportProgress :: IdeReportProgress
optReportProgress = Bool -> IdeReportProgress
IdeReportProgress Bool
False
    ,optLanguageSyntax :: FilePath
optLanguageSyntax = FilePath
"haskell"
    ,optNewColonConvention :: Bool
optNewColonConvention = Bool
False
    ,optKeywords :: [Text]
optKeywords = [Text]
haskellKeywords
    ,optDefer :: IdeDefer
optDefer = Bool -> IdeDefer
IdeDefer Bool
True
    ,optTesting :: IdeTesting
optTesting = Bool -> IdeTesting
IdeTesting Bool
False
    ,optCheckProject :: CheckProject
optCheckProject = LspConfig -> CheckProject
checkProject LspConfig
defaultLspConfig
    ,optCheckParents :: CheckParents
optCheckParents = LspConfig -> CheckParents
checkParents LspConfig
defaultLspConfig
    ,optHaddockParse :: OptHaddockParse
optHaddockParse = OptHaddockParse
HaddockParse
    ,optCustomDynFlags :: DynFlags -> DynFlags
optCustomDynFlags = DynFlags -> DynFlags
forall a. a -> a
id
    }


-- | The set of options used to locate files belonging to external packages.
data IdePkgLocationOptions = IdePkgLocationOptions
  { IdePkgLocationOptions
-> PackageConfig -> Module -> IO (Maybe FilePath)
optLocateHieFile :: PackageConfig -> Module -> IO (Maybe FilePath)
  -- ^ Locate the HIE file for the given module. The PackageConfig can be
  -- used to lookup settings like importDirs.
  , IdePkgLocationOptions
-> PackageConfig -> Module -> IO (Maybe FilePath)
optLocateSrcFile :: PackageConfig -> Module -> IO (Maybe FilePath)
  -- ^ Locate the source file for the given module. The PackageConfig can be
  -- used to lookup settings like importDirs. For DAML, we place them in the package DB.
  -- For cabal this could point somewhere in ~/.cabal/packages.
  }

defaultIdePkgLocationOptions :: IdePkgLocationOptions
defaultIdePkgLocationOptions :: IdePkgLocationOptions
defaultIdePkgLocationOptions = (PackageConfig -> Module -> IO (Maybe FilePath))
-> (PackageConfig -> Module -> IO (Maybe FilePath))
-> IdePkgLocationOptions
IdePkgLocationOptions PackageConfig -> Module -> IO (Maybe FilePath)
forall (m :: * -> *) p p a. Monad m => p -> p -> m (Maybe a)
f PackageConfig -> Module -> IO (Maybe FilePath)
forall (m :: * -> *) p p a. Monad m => p -> p -> m (Maybe a)
f
    where f :: p -> p -> m (Maybe a)
f p
_ p
_ = Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing

-- | From https://wiki.haskell.org/Keywords
haskellKeywords :: [T.Text]
haskellKeywords :: [Text]
haskellKeywords =
  [ Text
"as"
  , Text
"case", Text
"of"
  , Text
"class", Text
"instance", Text
"type"
  , Text
"data", Text
"family", Text
"newtype"
  , Text
"default"
  , Text
"deriving"
  , Text
"do", Text
"mdo", Text
"proc", Text
"rec"
  , Text
"forall"
  , Text
"foreign"
  , Text
"hiding"
  , Text
"if", Text
"then", Text
"else"
  , Text
"import", Text
"qualified", Text
"hiding"
  , Text
"infix", Text
"infixl", Text
"infixr"
  , Text
"let", Text
"in", Text
"where"
  , Text
"module"
  ]