Skip to content

Commit ad0c6ae

Browse files
jhrcekmichaelpj
authored andcommitted
Fix -Wall and -Wunused-packages in plugins api and floskell (haskell#4005)
* Fix -Wall and -Wunused-packages in plugins api and floskell * stylish-haskell --------- Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent 36d9349 commit ad0c6ae

File tree

9 files changed

+51
-37
lines changed

9 files changed

+51
-37
lines changed

hls-plugin-api/hls-plugin-api.cabal

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ source-repository head
3232
type: git
3333
location: https://github.com/haskell/haskell-language-server
3434

35+
common warnings
36+
ghc-options:
37+
-Wall -Wredundant-constraints -Wunused-packages
38+
-Wno-name-shadowing -Wno-unticked-promoted-constructors
39+
3540
library
41+
import: warnings
3642
exposed-modules:
3743
Ide.Logger
3844
Ide.Plugin.Config
@@ -84,10 +90,6 @@ library
8490
else
8591
build-depends: unix
8692

87-
ghc-options:
88-
-Wall -Wredundant-constraints -Wno-name-shadowing
89-
-Wno-unticked-promoted-constructors -Wunused-packages
90-
9193
if flag(pedantic)
9294
ghc-options: -Werror
9395

@@ -102,6 +104,7 @@ library
102104
TypeOperators
103105

104106
test-suite tests
107+
import: warnings
105108
type: exitcode-stdio-1.0
106109
default-language: Haskell2010
107110
hs-source-dirs: test
@@ -125,6 +128,7 @@ test-suite tests
125128
, text
126129

127130
benchmark rangemap-benchmark
131+
import: warnings
128132
-- Benchmark doesn't make sense if fingertree implementation
129133
-- is not used.
130134
if !flag(use-fingertree)
@@ -134,7 +138,7 @@ benchmark rangemap-benchmark
134138
default-language: Haskell2010
135139
hs-source-dirs: bench
136140
main-is: Main.hs
137-
ghc-options: -threaded -Wall
141+
ghc-options: -threaded
138142
build-depends:
139143
, base
140144
, criterion

hls-plugin-api/src/Ide/Logger.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ withFileRecorder path columns action = do
178178
fileHandle :: Either IOException Handle <- liftIO $ try (openFile path AppendMode)
179179
case fileHandle of
180180
Left e -> action $ Left e
181-
Right fileHandle -> finally ((Right <$> makeHandleRecorder fileHandle) >>= action) (liftIO $ hClose fileHandle)
181+
Right fileHandle -> finally (makeHandleRecorder fileHandle >>= action . Right) (liftIO $ hClose fileHandle)
182182

183183
makeDefaultHandleRecorder
184184
:: MonadIO m

hls-plugin-api/src/Ide/Plugin/RangeMap.hs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveFoldable #-}
3-
{-# LANGUAGE DeriveFunctor #-}
42
{-# LANGUAGE DeriveTraversable #-}
53
{-# LANGUAGE DerivingStrategies #-}
64
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+
#ifdef USE_FINGERTREE
6+
{-# LANGUAGE DeriveFoldable #-}
7+
{-# LANGUAGE DeriveFunctor #-}
8+
#endif
79

810
-- | A map that allows fast \"in-range\" filtering. 'RangeMap' is meant
911
-- to be constructed once and cached as part of a Shake rule. If
@@ -18,15 +20,14 @@ module Ide.Plugin.RangeMap
1820
fromList',
1921
filterByRange,
2022
) where
21-
22-
import Data.Bifunctor (first)
23-
import Data.Foldable (foldl')
2423
import Development.IDE.Graph.Classes (NFData)
25-
import Language.LSP.Protocol.Types (Position,
26-
Range (Range),
27-
isSubrangeOf)
24+
import Language.LSP.Protocol.Types (Range, isSubrangeOf)
2825
#ifdef USE_FINGERTREE
26+
import Data.Bifunctor (first)
27+
import Data.Foldable (foldl')
2928
import qualified HaskellWorks.Data.IntervalMap.FingerTree as IM
29+
import Language.LSP.Protocol.Types (Position,
30+
Range (Range))
3031
#endif
3132

3233
-- | A map from code ranges to values.

hls-plugin-api/src/Ide/Plugin/Resolve.hs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE DeriveGeneric #-}
22
{-# LANGUAGE DisambiguateRecordFields #-}
33
{-# LANGUAGE LambdaCase #-}
4-
{-# LANGUAGE NamedFieldPuns #-}
54
{-# LANGUAGE OverloadedLabels #-}
65
{-# LANGUAGE OverloadedStrings #-}
76
{-# LANGUAGE RankNTypes #-}

hls-plugin-api/src/Ide/PluginUtils.hs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE FlexibleContexts #-}
2-
{-# LANGUAGE LambdaCase #-}
32
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE TypeFamilies #-}
54

hls-plugin-api/test/Ide/PluginUtilsTest.hs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE TypeApplications #-}
3+
{-# OPTIONS_GHC -Wno-orphans #-}
34

45
module Ide.PluginUtilsTest
56
( tests
67
) where
78

8-
import Data.Char (isPrint)
99
import qualified Data.Set as Set
1010
import qualified Data.Text as T
1111
import qualified Ide.Plugin.RangeMap as RangeMap
12-
import Ide.PluginUtils (extractTextInRange,
13-
positionInRange, unescape)
12+
import Ide.PluginUtils (extractTextInRange, unescape)
1413
import Language.LSP.Protocol.Types (Position (..), Range (Range),
1514
UInt, isSubrangeOf)
1615
import Test.Tasty
@@ -106,7 +105,7 @@ genRangeInline = do
106105
pure $ Range x1 x2
107106
where
108107
genRangeLength :: Gen UInt
109-
genRangeLength = fromInteger <$> chooseInteger (5, 50)
108+
genRangeLength = uInt (5, 50)
110109

111110
genRangeMultiline :: Gen Range
112111
genRangeMultiline = do
@@ -119,17 +118,20 @@ genRangeMultiline = do
119118
pure $ Range x1 x2
120119
where
121120
genSecond :: Gen UInt
122-
genSecond = fromInteger <$> chooseInteger (0, 10)
121+
genSecond = uInt (0, 10)
123122

124123
genPosition :: Gen Position
125124
genPosition = Position
126-
<$> (fromInteger <$> chooseInteger (0, 1000))
127-
<*> (fromInteger <$> chooseInteger (0, 150))
125+
<$> uInt (0, 1000)
126+
<*> uInt (0, 150)
127+
128+
uInt :: (Integer, Integer) -> Gen UInt
129+
uInt (a, b) = fromInteger <$> chooseInteger (a, b)
128130

129131
instance Arbitrary Range where
130132
arbitrary = genRange
131133

132-
prop_rangemapListEq :: (Show a, Eq a, Ord a) => Range -> [(Range, a)] -> Property
134+
prop_rangemapListEq :: (Show a, Ord a) => Range -> [(Range, a)] -> Property
133135
prop_rangemapListEq r xs =
134136
let filteredList = (map snd . filter (isSubrangeOf r . fst)) xs
135137
filteredRangeMap = RangeMap.filterByRange r (RangeMap.fromList' xs)

hls-plugin-api/test/Ide/TypesTests.hs

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
module Ide.TypesTests
88
( tests
99
) where
10-
import Control.Lens (preview, (?~), (^?))
11-
import Control.Monad ((>=>))
10+
import Control.Lens ((?~), (^?))
1211
import Data.Default (Default (def))
1312
import Data.Function ((&))
14-
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty)
13+
import Data.List.NonEmpty (NonEmpty ((:|)))
1514
import Data.Maybe (isJust)
1615
import qualified Data.Text as Text
17-
import Ide.Types (Config (Config),
18-
PluginRequestMethod (combineResponses))
16+
import Ide.Types (PluginRequestMethod (combineResponses))
1917
import qualified Language.LSP.Protocol.Lens as L
20-
import Language.LSP.Protocol.Message (Method (Method_TextDocumentDefinition),
18+
import Language.LSP.Protocol.Message (MessageParams, MessageResult,
2119
SMethod (..))
2220
import Language.LSP.Protocol.Types (ClientCapabilities,
2321
Definition (Definition),
@@ -29,18 +27,17 @@ import Language.LSP.Protocol.Types (ClientCapabilities,
2927
Null (Null),
3028
Position (Position),
3129
Range (Range),
32-
TextDocumentClientCapabilities (TextDocumentClientCapabilities, _definition),
30+
TextDocumentClientCapabilities,
3331
TextDocumentIdentifier (TextDocumentIdentifier),
3432
TypeDefinitionClientCapabilities (TypeDefinitionClientCapabilities, _dynamicRegistration, _linkSupport),
3533
TypeDefinitionParams (..),
36-
Uri (Uri), _L, _R,
34+
Uri (Uri), _L, _R, _definition,
3735
_typeDefinition, filePathToUri,
3836
type (|?) (..))
3937
import Test.Tasty (TestTree, testGroup)
40-
import Test.Tasty.HUnit (assertBool, testCase, (@=?))
38+
import Test.Tasty.HUnit (testCase, (@=?))
4139
import Test.Tasty.QuickCheck (ASCIIString (ASCIIString),
4240
Arbitrary (arbitrary), Gen,
43-
NonEmptyList (NonEmpty),
4441
arbitraryBoundedEnum, cover,
4542
listOf1, oneof, testProperty,
4643
(===))
@@ -63,6 +60,11 @@ combineResponsesTextDocumentTypeDefinitionTests :: TestTree
6360
combineResponsesTextDocumentTypeDefinitionTests = testGroup "TextDocumentTypeDefinition" $
6461
defAndTypeDefSharedTests SMethod_TextDocumentTypeDefinition typeDefinitionParams
6562

63+
defAndTypeDefSharedTests ::
64+
( MessageResult m ~ (Definition |? ([DefinitionLink] |? Null))
65+
, PluginRequestMethod m
66+
)
67+
=> SMethod m -> MessageParams m -> [TestTree]
6668
defAndTypeDefSharedTests message params =
6769
[ testCase "merges all single location responses into one response with all locations (without upgrading to links)" $ do
6870
let pluginResponses :: NonEmpty (Definition |? ([DefinitionLink] |? Null))
@@ -177,7 +179,11 @@ defAndTypeDefSharedTests message params =
177179
(isJust (result ^? _L) || isJust (result ^? _R >>= (^? _R))) === True
178180
]
179181

180-
(range1, range2, range3) = (Range (Position 3 0) $ Position 3 5, Range (Position 5 7) $ Position 5 13, Range (Position 24 30) $ Position 24 40)
182+
183+
range1, range2, range3 :: Range
184+
range1 = Range (Position 3 0) $ Position 3 5
185+
range2 = Range (Position 5 7) $ Position 5 13
186+
range3 = Range (Position 24 30) $ Position 24 40
181187

182188
supportsLinkInAllDefinitionCaps :: ClientCapabilities
183189
supportsLinkInAllDefinitionCaps = def & L.textDocument ?~ textDocumentCaps

plugins/hls-floskell-plugin/hls-floskell-plugin.cabal

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ source-repository head
2020
type: git
2121
location: https://github.com/haskell/haskell-language-server.git
2222

23+
common warnings
24+
ghc-options: -Wall -Wunused-packages
25+
2326
library
27+
import: warnings
2428
exposed-modules: Ide.Plugin.Floskell
2529
hs-source-dirs: src
2630
build-depends:
@@ -31,11 +35,11 @@ library
3135
, lsp-types ^>=2.1
3236
, mtl
3337
, text
34-
, transformers
3538

3639
default-language: Haskell2010
3740

3841
test-suite tests
42+
import: warnings
3943
type: exitcode-stdio-1.0
4044
default-language: Haskell2010
4145
hs-source-dirs: test

plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Control.Monad.Except (throwError)
1010
import Control.Monad.IO.Class
1111
import qualified Data.Text as T
1212
import qualified Data.Text.Lazy as TL
13-
import qualified Data.Text.Lazy.Encoding as TL
1413
import Development.IDE hiding (pluginHandlers)
1514
import Floskell
1615
import Ide.Plugin.Error

0 commit comments

Comments
 (0)