Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 5b8cfbc

Browse files
authored
Merge pull request #996 from alanz/994-completion
Strip leading '-' from OPTIONS_GHC completions
2 parents 91ec5a0 + 8d5a10f commit 5b8cfbc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Haskell/Ide/Engine/Plugin/HieExtras.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,19 @@ getCompletions uri prefixInfo (WithSnippets withSnippets) =
422422
filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
423423
filtOptsCompls = filtListWith mkExtCompl
424424

425+
stripLeading :: Char -> String -> String
426+
stripLeading _ [] = []
427+
stripLeading c (s:ss)
428+
| s == c = ss
429+
| otherwise = s:ss
430+
425431
result
426432
| "import " `T.isPrefixOf` fullLine
427433
= filtImportCompls
428434
| "{-# language" `T.isPrefixOf` T.toLower fullLine
429435
= filtOptsCompls cachedExtensions
430436
| "{-# options_ghc" `T.isPrefixOf` T.toLower fullLine
431-
= filtOptsCompls (map T.pack $ GHC.flagsForCompletion False)
437+
= filtOptsCompls (map (T.pack . stripLeading '-') $ GHC.flagsForCompletion False)
432438
| "{-# " `T.isPrefixOf` fullLine
433439
= filtPragmaCompls (pragmaSuffix fullLine)
434440
| otherwise

test/functional/CompletionSpec.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ spec = describe "completions" $ do
115115
item ^. insertTextFormat `shouldBe` Just Snippet
116116
item ^. insertText `shouldBe` Just ("OPTIONS_GHC -${1:option} #-}")
117117

118+
-- -----------------------------------
119+
120+
it "completes ghc options pragma values" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
121+
doc <- openDoc "Completion.hs" "haskell"
122+
123+
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)
124+
125+
let te = TextEdit (Range (Position 0 0) (Position 0 0)) "{-# OPTIONS_GHC -Wno-red #-}\n"
126+
_ <- applyEdit doc te
127+
128+
compls <- getCompletions doc (Position 0 24)
129+
-- liftIO $ putStrLn $ "completions=" ++ show (map (^.label) compls)
130+
let item = head $ filter ((== "Wno-redundant-constraints") . (^. label)) compls
131+
liftIO $ putStrLn $ "item=" ++ show item
132+
liftIO $ do
133+
item ^. label `shouldBe` "Wno-redundant-constraints"
134+
item ^. kind `shouldBe` Just CiKeyword
135+
item ^. insertTextFormat `shouldBe` Nothing
136+
item ^. insertText `shouldBe` Nothing
137+
138+
-- -----------------------------------
139+
118140
it "completes with no prefix" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
119141
doc <- openDoc "Completion.hs" "haskell"
120142
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)

0 commit comments

Comments
 (0)