Skip to content

Commit 50854ca

Browse files
authored
Complete the No- variants of language extensions (#1238)
Fixes #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`.
1 parent 2ad9eb0 commit 50854ca

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

plugins/default/src/Ide/Plugin/Pragmas.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,26 @@ findPragma str = concatMap check possiblePragmas
9999
where
100100
check p = [p | T.isInfixOf p str]
101101

102+
-- We exclude the Strict extension as it causes many false positives, see
103+
-- the discussion at https://github.com/haskell/ghcide/pull/638
104+
--
105+
-- We don't include the No- variants, as GHC never suggests disabling an
106+
-- extension in an error message.
107+
possiblePragmas :: [T.Text]
108+
possiblePragmas =
109+
[ name
110+
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
111+
, "Strict" /= name
112+
]
113+
102114
-- ---------------------------------------------------------------------
103115

104-
-- | Possible Pragma names.
105-
-- See discussion at https://github.com/haskell/ghcide/pull/638
106-
possiblePragmas :: [T.Text]
107-
possiblePragmas = [name | FlagSpec{flagSpecName = T.pack -> name} <- xFlags, "Strict" /= name]
116+
-- | All language pragmas, including the No- variants
117+
allPragmas :: [T.Text]
118+
allPragmas = concat
119+
[ [name, "No" <> name]
120+
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
121+
]
108122

109123
-- ---------------------------------------------------------------------
110124

@@ -120,7 +134,7 @@ completion lspFuncs _ide complParams = do
120134
where
121135
result (Just pfix)
122136
| "{-# LANGUAGE" `T.isPrefixOf` VFS.fullLine pfix
123-
= Completions $ List $ map buildCompletion possiblePragmas
137+
= Completions $ List $ map buildCompletion allPragmas
124138
| otherwise
125139
= Completions $ List []
126140
result Nothing = Completions $ List []

test/functional/Completion.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ tests = testGroup "completions" [
9494
item ^. label @?= "OverloadedStrings"
9595
item ^. kind @?= Just CiKeyword
9696

97+
, testCase "completes the Strict language extension" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
98+
doc <- openDoc "Completion.hs" "haskell"
99+
100+
_ <- waitForDiagnostics
101+
102+
let te = TextEdit (Range (Position 0 13) (Position 0 31)) "Str"
103+
_ <- applyEdit doc te
104+
105+
compls <- getCompletions doc (Position 0 24)
106+
let item = head $ filter ((== "Strict") . (^. label)) compls
107+
liftIO $ do
108+
item ^. label @?= "Strict"
109+
item ^. kind @?= Just CiKeyword
110+
111+
, testCase "completes No- language extensions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
112+
doc <- openDoc "Completion.hs" "haskell"
113+
114+
_ <- waitForDiagnostics
115+
116+
let te = TextEdit (Range (Position 0 13) (Position 0 31)) "NoOverload"
117+
_ <- applyEdit doc te
118+
119+
compls <- getCompletions doc (Position 0 24)
120+
let item = head $ filter ((== "NoOverloadedStrings") . (^. label)) compls
121+
liftIO $ do
122+
item ^. label @?= "NoOverloadedStrings"
123+
item ^. kind @?= Just CiKeyword
124+
97125
, testCase "completes pragmas" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
98126
doc <- openDoc "Completion.hs" "haskell"
99127

0 commit comments

Comments
 (0)