mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-03 05:23:25 +03:00
Make keywords customizable (#493)
This is necessary for DAML where we have additional keywords (e.g. `with`) and other keywords don’t exist (e.g. `foreign`). I considered using just a modify function `[T.Text] -> [T.Text]` but decided against it in the end. The list is small enough and I think it’s much easier to understand with an explicit enumeration (and you can just show the field in the options which is often convenient for debugging).
This commit is contained in:
parent
7ecdd21874
commit
73ad8af648
@ -373,7 +373,9 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
|
|||||||
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
|
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
|
||||||
filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
|
filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
|
||||||
filtOptsCompls = filtListWith mkExtCompl
|
filtOptsCompls = filtListWith mkExtCompl
|
||||||
filtKeywordCompls = if T.null prefixModule then filtListWith mkExtCompl keywords else []
|
filtKeywordCompls
|
||||||
|
| T.null prefixModule = filtListWith mkExtCompl (optKeywords ideOpts)
|
||||||
|
| otherwise = []
|
||||||
|
|
||||||
stripLeading :: Char -> String -> String
|
stripLeading :: Char -> String -> String
|
||||||
stripLeading _ [] = []
|
stripLeading _ [] = []
|
||||||
@ -527,24 +529,3 @@ prefixes =
|
|||||||
, "$c"
|
, "$c"
|
||||||
, "$m"
|
, "$m"
|
||||||
]
|
]
|
||||||
|
|
||||||
keywords :: [T.Text]
|
|
||||||
keywords =
|
|
||||||
[
|
|
||||||
-- From https://wiki.haskell.org/Keywords
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
|
@ -19,6 +19,7 @@ import Development.IDE.GHC.Util
|
|||||||
import GHC hiding (parseModule, typecheckModule)
|
import GHC hiding (parseModule, typecheckModule)
|
||||||
import GhcPlugins as GHC hiding (fst3, (<>))
|
import GhcPlugins as GHC hiding (fst3, (<>))
|
||||||
import qualified Language.Haskell.LSP.Types.Capabilities as LSP
|
import qualified Language.Haskell.LSP.Types.Capabilities as LSP
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
data IdeOptions = IdeOptions
|
data IdeOptions = IdeOptions
|
||||||
{ optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
|
{ optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
|
||||||
@ -48,6 +49,9 @@ data IdeOptions = IdeOptions
|
|||||||
-- ^ the ```language to use
|
-- ^ the ```language to use
|
||||||
, optNewColonConvention :: Bool
|
, optNewColonConvention :: Bool
|
||||||
-- ^ whether to use new colon convention
|
-- ^ whether to use new colon convention
|
||||||
|
, optKeywords :: [T.Text]
|
||||||
|
-- ^ keywords used for completions. These are customizable
|
||||||
|
-- since DAML has a different set of keywords than Haskell.
|
||||||
, optDefer :: IdeDefer
|
, optDefer :: IdeDefer
|
||||||
-- ^ Whether to defer type errors, typed holes and out of scope
|
-- ^ Whether to defer type errors, typed holes and out of scope
|
||||||
-- variables. Deferral allows the IDE to continue to provide
|
-- variables. Deferral allows the IDE to continue to provide
|
||||||
@ -84,6 +88,7 @@ defaultIdeOptions session = IdeOptions
|
|||||||
,optReportProgress = IdeReportProgress False
|
,optReportProgress = IdeReportProgress False
|
||||||
,optLanguageSyntax = "haskell"
|
,optLanguageSyntax = "haskell"
|
||||||
,optNewColonConvention = False
|
,optNewColonConvention = False
|
||||||
|
,optKeywords = haskellKeywords
|
||||||
,optDefer = IdeDefer True
|
,optDefer = IdeDefer True
|
||||||
,optTesting = False
|
,optTesting = False
|
||||||
}
|
}
|
||||||
@ -103,3 +108,23 @@ data IdePkgLocationOptions = IdePkgLocationOptions
|
|||||||
defaultIdePkgLocationOptions :: IdePkgLocationOptions
|
defaultIdePkgLocationOptions :: IdePkgLocationOptions
|
||||||
defaultIdePkgLocationOptions = IdePkgLocationOptions f f
|
defaultIdePkgLocationOptions = IdePkgLocationOptions f f
|
||||||
where f _ _ = return Nothing
|
where f _ _ = return Nothing
|
||||||
|
|
||||||
|
-- | From https://wiki.haskell.org/Keywords
|
||||||
|
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"
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user