Skip to content

Commit b5a8063

Browse files
wz1000jhrcekmergify[bot]
authored
Exactprint plugins for 9.8 (#3973)
* Exactprint plugins for 9.8 * Fix last test * comments * fix borked cpp * Don't use CPP in refactor plugin tests * Fix -Wall, -Wunused-packages and hlint warnings in call-hierarchy plugin (#3979) * Fix -Wall and -Wunused-packages in call-hierarchy plugin * Make tests more uniform * accept func test differences * Run tests for 9.8 plugins in CI * Fix another test --------- Co-authored-by: Jan Hrcek <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 276dfd3 commit b5a8063

File tree

17 files changed

+209
-100
lines changed

17 files changed

+209
-100
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ jobs:
135135
HLS_WRAPPER_TEST_EXE: hls-wrapper
136136
run: cabal test wrapper-test --test-options="$TEST_OPTS --rerun-log-file .tasty-rerun-log-wrapper"
137137

138-
- if: matrix.test && !startsWith(matrix.ghc,'9.8')
138+
- if: matrix.test
139139
name: Test hls-refactor-plugin
140140
run: cabal test hls-refactor-plugin --test-options="$TEST_OPTS" || cabal test hls-refactor-plugin --test-options="$TEST_OPTS"
141141

142142
- if: matrix.test && matrix.ghc != '9.6' && !startsWith(matrix.ghc,'9.8')
143143
name: Test hls-floskell-plugin
144144
run: cabal test hls-floskell-plugin --test-options="$TEST_OPTS" || cabal test hls-floskell-plugin --test-options="$TEST_OPTS"
145145

146-
- if: matrix.test && !startsWith(matrix.ghc,'9.8')
146+
- if: matrix.test
147147
name: Test hls-class-plugin
148148
run: cabal test hls-class-plugin --test-options="$TEST_OPTS" || cabal test hls-class-plugin --test-options="$TEST_OPTS"
149149

@@ -155,7 +155,7 @@ jobs:
155155
name: Test hls-eval-plugin
156156
run: cabal test hls-eval-plugin --test-options="$TEST_OPTS" || cabal test hls-eval-plugin --test-options="$TEST_OPTS"
157157

158-
- if: matrix.test && !startsWith(matrix.ghc,'9.8')
158+
- if: matrix.test
159159
name: Test hls-splice-plugin
160160
run: cabal test hls-splice-plugin --test-options="$TEST_OPTS" || cabal test hls-splice-plugin --test-options="$TEST_OPTS"
161161

@@ -183,7 +183,7 @@ jobs:
183183
name: Test hls-call-hierarchy-plugin test suite
184184
run: cabal test hls-call-hierarchy-plugin --test-options="$TEST_OPTS" || cabal test hls-call-hierarchy-plugin --test-options="$TEST_OPTS"
185185

186-
- if: matrix.test && matrix.os != 'windows-latest' && !startsWith(matrix.ghc,'9.8')
186+
- if: matrix.test && matrix.os != 'windows-latest'
187187
name: Test hls-rename-plugin test suite
188188
run: cabal test hls-rename-plugin --test-options="$TEST_OPTS" || cabal test hls-rename-plugin --test-options="$TEST_OPTS"
189189

@@ -211,7 +211,7 @@ jobs:
211211
name: Test hls-change-type-signature test suite
212212
run: cabal test hls-change-type-signature-plugin --test-options="$TEST_OPTS" || cabal test hls-change-type-signature-plugin --test-options="$TEST_OPTS"
213213

214-
- if: matrix.test && !startsWith(matrix.ghc,'9.8')
214+
- if: matrix.test
215215
name: Test hls-gadt-plugin test suit
216216
run: cabal test hls-gadt-plugin --test-options="$TEST_OPTS" || cabal test hls-gadt-plugin --test-options="$TEST_OPTS"
217217

@@ -232,7 +232,7 @@ jobs:
232232
name: Test hls-cabal-plugin test suite
233233
run: cabal test hls-cabal-plugin --test-options="$TEST_OPTS" || cabal test hls-cabal-plugin --test-options="$TEST_OPTS"
234234

235-
- if: matrix.test && !startsWith(matrix.ghc,'9.8')
235+
- if: matrix.test
236236
name: Test hls-retrie-plugin test suite
237237
run: cabal test hls-retrie-plugin --test-options="$TEST_OPTS" || cabal test hls-retrie-plugin --test-options="$TEST_OPTS"
238238

ghcide/src/Development/IDE/GHC/Compat/Core.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ module Development.IDE.GHC.Compat.Core (
408408
#endif
409409
groupOrigin,
410410
isVisibleFunArg,
411+
lookupGlobalRdrEnv,
411412
) where
412413

413414
import qualified GHC
@@ -825,3 +826,7 @@ mkSimpleTarget df fp = Target (TargetFile fp Nothing) True (homeUnitId_ df) Noth
825826
#else
826827
mkSimpleTarget _ fp = Target (TargetFile fp Nothing) True Nothing
827828
#endif
829+
830+
#if MIN_VERSION_ghc(9,7,0)
831+
lookupGlobalRdrEnv gre_env occ = lookupGRE gre_env (LookupOccName occ AllRelevantGREs)
832+
#endif

haskell-language-server.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ common cabal
217217
cpp-options: -Dhls_cabal
218218

219219
common class
220-
if flag(class) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
220+
if flag(class)
221221
build-depends: hls-class-plugin == 2.6.0.0
222222
cpp-options: -Dhls_class
223223

@@ -237,12 +237,12 @@ common importLens
237237
cpp-options: -Dhls_importLens
238238

239239
common rename
240-
if flag(rename) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
240+
if flag(rename)
241241
build-depends: hls-rename-plugin == 2.6.0.0
242242
cpp-options: -Dhls_rename
243243

244244
common retrie
245-
if flag(retrie) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
245+
if flag(retrie)
246246
build-depends: hls-retrie-plugin == 2.6.0.0
247247
cpp-options: -Dhls_retrie
248248

@@ -267,7 +267,7 @@ common pragmas
267267
cpp-options: -Dhls_pragmas
268268

269269
common splice
270-
if flag(splice) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
270+
if flag(splice)
271271
build-depends: hls-splice-plugin == 2.6.0.0
272272
cpp-options: -Dhls_splice
273273

@@ -292,7 +292,7 @@ common changeTypeSignature
292292
cpp-options: -Dhls_changeTypeSignature
293293

294294
common gadt
295-
if flag(gadt) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
295+
if flag(gadt)
296296
build-depends: hls-gadt-plugin == 2.6.0.0
297297
cpp-options: -Dhls_gadt
298298

@@ -334,7 +334,7 @@ common stylishHaskell
334334
cpp-options: -Dhls_stylishHaskell
335335

336336
common refactor
337-
if flag(refactor) && (impl(ghc < 9.8.0) || flag(ignore-plugins-ghc-bounds))
337+
if flag(refactor)
338338
build-depends: hls-refactor-plugin == 2.6.0.0
339339
cpp-options: -Dhls_refactor
340340

plugins/hls-class-plugin/hls-class-plugin.cabal

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ common warnings
2929

3030
library
3131
import: warnings
32-
-- Plugins that need exactprint have not been updated for 9.8 yet
33-
if impl(ghc >= 9.8)
34-
buildable: False
35-
else
36-
buildable: True
3732
exposed-modules: Ide.Plugin.Class
3833
other-modules: Ide.Plugin.Class.CodeAction
3934
, Ide.Plugin.Class.CodeLens
@@ -66,10 +61,6 @@ library
6661

6762
test-suite tests
6863
import: warnings
69-
if impl(ghc >= 9.8)
70-
buildable: False
71-
else
72-
buildable: True
7364
type: exitcode-stdio-1.0
7465
default-language: Haskell2010
7566
hs-source-dirs: test

plugins/hls-class-plugin/src/Ide/Plugin/Class/Types.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE RecordWildCards #-}
66
{-# LANGUAGE TypeFamilies #-}
77
{-# LANGUAGE ViewPatterns #-}
8+
{-# LANGUAGE CPP #-}
89

910
module Ide.Plugin.Class.Types where
1011

@@ -207,7 +208,11 @@ getInstanceBindTypeSigsRule recorder = do
207208
(hscEnv -> hsc) <- useMT GhcSession nfp
208209
let binds = collectHsBindsBinders $ tcg_binds gblEnv
209210
(_, maybe [] catMaybes -> instanceBinds) <- liftIO $
210-
initTcWithGbl hsc gblEnv ghostSpan $ traverse bindToSig binds
211+
initTcWithGbl hsc gblEnv ghostSpan
212+
#if MIN_VERSION_ghc(9,7,0)
213+
$ liftZonkM
214+
#endif
215+
$ traverse bindToSig binds
211216
pure $ InstanceBindTypeSigsResult instanceBinds
212217
where
213218
bindToSig id = do

plugins/hls-gadt-plugin/hls-gadt-plugin.cabal

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ source-repository head
2020
location: https://github.com/haskell/haskell-language-server.git
2121

2222
library
23-
-- Plugins that need exactprint have not been updated for 9.8 yet
24-
if impl(ghc >= 9.8)
25-
buildable: False
26-
else
27-
buildable: True
2823
exposed-modules: Ide.Plugin.GADT
2924
other-modules: Ide.Plugin.GHC
3025

@@ -55,10 +50,6 @@ library
5550
default-extensions: DataKinds
5651

5752
test-suite tests
58-
if impl(ghc >= 9.8)
59-
buildable: False
60-
else
61-
buildable: True
6253
type: exitcode-stdio-1.0
6354
default-language: Haskell2010
6455
hs-source-dirs: test

plugins/hls-gadt-plugin/test/Main.hs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,8 @@ tests = testGroup "GADT"
3535
, runTest "ConstructorContext" "ConstructorContext" 2 0 2 38
3636
, runTest "Context" "Context" 2 0 4 41
3737
, runTest "Pragma" "Pragma" 2 0 3 29
38-
, onlyWorkForGhcVersions (`elem`[GHC92, GHC94, GHC96]) "Single deriving has different output on ghc9.2+" $
39-
runTest "SingleDerivingGHC92" "SingleDerivingGHC92" 2 0 3 14
40-
, knownBrokenForGhcVersions [GHC92,GHC94,GHC96] "Single deriving has different output on ghc9.2+" $
41-
runTest "SingleDeriving" "SingleDeriving" 2 0 3 14
42-
, onlyWorkForGhcVersions (`elem`[GHC92, GHC94, GHC96]) "only ghc-9.2+ enabled GADTs pragma implicitly" $
43-
gadtPragmaTest "ghc-9.2 don't need to insert GADTs pragma" False
44-
, knownBrokenForGhcVersions [GHC92,GHC94,GHC96] "ghc-9.2 has enabled GADTs pragma implicitly" $
45-
gadtPragmaTest "insert pragma" True
38+
, runTest "SingleDerivingGHC92" "SingleDerivingGHC92" 2 0 3 14
39+
, gadtPragmaTest "ghc-9.2 don't need to insert GADTs pragma" False
4640
]
4741

4842
gadtPragmaTest :: TestName -> Bool -> TestTree

plugins/hls-refactor-plugin/hls-refactor-plugin.cabal

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ common warnings
2626

2727
library
2828
import: warnings
29-
-- Plugins that need exactprint have not been updated for 9.8 yet
30-
if impl(ghc >= 9.8)
31-
buildable: False
32-
else
33-
buildable: True
3429
exposed-modules: Development.IDE.GHC.ExactPrint
3530
Development.IDE.GHC.Compat.ExactPrint
3631
Development.IDE.Plugin.CodeAction
@@ -102,10 +97,6 @@ library
10297

10398
test-suite tests
10499
import: warnings
105-
if impl(ghc >= 9.8)
106-
buildable: False
107-
else
108-
buildable: True
109100
type: exitcode-stdio-1.0
110101
default-language: Haskell2010
111102
hs-source-dirs: test

plugins/hls-refactor-plugin/src/Development/IDE/GHC/Dump.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ showAstDataHtml a0 = html $
123123

124124
sourceText :: SourceText -> SDoc
125125
sourceText NoSourceText = text "NoSourceText"
126+
#if MIN_VERSION_ghc(9,7,0)
127+
sourceText (SourceText src) = text "SourceText" <+> ftext src
128+
#else
126129
sourceText (SourceText src) = text "SourceText" <+> text src
130+
#endif
127131

128132
epaAnchor :: EpaLocation -> SDoc
129133
#if MIN_VERSION_ghc(9,5,0)

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,11 @@ suggestExtendImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T.Text, Cod
938938
suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_range,..}
939939
| Just [binding, mod, srcspan] <-
940940
matchRegexUnifySpaces _message
941+
#if MIN_VERSION_ghc(9,7,0)
942+
"Add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\(at (.*)\\)."
943+
#else
941944
"Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\((.*)\\)."
945+
#endif
942946
= suggestions hsmodImports binding mod srcspan
943947
| Just (binding, mod_srcspan) <-
944948
matchRegExMultipleImports _message
@@ -965,9 +969,13 @@ suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_
965969
| otherwise = []
966970
lookupExportMap binding mod
967971
| let em = getExportsMap exportsMap
972+
#if MIN_VERSION_ghc(9,7,0)
973+
match = mconcat $ lookupOccEnv_AllNameSpaces em (mkVarOrDataOcc binding)
974+
#else
968975
match1 = lookupOccEnv em (mkVarOrDataOcc binding)
969976
match2 = lookupOccEnv em (mkTypeOcc binding)
970977
, Just match <- match1 <> match2
978+
#endif
971979
-- Only for the situation that data constructor name is same as type constructor name,
972980
-- let ident with parent be in front of the one without.
973981
, sortedMatch <- sortBy (\ident1 ident2 -> parent ident2 `compare` parent ident1) (Set.toList match)
@@ -1165,9 +1173,20 @@ suggestFixConstructorImport Diagnostic{_range=_range,..}
11651173
-- import Data.Aeson.Types( Result( Success ) )
11661174
-- or
11671175
-- import Data.Aeson.Types( Result(..) ) (lsp-ui)
1176+
--
1177+
-- On 9.8+
1178+
--
1179+
-- In the import of ‘ModuleA’:
1180+
-- an item called ‘Constructor’
1181+
-- is exported, but it is a data constructor of
1182+
-- ‘A’.
11681183
| Just [constructor, typ] <-
11691184
matchRegexUnifySpaces _message
1185+
#if MIN_VERSION_ghc(9,7,0)
1186+
"an item called ‘([^’]*)’ is exported, but it is a data constructor of ‘([^’]*)’"
1187+
#else
11701188
"‘([^’]*)’ is a data constructor of ‘([^’]*)’ To import it use"
1189+
#endif
11711190
= let fixedImport = typ <> "(" <> constructor <> ")"
11721191
in [("Fix import of " <> fixedImport, TextEdit _range fixedImport)]
11731192
| otherwise = []
@@ -1434,7 +1453,11 @@ suggestNewImport df packageExportsMap ps fileContents Diagnostic{..}
14341453
*> extractQualifiedModuleNameFromMissingName (extractTextInRange _range fileContents)
14351454
, Just (range, indent) <- newImportInsertRange ps fileContents
14361455
, extendImportSuggestions <- matchRegexUnifySpaces msg
1456+
#if MIN_VERSION_ghc(9,7,0)
1457+
"Add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1458+
#else
14371459
"Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1460+
#endif
14381461
= let qis = qualifiedImportStyle df
14391462
-- FIXME: we can use thingMissing once the support for GHC 9.4 is dropped.
14401463
-- In what fllows, @missing@ is assumed to be qualified name.
@@ -1952,30 +1975,32 @@ regexSingleMatch msg regex = case matchRegexUnifySpaces msg regex of
19521975
Just (h:_) -> Just h
19531976
_ -> Nothing
19541977

1955-
-- | Parses tuples like (‘Data.Map’, (app/ModuleB.hs:2:1-18)) and
1956-
-- | return (Data.Map, app/ModuleB.hs:2:1-18)
1957-
regExPair :: (T.Text, T.Text) -> Maybe (T.Text, T.Text)
1958-
regExPair (modname, srcpair) = do
1959-
x <- regexSingleMatch modname "‘([^’]*)’"
1960-
y <- regexSingleMatch srcpair "\\((.*)\\)"
1961-
return (x, y)
1962-
19631978
-- | Process a list of (module_name, filename:src_span) values
19641979
-- | Eg. [(Data.Map, app/ModuleB.hs:2:1-18), (Data.HashMap.Strict, app/ModuleB.hs:3:1-29)]
19651980
regExImports :: T.Text -> Maybe [(T.Text, T.Text)]
1966-
regExImports msg = result
1967-
where
1968-
parts = T.words msg
1969-
isPrefix = not . T.isPrefixOf "("
1970-
(mod, srcspan) = partition isPrefix parts
1971-
-- check we have matching pairs like (Data.Map, (app/src.hs:1:2-18))
1972-
result = if length mod == length srcspan then
1973-
regExPair `traverse` zip mod srcspan
1974-
else Nothing
1981+
regExImports msg
1982+
| Just mods' <- allMatchRegex msg "‘([^’]*)’"
1983+
, Just srcspans' <- allMatchRegex msg
1984+
#if MIN_VERSION_ghc(9,7,0)
1985+
"\\(at ([^)]*)\\)"
1986+
#else
1987+
"\\(([^)]*)\\)"
1988+
#endif
1989+
, mods <- [mod | [_,mod] <- mods']
1990+
, srcspans <- [srcspan | [_,srcspan] <- srcspans']
1991+
-- check we have matching pairs like (Data.Map, (app/src.hs:1:2-18))
1992+
, let result = if length mods == length srcspans then
1993+
Just (zip mods srcspans) else Nothing
1994+
= result
1995+
| otherwise = Nothing
19751996

19761997
matchRegExMultipleImports :: T.Text -> Maybe (T.Text, [(T.Text, T.Text)])
19771998
matchRegExMultipleImports message = do
1999+
#if MIN_VERSION_ghc(9,7,0)
2000+
let pat = T.pack "Add ‘([^’]*)’ to one of these import lists: *(‘.*\\))$"
2001+
#else
19782002
let pat = T.pack "Perhaps you want to add ‘([^’]*)’ to one of these import lists: *(‘.*\\))$"
2003+
#endif
19792004
(binding, imports) <- case matchRegexUnifySpaces message pat of
19802005
Just [x, xs] -> Just (x, xs)
19812006
_ -> Nothing

0 commit comments

Comments
 (0)