Skip to content

Commit c14cbdb

Browse files
Support hls-hlint-plugin and hls-stylish-plugin for ghc9.0 and ghc9.2 (#2854)
* hls-hlint-plugin & hls-stylish-haskell-plugin rush to ghc92 * Restore allow-newer * Add BufSpan for lower version ghc * Add Cabal constraint for stack-9.0.1.yaml * Try ghc-lib-parser for BufSpan * Loose tactic compiling constraint * Rename hlint34 * Rerun test * Update doc * Comment ghc-exactprint requirements * Add test for apply-refact-0.10 * Use hackage stylish-haskell * ghc-exactprint constraints for hls-class-plugin * Remove uncompiled if Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a541ae8 commit c14cbdb

File tree

22 files changed

+123
-92
lines changed

22 files changed

+123
-92
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ jobs:
190190
name: Test hls-splice-plugin
191191
run: cabal test hls-splice-plugin --test-options="$TEST_OPTS" || cabal test hls-splice-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-splice-plugin --test-options="$TEST_OPTS"
192192

193-
- if: matrix.test && matrix.ghc != '9.0.1' && matrix.ghc != '9.0.2'
193+
- if: matrix.test
194194
name: Test hls-stylish-haskell-plugin
195195
run: cabal test hls-stylish-haskell-plugin --test-options="$TEST_OPTS" || cabal test hls-stylish-haskell-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-stylish-haskell-plugin --test-options="$TEST_OPTS"
196196

@@ -222,7 +222,7 @@ jobs:
222222
name: Test hls-rename-plugin test suite
223223
run: cabal test hls-rename-plugin --test-options="$TEST_OPTS" || cabal test hls-rename-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-rename-plugin --test-options="$TEST_OPTS"
224224

225-
- if: matrix.test && matrix.ghc != '9.2.2'
225+
- if: matrix.test
226226
name: Test hls-hlint-plugin test suite
227227
run: cabal test hls-hlint-plugin --test-options="$TEST_OPTS" || cabal test hls-hlint-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-hlint-plugin --test-options="$TEST_OPTS"
228228

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The official Haskell language server (LSP) implementation. Consult the [project
3030

3131
- [Features](https://haskell-language-server.readthedocs.io/en/latest/features.html)
3232
- [Installation](https://haskell-language-server.readthedocs.io/en/latest/installation.html)
33+
- [Supported GHC Versions](https://haskell-language-server.readthedocs.io/en/latest/supported-versions.html)
3334
- [Configuration](https://haskell-language-server.readthedocs.io/en/latest/configuration.html)
3435
- [Troubleshooting](https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html)
3536
- [Contributing](https://haskell-language-server.readthedocs.io/en/latest/contributing/index.html)

cabal-ghc90.project

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ package *
3737

3838
write-ghc-environment-files: never
3939

40-
index-state: 2022-03-08T10:53:01Z
40+
index-state: 2022-04-27T09:22:49Z
4141

4242
constraints:
43-
-- These plugins don't work on GHC9 yet
44-
-- Add a plugin needs remove the -flag but also update ghc bounds in hls.cabal
45-
haskell-language-server +ignore-plugins-ghc-bounds -stylishhaskell,
46-
ghc-lib-parser ^>= 9.0
43+
hls-hlint-plugin +ghc-lib
4744

4845
-- although we are not building all plugins cabal solver phase is run for all packages
4946
-- this way we track explicitly all transitive dependencies which need support for ghc-9
@@ -57,10 +54,6 @@ allow-newer:
5754
-- https://github.com/lspitzner/butcher/pull/8
5855
butcher:base,
5956

60-
stylish-haskell:Cabal,
61-
stylish-haskell:ghc-lib-parser,
62-
stylish-haskell:aeson,
63-
6457
-- ghc-9.0.2 specific
6558
-- for ghcide:test via ghc-typelits-knownnat
6659
ghc-typelits-natnormalise:ghc-bignum

cabal-ghc92.project

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ package *
3939

4040
write-ghc-environment-files: never
4141

42-
index-state: 2022-04-19T07:18:40Z
42+
index-state: 2022-04-27T09:22:49Z
4343

4444
constraints:
4545
-- These plugins don't build/work on GHC92 yet
4646
haskell-language-server
4747
+ignore-plugins-ghc-bounds
4848
-brittany
4949
-haddockComments
50-
-hlint
5150
-retrie
5251
-splice
5352
-tactic,
53+
hls-hlint-plugin +ghc-lib,
54+
-- # Use ghc-lib force instead of ghc itself
55+
ghc-lib-parser-ex -auto,
56+
hlint +ghc-lib,
57+
stylish-haskell +ghc-lib
5458

5559
allow-newer:
5660
-- for shake-bench
@@ -73,19 +77,6 @@ allow-newer:
7377
-- https://github.com/lspitzner/butcher/pull/8
7478
butcher:base,
7579

76-
ormolu:ghc-lib-parser,
77-
78-
fourmolu:ghc-lib-parser,
79-
fourmolu:Cabal,
80-
81-
hls-hlint-plugin:ghc-lib,
82-
hls-hlint-plugin:ghc-lib-parser,
83-
hls-hlint-plugin:ghc-lib-parser-ex,
84-
hlint:ghc-lib-parser,
85-
hlint:ghc-lib-parser-ex,
86-
-- See https://github.com/mpickering/apply-refact/pull/116
87-
apply-refact:base,
88-
8980
implicit-hie-cradle:bytestring,
9081
implicit-hie-cradle:time,
9182

@@ -95,7 +86,8 @@ allow-newer:
9586
-- for ghcide:test via ghc-typelits-knownnat
9687
ghc-typelits-natnormalise:ghc-bignum,
9788

98-
hiedb:base
89+
hiedb:base,
90+
retrie:ghc-exactprint
9991

10092
allow-older:
10193
primitive-extras:primitive-unlifted

docs/supported-versions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
4343
| `hls-floskell-plugin` | |
4444
| `hls-fourmolu-plugin` | |
4545
| `hls-haddock-comments-plugin` | 9.2 |
46-
| `hls-hlint-plugin` | 9.2 |
46+
| `hls-hlint-plugin` | |
4747
| `hls-module-name-plugin` | |
4848
| `hls-ormolu-plugin` | |
4949
| `hls-pragmas-plugin` | |
@@ -52,7 +52,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
5252
| `hls-rename-plugin` | |
5353
| `hls-retrie-plugin` | 9.2 |
5454
| `hls-splice-plugin` | 9.2 |
55-
| `hls-stylish-haskell-plugin` | 9.0 |
55+
| `hls-stylish-haskell-plugin` | |
5656
| `hls-tactics-plugin` | 9.2 |
5757
| `hls-selection-range-plugin` | |
5858

haskell-language-server.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ common example-plugins
224224
Ide.Plugin.Example2
225225

226226
common class
227-
if flag(class) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
227+
if flag(class)
228228
build-depends: hls-class-plugin ^>= 1.0
229229
cpp-options: -Dclass
230230

@@ -264,12 +264,12 @@ common retrie
264264
cpp-options: -Dretrie
265265

266266
common tactic
267-
if flag(tactic) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
267+
if flag(tactic) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
268268
build-depends: hls-tactics-plugin >=1.2.0.0 && <1.7
269269
cpp-options: -Dtactic
270270

271271
common hlint
272-
if flag(hlint) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
272+
if flag(hlint)
273273
build-depends: hls-hlint-plugin ^>= 1.0
274274
cpp-options: -Dhlint
275275

@@ -326,7 +326,7 @@ common ormolu
326326
cpp-options: -Dormolu
327327

328328
common stylishHaskell
329-
if flag(stylishHaskell) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
329+
if flag(stylishHaskell)
330330
build-depends: hls-stylish-haskell-plugin ^>= 1.0
331331
cpp-options: -DstylishHaskell
332332

hls-test-utils/src/Test/Hls/Util.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Test.Hls.Util
2525
, noLiteralCaps
2626
, ignoreForGhcVersions
2727
, ignoreInEnv
28+
, onlyRunForGhcVersions
2829
, inspectCodeAction
2930
, inspectCommand
3031
, inspectDiagnostic
@@ -148,6 +149,12 @@ ignoreInEnv envSpecs reason
148149
ignoreForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
149150
ignoreForGhcVersions vers = ignoreInEnv (map GhcVer vers)
150151

152+
onlyRunForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
153+
onlyRunForGhcVersions vers =
154+
if ghcVersion `elem` vers
155+
then const id
156+
else ignoreTestBecause
157+
151158
-- ---------------------------------------------------------------------
152159

153160
hieYamlCradleDirectContents :: String
@@ -362,7 +369,7 @@ actual `expectSameLocations` expected = do
362369

363370
-- ---------------------------------------------------------------------
364371
getCompletionByLabel :: MonadIO m => T.Text -> [CompletionItem] -> m CompletionItem
365-
getCompletionByLabel desiredLabel compls =
372+
getCompletionByLabel desiredLabel compls =
366373
case find (\c -> c ^. L.label == desiredLabel) compls of
367374
Just c -> pure c
368375
Nothing -> liftIO . assertFailure $

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ library
2828
, base >=4.12 && <5
2929
, containers
3030
, ghc
31-
, ghc-exactprint >= 0.6.4
3231
, ghcide ^>=1.7
3332
, hls-plugin-api ^>=1.4
3433
, lens
3534
, lsp
3635
, text
3736
, transformers
3837

38+
if impl(ghc >=9.2.1)
39+
build-depends: ghc-exactprint ^>= 1.5
40+
else
41+
build-depends: ghc-exactprint >= 0.6.4 && <1.1
42+
3943
default-language: Haskell2010
4044
default-extensions:
4145
DataKinds

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ addMethodPlaceholders state AddMinimalMethodsParams{..} = do
128128
addWhere decl = decl
129129

130130
newLine (L l e) =
131-
let dp = deltaPos 1 (indent + 1) -- Not sure why there need one more space
131+
let dp = deltaPos 1 indent
132132
in L (noAnnSrcSpanDP (locA l) dp <> l) e
133133

134134
#else

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ library
2323
build-depends:
2424
, base >=4.12 && <5
2525
, filepath
26-
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.5
26+
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6
2727
, ghc
2828
, ghc-boot-th
2929
, ghcide ^>=1.7

plugins/hls-hlint-plugin/hls-hlint-plugin.cabal

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@ flag ghc-lib
3131
description:
3232
Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported
3333

34-
flag hlint33
34+
flag hlint34
3535
default: True
3636
manual: False
3737
description:
38-
Hlint-3.3 doesn't support versions ghc-lib < 9.0.1 nor ghc <= 8.6, so we can use hlint-3.2 for backwards compat
38+
Hlint-3.4 doesn't support versions ghc-lib < 9.0.1 nor ghc <= 8.6, so we can use hlint-3.2 for backwards compat
3939
This flag can be removed when all dependencies support ghc-lib-9.0.* and we drop support for ghc-8.6
4040

4141
library
4242
exposed-modules: Ide.Plugin.Hlint
4343
hs-source-dirs: src
4444
build-depends:
4545
, aeson
46-
, apply-refact >=0.9.3.0
4746
, base >=4.12 && <5
4847
, binary
4948
, bytestring
@@ -69,30 +68,32 @@ library
6968
, text
7069
, transformers
7170
, unordered-containers
71+
, apply-refact >=0.9.0.0
7272
-- can be removed if https://github.com/ndmitchell/hlint/pull/1325#issue-1077062712 is merged
7373
-- and https://github.com/haskell/haskell-language-server/pull/2464#issue-1077133441 is updated
7474
-- accordingly
7575
, ghc-lib-parser-ex
7676

77-
if (flag(hlint33))
77+
if (flag(hlint34))
7878
-- This mirrors the logic in hlint.cabal for hlint-3.3
7979
-- https://github.com/ndmitchell/hlint/blob/d3576de4529d8df6cca5a345f5b7e04474ff7bff/hlint.cabal#L79-L88
8080
-- so we can make sure that we do the same thing as hlint
81-
build-depends: hlint ^>=3.3
81+
build-depends: hlint ^>=3.4
82+
8283
if (!flag(ghc-lib) && impl(ghc >=9.0.1) && impl(ghc <9.1.0))
83-
build-depends: ghc ==9.0.*
84+
build-depends: ghc ==9.0.*
8485
else
8586
build-depends:
86-
, ghc
87-
, ghc-lib ^>=9.0
88-
, ghc-lib-parser-ex ^>=9.0
87+
, ghc-lib ^>=9.2
88+
, ghc-lib-parser-ex ^>=9.2
89+
, ghc-lib-parser ^>=9.2
8990

9091
cpp-options: -DHLINT_ON_GHC_LIB
9192

9293
else
9394
-- This mirrors the logic in hlint.cabal for hlint-3.2
9495
-- https://github.com/ndmitchell/hlint/blob/c7354e473c7d09213c8adc3dc94bf50a6eb4a42d/hlint.cabal#L79-L88
95-
build-depends: hlint ^>=3.2
96+
build-depends: hlint ^>=3.2
9697
if (!flag(ghc-lib) && impl(ghc >=8.10.1) && impl(ghc < 8.11.0))
9798
build-depends: ghc >=8.10 && <9.0
9899
else

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ import qualified Refact.Apply as Refact
6060
import qualified Refact.Types as Refact
6161

6262
#ifdef HLINT_ON_GHC_LIB
63-
import Development.IDE.GHC.Compat (BufSpan,
64-
DynFlags,
63+
import Development.IDE.GHC.Compat (DynFlags,
6564
WarningFlag (Opt_WarnUnrecognisedPragmas),
6665
extensionFlags,
6766
ms_hspp_opts,
@@ -73,6 +72,9 @@ import "ghc-lib" GHC hiding
7372
RealSrcSpan,
7473
ms_hspp_opts)
7574
import qualified "ghc-lib" GHC
75+
#if MIN_GHC_API_VERSION(9,0,0)
76+
import "ghc-lib-parser" GHC.Types.SrcLoc (BufSpan)
77+
#endif
7678
import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
7779
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension)
7880
import System.FilePath (takeFileName)
@@ -89,7 +91,11 @@ import System.IO.Temp
8991
import Development.IDE.GHC.Compat hiding
9092
(setEnv, (<+>))
9193
import GHC.Generics (Associativity (LeftAssociative, NotAssociative, RightAssociative))
94+
#if MIN_GHC_API_VERSION(9,2,0)
95+
import Language.Haskell.GHC.ExactPrint.ExactPrint (deltaOptions)
96+
#else
9297
import Language.Haskell.GHC.ExactPrint.Delta (deltaOptions)
98+
#endif
9399
import Language.Haskell.GHC.ExactPrint.Parsers (postParseTransform)
94100
import Language.Haskell.GHC.ExactPrint.Types (Rigidity (..))
95101
import Language.Haskell.GhclibParserEx.Fixity as GhclibParserEx (applyFixities)
@@ -141,12 +147,15 @@ instance Pretty Log where
141147
LogApplying fp res -> "Applying hint(s) for" <+> viaShow fp <> ":" <+> viaShow res
142148
LogGeneratedIdeas fp ideas -> "Generated hlint ideas for for" <+> viaShow fp <> ":" <+> viaShow ideas
143149
LogUsingExtensions fp exts -> "Using extensions for " <+> viaShow fp <> ":" <+> pretty exts
144-
LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp
150+
LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp
145151

146152
#ifdef HLINT_ON_GHC_LIB
147153
-- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib
154+
#if !MIN_GHC_API_VERSION(9,0,0)
155+
type BufSpan = ()
156+
#endif
148157
pattern RealSrcSpan :: GHC.RealSrcSpan -> Maybe BufSpan -> GHC.SrcSpan
149-
#if MIN_VERSION_ghc(9,0,0)
158+
#if MIN_GHC_API_VERSION(9,0,0)
150159
pattern RealSrcSpan x y = GHC.RealSrcSpan x y
151160
#else
152161
pattern RealSrcSpan x y <- ((,Nothing) -> (GHC.RealSrcSpan x, y))
@@ -323,8 +332,7 @@ getExtensions nfp = do
323332
dflags <- getFlags
324333
let hscExts = EnumSet.toList (extensionFlags dflags)
325334
let hscExts' = mapMaybe (GhclibParserEx.readExtension . show) hscExts
326-
let hlintExts = hscExts'
327-
return hlintExts
335+
return hscExts'
328336
where getFlags :: Action DynFlags
329337
getFlags = do
330338
modsum <- use_ GetModSummary nfp

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ suggestionsTests =
181181
doc <- openDoc "IgnoreAnnHlint.hs" "haskell"
182182
expectNoMoreDiagnostics 3 doc "hlint"
183183

184-
, testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do
184+
, knownBrokenForGhcVersions [GHC92] "apply-refact has different behavior on v0.10" $
185+
testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do
185186
testRefactor "Comments.hs" "Redundant bracket" expectedComments
186187

188+
, onlyRunForGhcVersions [GHC92] "only run test for apply-refact-0.10" $
189+
testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do
190+
testRefactor "Comments.hs" "Redundant bracket" expectedComments'
191+
187192
, testCase "[#2290] apply all hints works with a trailing comment" $ runHlintSession "" $ do
188193
testRefactor "TwoHintsAndComment.hs" "Apply all hints" expectedComments2
189194

@@ -257,6 +262,14 @@ suggestionsTests =
257262
, "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", ""
258263
, "-- final comment"
259264
]
265+
expectedComments' = [ "-- comment before header"
266+
, "module Comments where", ""
267+
, "{-# standalone annotation #-}", ""
268+
, "-- standalone comment", ""
269+
, "-- | haddock comment"
270+
, "f = {- inline comment -} {- inline comment inside refactored code -}1 -- ending comment", ""
271+
, "-- final comment"
272+
]
260273
expectedComments2 = [ "module TwoHintsAndComment where"
261274
, "biggest = foldr1 max -- the line above will show two hlint hints, \"eta reduce\" and \"use maximum\""
262275
]
@@ -358,10 +371,7 @@ disableHlint = sendConfigurationChanged $ toJSON $ def { Plugin.plugins = Map.fr
358371
-- Although a given hlint version supports one direct ghc, we could use several versions of hlint
359372
-- each one supporting a different ghc version. It should be a temporary situation though.
360373
knownBrokenForHlintOnGhcLib :: String -> TestTree -> TestTree
361-
knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC88, GHC86]
362-
363-
knownBrokenForHlintOnRawGhc :: String -> TestTree -> TestTree
364-
knownBrokenForHlintOnRawGhc = knownBrokenForGhcVersions [GHC810, GHC90]
374+
knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC86, GHC88, GHC90, GHC92]
365375

366376
-- 1's based
367377
data Point = Point {

0 commit comments

Comments
 (0)