1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE RankNTypes #-}
7module Development.IDE.Types.Options
9 , IdePreprocessedSource(..)
10 , IdeReportProgress(..)
12 , clientSupportsProgress
13 , IdePkgLocationOptions(..)
17import Development.Shake
18import Development.IDE.GHC.Util
19import GHC hiding (parseModule, typecheckModule)
20import GhcPlugins as GHC hiding (fst3, (<>))
21import qualified Language.Haskell.LSP.Types.Capabilities as LSP
22import qualified Data.Text as T
24data IdeOptions = IdeOptions
25 { optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
26 -- ^ Preprocessor to run over all parsed source trees, generating a list of warnings
27 -- and a list of errors, along with a new parse tree.
28 , optGhcSession :: Action (FilePath -> Action HscEnvEq)
29 -- ^ Setup a GHC session for a given file, e.g. @Foo.hs@.
30 -- For the same 'ComponentOptions' from hie-bios, the resulting function will be applied once per file.
31 -- It is desirable that many files get the same 'HscEnvEq', so that more IDE features work.
32 , optPkgLocationOpts :: IdePkgLocationOptions
33 -- ^ How to locate source and @.hie@ files given a module name.
34 , optExtensions :: [String]
35 -- ^ File extensions to search for code, defaults to Haskell sources (including @.hs@)
38 -- ^ Number of threads to use. Use 0 for number of threads on the machine.
39 , optShakeFiles :: Maybe FilePath
40 -- ^ Directory where the shake database should be stored. For ghcide this is always set to `Nothing` for now
41 -- meaning we keep everything in memory but the daml CLI compiler uses this for incremental builds.
42 , optShakeProfiling :: Maybe FilePath
43 -- ^ Set to 'Just' to create a directory of profiling reports.
45 -- ^ Whether to enable additional lsp messages used by the test suite for checking invariants
46 , optReportProgress :: IdeReportProgress
47 -- ^ Whether to report progress during long operations.
48 , optLanguageSyntax :: String
49 -- ^ the ```language to use
50 , optNewColonConvention :: Bool
51 -- ^ whether to use new colon convention
52 , optKeywords :: [T.Text]
53 -- ^ keywords used for completions. These are customizable
54 -- since DAML has a different set of keywords than Haskell.
55 , optDefer :: IdeDefer
56 -- ^ Whether to defer type errors, typed holes and out of scope
57 -- variables. Deferral allows the IDE to continue to provide
58 -- features such as diagnostics and go-to-definition, in
59 -- situations in which they would become unavailable because of
60 -- the presence of type errors, holes or unbound variables.
61 , optInterfaceLoadingDiagnostics :: Bool
62 -- ^ Generate Info-level diagnostics to report interface loading actions
65data IdePreprocessedSource = IdePreprocessedSource
66 { preprocWarnings :: [(GHC.SrcSpan, String)]
67 -- ^ Warnings emitted by the preprocessor.
68 , preprocErrors :: [(GHC.SrcSpan, String)]
69 -- ^ Errors emitted by the preprocessor.
70 , preprocSource :: GHC.ParsedSource
71 -- ^ New parse tree emitted by the preprocessor.
74newtype IdeReportProgress = IdeReportProgress Bool
75newtype IdeDefer = IdeDefer Bool
77clientSupportsProgress :: LSP.ClientCapabilities -> IdeReportProgress
78clientSupportsProgress caps = IdeReportProgress $ Just True ==
79 (LSP._workDoneProgress =<< LSP._window (caps :: LSP.ClientCapabilities))
81defaultIdeOptions :: Action (FilePath -> Action HscEnvEq) -> IdeOptions
82defaultIdeOptions session = IdeOptions
83 {optPreprocessor = IdePreprocessedSource [] []
84 ,optGhcSession = session
85 ,optExtensions = ["hs", "lhs"]
86 ,optPkgLocationOpts = defaultIdePkgLocationOptions
88 ,optShakeFiles = Nothing
89 ,optShakeProfiling = Nothing
90 ,optReportProgress = IdeReportProgress False
91 ,optLanguageSyntax = "haskell"
92 ,optNewColonConvention = False
93 ,optKeywords = haskellKeywords
94 ,optDefer = IdeDefer True
96 ,optInterfaceLoadingDiagnostics = False
100-- | The set of options used to locate files belonging to external packages.
101data IdePkgLocationOptions = IdePkgLocationOptions
102 { optLocateHieFile :: PackageConfig -> Module -> IO (Maybe FilePath)
103 -- ^ Locate the HIE file for the given module. The PackageConfig can be
104 -- used to lookup settings like importDirs.
105 , optLocateSrcFile :: PackageConfig -> Module -> IO (Maybe FilePath)
106 -- ^ Locate the source file for the given module. The PackageConfig can be
107 -- used to lookup settings like importDirs. For DAML, we place them in the package DB.
108 -- For cabal this could point somewhere in ~/.cabal/packages.
111defaultIdePkgLocationOptions :: IdePkgLocationOptions
112defaultIdePkgLocationOptions = IdePkgLocationOptions f f
113 where f _ _ = return Nothing
115-- | From https://wiki.haskell.org/Keywords
116haskellKeywords :: [T.Text]
120 , "class", "instance", "type"
121 , "data", "family", "newtype"
124 , "do", "mdo", "proc", "rec"
128 , "if", "then", "else"
129 , "import", "qualified", "hiding"
130 , "infix", "infixl", "infixr"
131 , "let", "in", "where"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list