on 63432ce help sign in
69 lines 2.6 kB history raw
1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE RankNTypes #-}
6-- | Options
7module Development.IDE.Types.Options
8 ( IdeOptions(..)
9 , IdeReportProgress(..)
10 , clientSupportsProgress
11 , IdePkgLocationOptions(..)
12 , defaultIdeOptions
13 ) where
15import Data.Maybe
16import Development.Shake
17import GHC hiding (parseModule, typecheckModule)
18import GhcPlugins as GHC hiding (fst3, (<>))
19import qualified Language.Haskell.LSP.Types.Capabilities as LSP
21data IdeOptions = IdeOptions
22 { optPreprocessor :: GHC.ParsedSource -> ([(GHC.SrcSpan, String)], GHC.ParsedSource)
23 , optGhcSession :: Action HscEnv
24 -- ^ Setup a GHC session using a given package state. If a `ParsedModule` is supplied,
25 -- the import path should be setup for that module.
26 , optPkgLocationOpts :: IdePkgLocationOptions
27 , optExtensions :: [String]
29 , optThreads :: Int
30 , optShakeProfiling :: Maybe FilePath
31 , optReportProgress :: IdeReportProgress
32 , optLanguageSyntax :: String -- ^ the ```language to use
33 , optNewColonConvention :: Bool -- ^ whether to use new colon convention
34 }
36newtype IdeReportProgress = IdeReportProgress Bool
38clientSupportsProgress :: LSP.ClientCapabilities -> IdeReportProgress
39clientSupportsProgress caps = IdeReportProgress $ fromMaybe False $
40 LSP._progress =<< LSP._window (caps :: LSP.ClientCapabilities)
42defaultIdeOptions :: Action HscEnv -> IdeOptions
43defaultIdeOptions session = IdeOptions
44 {optPreprocessor = (,) []
45 ,optGhcSession = session
46 ,optExtensions = ["hs"]
47 ,optPkgLocationOpts = defaultIdePkgLocationOptions
48 ,optThreads = 0
49 ,optShakeProfiling = Nothing
50 ,optReportProgress = IdeReportProgress False
51 ,optLanguageSyntax = "haskell"
52 ,optNewColonConvention = False
53 }
56-- | The set of options used to locate files belonging to external packages.
57data IdePkgLocationOptions = IdePkgLocationOptions
58 { optLocateHieFile :: PackageConfig -> Module -> IO (Maybe FilePath)
59 -- ^ Locate the HIE file for the given module. The PackageConfig can be
60 -- used to lookup settings like importDirs.
61 , optLocateSrcFile :: PackageConfig -> Module -> IO (Maybe FilePath)
62 -- ^ Locate the source file for the given module. The PackageConfig can be
63 -- used to lookup settings like importDirs. For DAML, we place them in the package DB.
64 -- For cabal this could point somewhere in ~/.cabal/packages.
65 }
67defaultIdePkgLocationOptions :: IdePkgLocationOptions
68defaultIdePkgLocationOptions = IdePkgLocationOptions f f
69 where f _ _ = return Nothing