on master help sign in
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).

commit73ad8af648353acb280a7f8e9a1eb11b7d4eb67d authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateFri 20 Mar 2020, 10:05 (7 years ago) parent7ecdd21
2 files changed+28−22
src/Development/IDE/Plugin/Completions/Logic.hs+3−22 src/Development/IDE/Types/Options.hs+25
src/Development/IDE/Plugin/Completions/Logic.hs+3−22
@@ -373,7 +373,9 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
373373 filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
374374 filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
375375 filtOptsCompls = filtListWith mkExtCompl
376− filtKeywordCompls = if T.null prefixModule then filtListWith mkExtCompl keywords else []
376+ filtKeywordCompls
377+ | T.null prefixModule = filtListWith mkExtCompl (optKeywords ideOpts)
378+ | otherwise = []
377379
378380 stripLeading :: Char -> String -> String
379381 stripLeading _ [] = []
@@ -527,24 +529,3 @@ prefixes =
527529 , "$c"
528530 , "$m"
529531 ]
530−
531−keywords :: [T.Text]
532−keywords =
533− [
534− -- From https://wiki.haskell.org/Keywords
535− "as"
536− , "case", "of"
537− , "class", "instance", "type"
538− , "data", "family", "newtype"
539− , "default"
540− , "deriving"
541− , "do", "mdo", "proc", "rec"
542− , "forall"
543− , "foreign"
544− , "hiding"
545− , "if", "then", "else"
546− , "import", "qualified", "hiding"
547− , "infix", "infixl", "infixr"
548− , "let", "in", "where"
549− , "module"
550− ]
src/Development/IDE/Types/Options.hs+25
@@ -19,6 +19,7 @@ import Development.IDE.GHC.Util
1919import GHC hiding (parseModule, typecheckModule)
2020import GhcPlugins as GHC hiding (fst3, (<>))
2121import qualified Language.Haskell.LSP.Types.Capabilities as LSP
22+import qualified Data.Text as T
2223
2324data IdeOptions = IdeOptions
2425 { optPreprocessor :: GHC.ParsedSource -> IdePreprocessedSource
@@ -48,6 +49,9 @@ data IdeOptions = IdeOptions
4849 -- ^ the ```language to use
4950 , optNewColonConvention :: Bool
5051 -- ^ 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.
5155 , optDefer :: IdeDefer
5256 -- ^ Whether to defer type errors, typed holes and out of scope
5357 -- variables. Deferral allows the IDE to continue to provide
@@ -84,6 +88,7 @@ defaultIdeOptions session = IdeOptions
8488 ,optReportProgress = IdeReportProgress False
8589 ,optLanguageSyntax = "haskell"
8690 ,optNewColonConvention = False
91+ ,optKeywords = haskellKeywords
8792 ,optDefer = IdeDefer True
8893 ,optTesting = False
8994 }
@@ -103,3 +108,23 @@ data IdePkgLocationOptions = IdePkgLocationOptions
103108defaultIdePkgLocationOptions :: IdePkgLocationOptions
104109defaultIdePkgLocationOptions = IdePkgLocationOptions f f
105110 where f _ _ = return Nothing
111+
112+-- | From https://wiki.haskell.org/Keywords
113+haskellKeywords :: [T.Text]
114+haskellKeywords =
115+ [ "as"
116+ , "case", "of"
117+ , "class", "instance", "type"
118+ , "data", "family", "newtype"
119+ , "default"
120+ , "deriving"
121+ , "do", "mdo", "proc", "rec"
122+ , "forall"
123+ , "foreign"
124+ , "hiding"
125+ , "if", "then", "else"
126+ , "import", "qualified", "hiding"
127+ , "infix", "infixl", "infixr"
128+ , "let", "in", "where"
129+ , "module"
130+ ]