Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete the No- variants of language extensions and Strict extension #1238

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

mrBliss marked this conversation as resolved.
Show resolved Hide resolved
, testCase "completes pragmas" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "Completion.hs" "haskell"

Expand Down