Skip to content

Commit 78dacc5

Browse files
authored
Fix -Wall and -Wunused-packages in hls-class-plugin (#3972)
* Fix -Wunused-packages in class plugin * -Wall and hlint fixes * Fix type annotation for ghc 9.6+
1 parent 4361687 commit 78dacc5

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ source-repository head
2424
type: git
2525
location: https://github.com/haskell/haskell-language-server.git
2626

27+
common warnings
28+
ghc-options: -Wall -Wno-unticked-promoted-constructors -Wno-name-shadowing -Wunused-packages
29+
2730
library
31+
import: warnings
2832
-- Plugins that need exactprint have not been updated for 9.8 yet
2933
if impl(ghc >= 9.8)
3034
buildable: False
@@ -46,7 +50,6 @@ library
4650
, ghc
4751
, ghc-exactprint >= 1.5
4852
, ghcide == 2.6.0.0
49-
, ghc-boot-th
5053
, hls-graph
5154
, hls-plugin-api == 2.6.0.0
5255
, lens
@@ -61,9 +64,8 @@ library
6164
TypeOperators
6265
OverloadedStrings
6366

64-
ghc-options: -Wall -Wno-unticked-promoted-constructors -Wno-name-shadowing
65-
6667
test-suite tests
68+
import: warnings
6769
if impl(ghc >= 9.8)
6870
buildable: False
6971
else
@@ -74,12 +76,10 @@ test-suite tests
7476
main-is: Main.hs
7577
ghc-options: -threaded -rtsopts -with-rtsopts=-N
7678
build-depends:
77-
, aeson
7879
, base
7980
, filepath
8081
, ghcide
8182
, hls-class-plugin
82-
, hls-plugin-api
8383
, hls-test-utils == 2.6.0.0
8484
, lens
8585
, lsp-types

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Language.LSP.Server
4343

4444
addMethodPlaceholders :: PluginId -> CommandFunction IdeState AddMinimalMethodsParams
4545
addMethodPlaceholders _ state param@AddMinimalMethodsParams{..} = do
46-
caps <- lift $ getClientCapabilities
46+
caps <- lift getClientCapabilities
4747
nfp <- getNormalizedFilePathE (verTxtDocId ^. L.uri)
4848
pm <- runActionE "classplugin.addMethodPlaceholders.GetParsedModule" state
4949
$ useE GetParsedModule nfp
@@ -239,6 +239,6 @@ minDefToMethodGroups hsc gblEnv range sigs minDef = makeMethodGroup <$> go minDe
239239

240240
go (Var mn) = pure $ makeMethodDefinitions hsc gblEnv range $ filter ((==) (printOutputable mn) . signatureToName) sigs
241241
go (Or ms) = concatMap (go . unLoc) ms
242-
go (And ms) = foldr (liftA2 (<>)) [[]] (fmap (go . unLoc) ms)
242+
go (And ms) = foldr (liftA2 (<>) . go . unLoc) [[]] ms
243243
go (Parens m) = go (unLoc m)
244244

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import Language.Haskell.GHC.ExactPrint
1313
import Language.Haskell.GHC.ExactPrint.Parsers
1414

1515
import Data.Either.Extra (eitherToMaybe)
16+
import Data.Functor.Identity (Identity)
1617
import GHC.Parser.Annotation
18+
import Language.LSP.Protocol.Types (Range)
1719

1820
makeEditText :: Monad m => ParsedModule -> DynFlags -> AddMinimalMethodsParams -> MaybeT m (T.Text, T.Text)
19-
-- addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located HsModule)
2021
makeEditText pm df AddMinimalMethodsParams{..} = do
2122
mDecls <- MaybeT . pure $ traverse (makeMethodDecl df) methodGroup
2223
let ps = makeDeltaAst $ pm_parsed_source pm
@@ -31,14 +32,21 @@ makeMethodDecl df (mName, sig) = do
3132
sig' <- eitherToMaybe $ parseDecl df (T.unpack sig) $ T.unpack sig
3233
pure (name, sig')
3334

35+
#if MIN_VERSION_ghc(9,5,0)
36+
addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located (HsModule GhcPs))
37+
#else
38+
addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located HsModule)
39+
#endif
3440
addMethodDecls ps mDecls range withSig
3541
| withSig = go (concatMap (\(decl, sig) -> [sig, decl]) mDecls)
3642
| otherwise = go (map fst mDecls)
3743
where
3844
go inserting = do
3945
allDecls <- hsDecls ps
40-
let (before, ((L l inst): after)) = break (inRange range . getLoc) allDecls
41-
replaceDecls ps (before ++ (L l (addWhere inst)): (map newLine inserting ++ after))
46+
case break (inRange range . getLoc) allDecls of
47+
(before, L l inst : after) -> replaceDecls ps (before ++ L l (addWhere inst):(map newLine inserting ++ after))
48+
(before, []) -> replaceDecls ps before
49+
4250
-- Add `where` keyword for `instance X where` if `where` is missing.
4351
--
4452
-- The `where` in ghc-9.2 is now stored in the instance declaration
@@ -48,15 +56,17 @@ addMethodDecls ps mDecls range withSig
4856
--
4957
-- See the link for the original definition:
5058
-- https://hackage.haskell.org/package/ghc-9.2.1/docs/Language-Haskell-Syntax-Extension.html#t:XCClsInstDecl
51-
addWhere (InstD xInstD (ClsInstD ext decl@ClsInstDecl{..})) =
52-
let (EpAnn entry anns comments, key) = cid_ext
53-
in InstD xInstD (ClsInstD ext decl {
54-
cid_ext = (EpAnn
55-
entry
56-
(AddEpAnn AnnWhere (EpaDelta (SameLine 1) []) : anns)
57-
comments
58-
, key)
59-
})
59+
addWhere instd@(InstD xInstD (ClsInstD ext decl@ClsInstDecl{..})) =
60+
case cid_ext of
61+
(EpAnn entry anns comments, key) ->
62+
InstD xInstD (ClsInstD ext decl {
63+
cid_ext = (EpAnn
64+
entry
65+
(AddEpAnn AnnWhere (EpaDelta (SameLine 1) []) : anns)
66+
comments
67+
, key)
68+
})
69+
_ -> instd
6070
addWhere decl = decl
6171

6272
newLine (L l e) =

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ getInstanceBindLensRule recorder = do
190190
(locA l) -- bindSpan
191191
(locA l') -- bindNameSpan
192192
in toBindInfo <$> filter (\(L _ name) -> unLoc name `notElem` sigNames) bindNames
193-
getBindSpanWithoutSig _ = []
194193

195194
-- Get bind definition range with its rendered signature text
196195
getRangeWithSig :: Maybe (InstanceBindTypeSig, SrcSpan) -> IO (Maybe (Range, Int, Name, Type))

0 commit comments

Comments
 (0)