Skip to content

Commit

Permalink
Support hls-hlint-plugin and hls-stylish-plugin for ghc9.0 and ghc9.2 (
Browse files Browse the repository at this point in the history
…haskell#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>
  • Loading branch information
2 people authored and sloorush committed May 21, 2022
1 parent d917c34 commit 3cb8d98
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
name: Test hls-splice-plugin
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"

- if: matrix.test && matrix.ghc != '9.0.1' && matrix.ghc != '9.0.2'
- if: matrix.test
name: Test hls-stylish-haskell-plugin
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"

Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
name: Test hls-rename-plugin test suite
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"

- if: matrix.test && matrix.ghc != '9.2.2'
- if: matrix.test
name: Test hls-hlint-plugin test suite
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"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The official Haskell language server (LSP) implementation. Consult the [project

- [Features](https://haskell-language-server.readthedocs.io/en/latest/features.html)
- [Installation](https://haskell-language-server.readthedocs.io/en/latest/installation.html)
- [Supported GHC Versions](https://haskell-language-server.readthedocs.io/en/latest/supported-versions.html)
- [Configuration](https://haskell-language-server.readthedocs.io/en/latest/configuration.html)
- [Troubleshooting](https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html)
- [Contributing](https://haskell-language-server.readthedocs.io/en/latest/contributing/index.html)
11 changes: 2 additions & 9 deletions cabal-ghc90.project
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ package *

write-ghc-environment-files: never

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

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

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

stylish-haskell:Cabal,
stylish-haskell:ghc-lib-parser,
stylish-haskell:aeson,

-- ghc-9.0.2 specific
-- for ghcide:test via ghc-typelits-knownnat
ghc-typelits-natnormalise:ghc-bignum
24 changes: 8 additions & 16 deletions cabal-ghc92.project
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ package *

write-ghc-environment-files: never

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

constraints:
-- These plugins don't build/work on GHC92 yet
haskell-language-server
+ignore-plugins-ghc-bounds
-brittany
-haddockComments
-hlint
-retrie
-splice
-tactic,
hls-hlint-plugin +ghc-lib,
-- # Use ghc-lib force instead of ghc itself
ghc-lib-parser-ex -auto,
hlint +ghc-lib,
stylish-haskell +ghc-lib

allow-newer:
-- for shake-bench
Expand All @@ -73,19 +77,6 @@ allow-newer:
-- https://github.com/lspitzner/butcher/pull/8
butcher:base,

ormolu:ghc-lib-parser,

fourmolu:ghc-lib-parser,
fourmolu:Cabal,

hls-hlint-plugin:ghc-lib,
hls-hlint-plugin:ghc-lib-parser,
hls-hlint-plugin:ghc-lib-parser-ex,
hlint:ghc-lib-parser,
hlint:ghc-lib-parser-ex,
-- See https://github.com/mpickering/apply-refact/pull/116
apply-refact:base,

implicit-hie-cradle:bytestring,
implicit-hie-cradle:time,

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

hiedb:base
hiedb:base,
retrie:ghc-exactprint

allow-older:
primitive-extras:primitive-unlifted
4 changes: 2 additions & 2 deletions docs/supported-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
| `hls-floskell-plugin` | |
| `hls-fourmolu-plugin` | |
| `hls-haddock-comments-plugin` | 9.2 |
| `hls-hlint-plugin` | 9.2 |
| `hls-hlint-plugin` | |
| `hls-module-name-plugin` | |
| `hls-ormolu-plugin` | |
| `hls-pragmas-plugin` | |
Expand All @@ -52,7 +52,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
| `hls-rename-plugin` | |
| `hls-retrie-plugin` | 9.2 |
| `hls-splice-plugin` | 9.2 |
| `hls-stylish-haskell-plugin` | 9.0 |
| `hls-stylish-haskell-plugin` | |
| `hls-tactics-plugin` | 9.2 |
| `hls-selection-range-plugin` | |

Expand Down
8 changes: 4 additions & 4 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ common example-plugins
Ide.Plugin.Example2

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

Expand Down Expand Up @@ -264,12 +264,12 @@ common retrie
cpp-options: -Dretrie

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

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

Expand Down Expand Up @@ -326,7 +326,7 @@ common ormolu
cpp-options: -Dormolu

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

Expand Down
9 changes: 8 additions & 1 deletion hls-test-utils/src/Test/Hls/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Test.Hls.Util
, noLiteralCaps
, ignoreForGhcVersions
, ignoreInEnv
, onlyRunForGhcVersions
, inspectCodeAction
, inspectCommand
, inspectDiagnostic
Expand Down Expand Up @@ -148,6 +149,12 @@ ignoreInEnv envSpecs reason
ignoreForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
ignoreForGhcVersions vers = ignoreInEnv (map GhcVer vers)

onlyRunForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
onlyRunForGhcVersions vers =
if ghcVersion `elem` vers
then const id
else ignoreTestBecause

-- ---------------------------------------------------------------------

hieYamlCradleDirectContents :: String
Expand Down Expand Up @@ -362,7 +369,7 @@ actual `expectSameLocations` expected = do

-- ---------------------------------------------------------------------
getCompletionByLabel :: MonadIO m => T.Text -> [CompletionItem] -> m CompletionItem
getCompletionByLabel desiredLabel compls =
getCompletionByLabel desiredLabel compls =
case find (\c -> c ^. L.label == desiredLabel) compls of
Just c -> pure c
Nothing -> liftIO . assertFailure $
Expand Down
6 changes: 5 additions & 1 deletion plugins/hls-class-plugin/hls-class-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ library
, base >=4.12 && <5
, containers
, ghc
, ghc-exactprint >= 0.6.4
, ghcide ^>=1.7
, hls-plugin-api ^>=1.4
, lens
, lsp
, text
, transformers

if impl(ghc >=9.2.1)
build-depends: ghc-exactprint ^>= 1.5
else
build-depends: ghc-exactprint >= 0.6.4 && <1.1

default-language: Haskell2010
default-extensions:
DataKinds
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-class-plugin/src/Ide/Plugin/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ addMethodPlaceholders state AddMinimalMethodsParams{..} = do
addWhere decl = decl

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

#else
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library
build-depends:
, base >=4.12 && <5
, filepath
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.5
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6
, ghc
, ghc-boot-th
, ghcide ^>=1.7
Expand Down
21 changes: 11 additions & 10 deletions plugins/hls-hlint-plugin/hls-hlint-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ flag ghc-lib
description:
Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported

flag hlint33
flag hlint34
default: True
manual: False
description:
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
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
This flag can be removed when all dependencies support ghc-lib-9.0.* and we drop support for ghc-8.6

library
exposed-modules: Ide.Plugin.Hlint
hs-source-dirs: src
build-depends:
, aeson
, apply-refact >=0.9.3.0
, base >=4.12 && <5
, binary
, bytestring
Expand All @@ -69,30 +68,32 @@ library
, text
, transformers
, unordered-containers
, apply-refact >=0.9.0.0
-- can be removed if https://github.com/ndmitchell/hlint/pull/1325#issue-1077062712 is merged
-- and https://github.com/haskell/haskell-language-server/pull/2464#issue-1077133441 is updated
-- accordingly
, ghc-lib-parser-ex

if (flag(hlint33))
if (flag(hlint34))
-- This mirrors the logic in hlint.cabal for hlint-3.3
-- https://github.com/ndmitchell/hlint/blob/d3576de4529d8df6cca5a345f5b7e04474ff7bff/hlint.cabal#L79-L88
-- so we can make sure that we do the same thing as hlint
build-depends: hlint ^>=3.3
build-depends: hlint ^>=3.4

if (!flag(ghc-lib) && impl(ghc >=9.0.1) && impl(ghc <9.1.0))
build-depends: ghc ==9.0.*
build-depends: ghc ==9.0.*
else
build-depends:
, ghc
, ghc-lib ^>=9.0
, ghc-lib-parser-ex ^>=9.0
, ghc-lib ^>=9.2
, ghc-lib-parser-ex ^>=9.2
, ghc-lib-parser ^>=9.2

cpp-options: -DHLINT_ON_GHC_LIB

else
-- This mirrors the logic in hlint.cabal for hlint-3.2
-- https://github.com/ndmitchell/hlint/blob/c7354e473c7d09213c8adc3dc94bf50a6eb4a42d/hlint.cabal#L79-L88
build-depends: hlint ^>=3.2
build-depends: hlint ^>=3.2
if (!flag(ghc-lib) && impl(ghc >=8.10.1) && impl(ghc < 8.11.0))
build-depends: ghc >=8.10 && <9.0
else
Expand Down
20 changes: 14 additions & 6 deletions plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ import qualified Refact.Apply as Refact
import qualified Refact.Types as Refact

#ifdef HLINT_ON_GHC_LIB
import Development.IDE.GHC.Compat (BufSpan,
DynFlags,
import Development.IDE.GHC.Compat (DynFlags,
WarningFlag (Opt_WarnUnrecognisedPragmas),
extensionFlags,
ms_hspp_opts,
Expand All @@ -73,6 +72,9 @@ import "ghc-lib" GHC hiding
RealSrcSpan,
ms_hspp_opts)
import qualified "ghc-lib" GHC
#if MIN_GHC_API_VERSION(9,0,0)
import "ghc-lib-parser" GHC.Types.SrcLoc (BufSpan)
#endif
import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension)
import System.FilePath (takeFileName)
Expand All @@ -89,7 +91,11 @@ import System.IO.Temp
import Development.IDE.GHC.Compat hiding
(setEnv, (<+>))
import GHC.Generics (Associativity (LeftAssociative, NotAssociative, RightAssociative))
#if MIN_GHC_API_VERSION(9,2,0)
import Language.Haskell.GHC.ExactPrint.ExactPrint (deltaOptions)
#else
import Language.Haskell.GHC.ExactPrint.Delta (deltaOptions)
#endif
import Language.Haskell.GHC.ExactPrint.Parsers (postParseTransform)
import Language.Haskell.GHC.ExactPrint.Types (Rigidity (..))
import Language.Haskell.GhclibParserEx.Fixity as GhclibParserEx (applyFixities)
Expand Down Expand Up @@ -141,12 +147,15 @@ instance Pretty Log where
LogApplying fp res -> "Applying hint(s) for" <+> viaShow fp <> ":" <+> viaShow res
LogGeneratedIdeas fp ideas -> "Generated hlint ideas for for" <+> viaShow fp <> ":" <+> viaShow ideas
LogUsingExtensions fp exts -> "Using extensions for " <+> viaShow fp <> ":" <+> pretty exts
LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp
LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp

#ifdef HLINT_ON_GHC_LIB
-- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib
#if !MIN_GHC_API_VERSION(9,0,0)
type BufSpan = ()
#endif
pattern RealSrcSpan :: GHC.RealSrcSpan -> Maybe BufSpan -> GHC.SrcSpan
#if MIN_VERSION_ghc(9,0,0)
#if MIN_GHC_API_VERSION(9,0,0)
pattern RealSrcSpan x y = GHC.RealSrcSpan x y
#else
pattern RealSrcSpan x y <- ((,Nothing) -> (GHC.RealSrcSpan x, y))
Expand Down Expand Up @@ -323,8 +332,7 @@ getExtensions nfp = do
dflags <- getFlags
let hscExts = EnumSet.toList (extensionFlags dflags)
let hscExts' = mapMaybe (GhclibParserEx.readExtension . show) hscExts
let hlintExts = hscExts'
return hlintExts
return hscExts'
where getFlags :: Action DynFlags
getFlags = do
modsum <- use_ GetModSummary nfp
Expand Down
20 changes: 15 additions & 5 deletions plugins/hls-hlint-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@ suggestionsTests =
doc <- openDoc "IgnoreAnnHlint.hs" "haskell"
expectNoMoreDiagnostics 3 doc "hlint"

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

, onlyRunForGhcVersions [GHC92] "only run test for apply-refact-0.10" $
testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do
testRefactor "Comments.hs" "Redundant bracket" expectedComments'

, testCase "[#2290] apply all hints works with a trailing comment" $ runHlintSession "" $ do
testRefactor "TwoHintsAndComment.hs" "Apply all hints" expectedComments2

Expand Down Expand Up @@ -257,6 +262,14 @@ suggestionsTests =
, "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", ""
, "-- final comment"
]
expectedComments' = [ "-- comment before header"
, "module Comments where", ""
, "{-# standalone annotation #-}", ""
, "-- standalone comment", ""
, "-- | haddock comment"
, "f = {- inline comment -} {- inline comment inside refactored code -}1 -- ending comment", ""
, "-- final comment"
]
expectedComments2 = [ "module TwoHintsAndComment where"
, "biggest = foldr1 max -- the line above will show two hlint hints, \"eta reduce\" and \"use maximum\""
]
Expand Down Expand Up @@ -358,10 +371,7 @@ disableHlint = sendConfigurationChanged $ toJSON $ def { Plugin.plugins = Map.fr
-- Although a given hlint version supports one direct ghc, we could use several versions of hlint
-- each one supporting a different ghc version. It should be a temporary situation though.
knownBrokenForHlintOnGhcLib :: String -> TestTree -> TestTree
knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC88, GHC86]

knownBrokenForHlintOnRawGhc :: String -> TestTree -> TestTree
knownBrokenForHlintOnRawGhc = knownBrokenForGhcVersions [GHC810, GHC90]
knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC86, GHC88, GHC90, GHC92]

-- 1's based
data Point = Point {
Expand Down
Loading

0 comments on commit 3cb8d98

Please sign in to comment.