Skip to content

Commit

Permalink
Complete the No- variants of language extensions
Browse files Browse the repository at this point in the history
Fixes haskell#1187.

Separate the list of pragmas used for completion from the list of pragmas used
to suggest enabling a language extension to fix an error. The former now include
the `No-` variants of the language extensions, e.g., `NoDuplicateRecordFields`.
  • Loading branch information
mrBliss committed Jan 20, 2021
1 parent 2ad9eb0 commit 8f58652
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
24 changes: 19 additions & 5 deletions plugins/default/src/Ide/Plugin/Pragmas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,26 @@ findPragma str = concatMap check possiblePragmas
where
check p = [p | T.isInfixOf p str]

-- We exclude the Strict extension as it causes many false positives, see
-- the discussion at https://github.com/haskell/ghcide/pull/638
--
-- We don't include the No- variants, as GHC never suggests disabling an
-- extension in an error message.
possiblePragmas :: [T.Text]
possiblePragmas =
[ name
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
, "Strict" /= name
]

-- ---------------------------------------------------------------------

-- | Possible Pragma names.
-- See discussion at https://github.com/haskell/ghcide/pull/638
possiblePragmas :: [T.Text]
possiblePragmas = [name | FlagSpec{flagSpecName = T.pack -> name} <- xFlags, "Strict" /= name]
-- | All language pragmas, including the No- variants
allPragmas :: [T.Text]
allPragmas = concat
[ [name, "No" <> name]
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
]

-- ---------------------------------------------------------------------

Expand All @@ -120,7 +134,7 @@ completion lspFuncs _ide complParams = do
where
result (Just pfix)
| "{-# LANGUAGE" `T.isPrefixOf` VFS.fullLine pfix
= Completions $ List $ map buildCompletion possiblePragmas
= Completions $ List $ map buildCompletion allPragmas
| otherwise
= Completions $ List []
result Nothing = Completions $ List []
Expand Down
28 changes: 28 additions & 0 deletions test/functional/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,34 @@ tests = testGroup "completions" [
item ^. label @?= "OverloadedStrings"
item ^. kind @?= Just CiKeyword

, testCase "completes the Strict language extension" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "Completion.hs" "haskell"

_ <- waitForDiagnostics

let te = TextEdit (Range (Position 0 13) (Position 0 31)) "Str"
_ <- applyEdit doc te

compls <- getCompletions doc (Position 0 24)
let item = head $ filter ((== "Strict") . (^. label)) compls
liftIO $ do
item ^. label @?= "Strict"
item ^. kind @?= Just CiKeyword

, testCase "completes No- language extensions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "Completion.hs" "haskell"

_ <- waitForDiagnostics

let te = TextEdit (Range (Position 0 13) (Position 0 31)) "NoOverload"
_ <- applyEdit doc te

compls <- getCompletions doc (Position 0 24)
let item = head $ filter ((== "NoOverloadedStrings") . (^. label)) compls
liftIO $ do
item ^. label @?= "NoOverloadedStrings"
item ^. kind @?= Just CiKeyword

, testCase "completes pragmas" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "Completion.hs" "haskell"

Expand Down

0 comments on commit 8f58652

Please sign in to comment.