Skip to content

Commit

Permalink
Fix -Wall and -Wunused-package in gadt plugin (haskell#4008)
Browse files Browse the repository at this point in the history
* Fix -Wall and -Wunused-package in gadt plugin

* stylish-haskell
  • Loading branch information
jhrcek authored Jan 23, 2024
1 parent dc9326c commit 3fa2f7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
18 changes: 9 additions & 9 deletions plugins/hls-gadt-plugin/hls-gadt-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ source-repository head
type: git
location: https://github.com/haskell/haskell-language-server.git

common warnings
ghc-options:
-Wall
-Wunused-packages
-Wno-name-shadowing
-Wno-unticked-promoted-constructors

library
import: warnings
exposed-modules: Ide.Plugin.GADT
other-modules: Ide.Plugin.GHC

Expand All @@ -31,7 +39,6 @@ library
, extra
, ghc
, ghcide == 2.6.0.0
, ghc-boot-th
, ghc-exactprint
, hls-plugin-api == 2.6.0.0
, hls-refactor-plugin
Expand All @@ -40,16 +47,12 @@ library
, mtl
, text
, transformers
, unordered-containers

ghc-options:
-Wall
-Wno-name-shadowing
-Wno-unticked-promoted-constructors
default-language: Haskell2010
default-extensions: DataKinds

test-suite tests
import: warnings
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: test
Expand All @@ -60,7 +63,4 @@ test-suite tests
, filepath
, hls-gadt-plugin
, hls-test-utils == 2.6.0.0
, lens
, lsp
, lsp-test
, text
8 changes: 4 additions & 4 deletions plugins/hls-gadt-plugin/src/Ide/Plugin/GADT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ toGADTSyntaxCommandId = "GADT.toGADT"
-- | A command replaces H98 data decl with GADT decl in place
toGADTCommand :: PluginId -> CommandFunction IdeState ToGADTParams
toGADTCommand pId@(PluginId pId') state ToGADTParams{..} = withExceptT handleGhcidePluginError $ do
nfp <- withExceptT (GhcidePluginErrors) $ getNormalizedFilePathE uri
nfp <- withExceptT GhcidePluginErrors $ getNormalizedFilePathE uri
(decls, exts) <- getInRangeH98DeclsAndExts state range nfp
(L ann decl) <- case decls of
[d] -> pure d
Expand Down Expand Up @@ -88,7 +88,7 @@ toGADTCommand pId@(PluginId pId') state ToGADTParams{..} = withExceptT handleGhc

codeActionHandler :: PluginMethodHandler IdeState Method_TextDocumentCodeAction
codeActionHandler state plId (CodeActionParams _ _ doc range _) = withExceptT handleGhcidePluginError $ do
nfp <- withExceptT (GhcidePluginErrors) $ getNormalizedFilePathE (doc ^. L.uri)
nfp <- withExceptT GhcidePluginErrors $ getNormalizedFilePathE (doc ^. L.uri)
(inRangeH98Decls, _) <- getInRangeH98DeclsAndExts state range nfp
let actions = map (mkAction . printOutputable . tcdLName . unLoc) inRangeH98Decls
pure $ InL actions
Expand Down Expand Up @@ -138,8 +138,8 @@ handleGhcidePluginError = \case
UnexpectedNumberOfDeclarations nums -> do
PluginInternalError $ "Expected one declaration but found: " <> T.pack (show nums)
FailedToFindDataDeclRange ->
PluginInternalError $ "Unable to get data decl range"
PluginInternalError "Unable to get data decl range"
PrettyGadtError errMsg ->
PluginInternalError $ errMsg
PluginInternalError errMsg
GhcidePluginErrors errors ->
errors
13 changes: 6 additions & 7 deletions plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
module Ide.Plugin.GHC where

import Data.Functor ((<&>))
import Data.List.Extra (stripInfix)
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import Development.IDE
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.ExactPrint
import Ide.PluginUtils (subRange)
import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl)

import GHC.Parser.Annotation (AddEpAnn (..),
Anchor (Anchor),
AnchorOperation (MovedAnchor),
Expand All @@ -30,10 +25,14 @@ import GHC.Parser.Annotation (AddEpAnn (..),
EpaLocation (EpaDelta),
SrcSpanAnn' (SrcSpanAnn),
spanAsAnchor)
import Ide.PluginUtils (subRange)
import Language.Haskell.GHC.ExactPrint (showAst)
import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl)

#if MIN_VERSION_ghc(9,5,0)
import qualified Data.List.NonEmpty as NE
import GHC.Parser.Annotation (TokenLocation (..))
#endif
import Language.Haskell.GHC.ExactPrint (showAst)

type GP = GhcPass Parsed

Expand Down Expand Up @@ -229,4 +228,4 @@ noUsed = EpAnnNotUsed
pattern UserTyVar' :: LIdP pass -> HsTyVarBndr flag pass
pattern UserTyVar' s <- UserTyVar _ _ s

implicitTyVars = (wrapXRec @GP mkHsOuterImplicit)
implicitTyVars = wrapXRec @GP mkHsOuterImplicit

0 comments on commit 3fa2f7c

Please sign in to comment.