Skip to content

Commit ae6f707

Browse files
Ailrunmergify[bot]
andauthored
Class plugin bump up (#2475)
* Bump class plugin to work with GHC 9.0.1 * Update class flag in hls cabal file Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 807cb8f commit ae6f707

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ jobs:
192192
name: Test hls-brittany-plugin
193193
run: cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-brittany-plugin --test-options="$TEST_OPTS"
194194

195-
- if: matrix.test && matrix.ghc != '9.0.1'
195+
- if: matrix.test
196196
name: Test hls-class-plugin
197197
run: cabal test hls-class-plugin --test-options="$TEST_OPTS" || cabal test hls-class-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="$TEST_OPTS"
198198

cabal-ghc901.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ index-state: 2021-11-29T12:30:07Z
4141

4242
constraints:
4343
-- These plugins don't work on GHC9 yet
44-
haskell-language-server +ignore-plugins-ghc-bounds -brittany -class -stylishhaskell -tactic,
44+
haskell-language-server +ignore-plugins-ghc-bounds -brittany -stylishhaskell -tactic,
4545
ghc-lib-parser ^>= 9.0
4646

4747
-- although we are not building all plugins cabal solver phase is run for all packages

configuration-ghc-901.nix

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let
77
"hls-brittany-plugin"
88
"hls-stylish-haskell-plugin"
99
"hls-fourmolu-plugin"
10-
"hls-class-plugin"
1110
];
1211

1312
hpkgsOverride = hself: hsuper:
@@ -27,7 +26,6 @@ let
2726
hself.callCabal2nixWithOptions "haskell-language-server" ./.
2827
(pkgs.lib.concatStringsSep " " [
2928
"-f-brittany"
30-
"-f-class"
3129
"-f-fourmolu"
3230
"-f-stylishhaskell"
3331
"-f-tactic"

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
with haskell.lib; {
7171
# Patches don't apply
7272
github = overrideCabal hsuper.github (drv: { patches = []; });
73-
# We need an older version
73+
# We need an older version
7474
hiedb = hself.hiedb_0_4_1_0;
7575

7676
implicit-hie-cradle = hself.callCabal2nix "implicit-hie-cradle"

haskell-language-server.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ common example-plugins
206206
Ide.Plugin.Example2
207207

208208
common class
209-
if flag(class) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
209+
if flag(class) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
210210
build-depends: hls-class-plugin ^>=1.0.0.1
211211
cpp-options: -Dclass
212212

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DeriveAnyClass #-}
23
{-# LANGUAGE DeriveGeneric #-}
34
{-# LANGUAGE OverloadedStrings #-}
@@ -32,6 +33,7 @@ import Ide.Types
3233
import Language.Haskell.GHC.ExactPrint
3334
import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl)
3435
import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs, Parens)
36+
import Language.Haskell.GHC.ExactPrint.Utils (rs)
3537
import Language.LSP.Server
3638
import Language.LSP.Types
3739
import qualified Language.LSP.Types.Lens as J
@@ -85,20 +87,19 @@ addMethodPlaceholders state AddMinimalMethodsParams{..} = do
8587
Right (ann, d) -> Just (setPrecedingLines d 1 indent ann, d)
8688
Left _ -> Nothing
8789

88-
addMethodDecls :: ParsedSource -> [LHsDecl GhcPs] -> Transform (Located (HsModule GhcPs))
8990
addMethodDecls ps mDecls = do
9091
d <- findInstDecl ps
9192
newSpan <- uniqueSrcSpanT
9293
let
9394
annKey = mkAnnKey d
94-
newAnnKey = AnnKey newSpan (CN "HsValBinds")
95+
newAnnKey = AnnKey (rs newSpan) (CN "HsValBinds")
9596
addWhere mkds@(Map.lookup annKey -> Just ann)
9697
= Map.insert newAnnKey ann2 mkds2
9798
where
9899
ann1 = ann
99100
{ annsDP = annsDP ann ++ [(G AnnWhere, DP (0, 1))]
100101
, annCapturedSpan = Just newAnnKey
101-
, annSortKey = Just (fmap getLoc mDecls)
102+
, annSortKey = Just (fmap (rs . getLoc) mDecls)
102103
}
103104
mkds2 = Map.insert annKey ann1 mkds
104105
ann2 = annNone
@@ -168,9 +169,15 @@ codeAction state plId (CodeActionParams _ _ docId _ context) = liftIO $ fmap (fr
168169
pure
169170
$ head . head
170171
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1)
172+
#if !MIN_VERSION_ghc(9,0,0)
171173
( (Map.keys . Map.filter isClassNodeIdentifier . nodeIdentifiers . nodeInfo)
172174
<=< nodeChildren
173175
)
176+
#else
177+
( (Map.keys . Map.filter isClassNodeIdentifier . sourcedNodeIdents . sourcedNodeInfo)
178+
<=< nodeChildren
179+
)
180+
#endif
174181

175182
findClassFromIdentifier docPath (Right name) = do
176183
(hscEnv -> hscenv, _) <- MaybeT . runAction "classplugin" state $ useWithStale GhcSessionDeps docPath

stack-9.0.1.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages:
99
- ./hls-test-utils
1010
- ./shake-bench
1111
- ./plugins/hls-call-hierarchy-plugin
12-
# - ./plugins/hls-class-plugin
12+
- ./plugins/hls-class-plugin
1313
- ./plugins/hls-haddock-comments-plugin
1414
- ./plugins/hls-eval-plugin
1515
- ./plugins/hls-explicit-imports-plugin

0 commit comments

Comments
 (0)