diff --git a/plugins/default/src/Ide/Plugin/Pragmas.hs b/plugins/default/src/Ide/Plugin/Pragmas.hs index ca595873f2..a74a26ae3b 100644 --- a/plugins/default/src/Ide/Plugin/Pragmas.hs +++ b/plugins/default/src/Ide/Plugin/Pragmas.hs @@ -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 + ] -- --------------------------------------------------------------------- @@ -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 [] diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs index a07988f12e..a3e7e149a4 100644 --- a/test/functional/Completion.hs +++ b/test/functional/Completion.hs @@ -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"