on master help sign in
Keywords in completion (#351)

* Keywords in completion * Update src/Development/IDE/Core/Completions.hs Co-Authored-By: fendor <fendor@users.noreply.github.com> * Fix the other usage of "keywrd" Co-authored-by: fendor <fendor@users.noreply.github.com>

commit1d32025e937c0920a06eeee30aba6811f21f7021 authorAlejandro Serrano <trupill@gmail.com> dateSat 25 Jan 2020, 09:36 (7 years ago) parenteb0c0ea
2 files changed+45
src/Development/IDE/Core/Completions.hs+23 test/exe/Main.hs+22
src/Development/IDE/Core/Completions.hs+23
@@ -361,6 +361,7 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
361361 filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
362362 filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
363363 filtOptsCompls = filtListWith mkExtCompl
364+ filtKeywordCompls = if T.null prefixModule then filtListWith mkExtCompl keywords else []
364365
365366 stripLeading :: Char -> String -> String
366367 stripLeading _ [] = []
@@ -380,6 +381,7 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
380381 | otherwise
381382 = filtModNameCompls ++ map (toggleSnippets caps withSnippets
382383 . mkCompl ideOpts . stripAutoGenerated) filtCompls
384+ ++ filtKeywordCompls
383385
384386 return result
385387
@@ -509,3 +511,24 @@ prefixes =
509511 , "$c"
510512 , "$m"
511513 ]
514+
515+keywords :: [T.Text]
516+keywords =
517+ [
518+ -- From https://wiki.haskell.org/Keywords
519+ "as"
520+ , "case", "of"
521+ , "class", "instance", "type"
522+ , "data", "family", "newtype"
523+ , "default"
524+ , "deriving"
525+ , "do", "mdo", "proc", "rec"
526+ , "forall"
527+ , "foreign"
528+ , "hiding"
529+ , "if", "then", "else"
530+ , "import", "qualified", "hiding"
531+ , "infix", "infixl", "infixr"
532+ , "let", "in", "where"
533+ , "module"
534+ ]
test/exe/Main.hs+22
@@ -1354,6 +1354,11 @@ completionTests
13541354 , "Extract the first element of a list"
13551355#endif
13561356 ]
1357+ , testSessionWait "keyword" $ do
1358+ let source = T.unlines ["module A where", "f = newty"]
1359+ docId <- openDoc' "A.hs" "haskell" source
1360+ compls <- getCompletions docId (Position 1 9)
1361+ liftIO $ compls @?= [keywordItem "newtype"]
13571362 ]
13581363 where
13591364 dropDocs :: CompletionItem -> CompletionItem
@@ -1375,6 +1380,23 @@ completionTests
13751380 , _command = Nothing
13761381 , _xdata = Nothing
13771382 }
1383+ keywordItem label = CompletionItem
1384+ { _label = label
1385+ , _kind = Just CiKeyword
1386+ , _detail = Nothing
1387+ , _documentation = Nothing
1388+ , _deprecated = Nothing
1389+ , _preselect = Nothing
1390+ , _sortText = Nothing
1391+ , _filterText = Nothing
1392+ , _insertText = Nothing
1393+ , _insertTextFormat = Nothing
1394+ , _textEdit = Nothing
1395+ , _additionalTextEdits = Nothing
1396+ , _commitCharacters = Nothing
1397+ , _command = Nothing
1398+ , _xdata = Nothing
1399+ }
13781400 getDocText (CompletionDocString s) = s
13791401 getDocText (CompletionDocMarkup (MarkupContent _ s)) = s
13801402 checkDocText thing Nothing _