Skip to content

Commit b3c18fe

Browse files
authored
Fix ghc and hlint warnings (#568)
* Fix ghc and hlint warnings * exceptions needed with ghc 9.6+ * Small improvements * Add -Wunused-packages, consolidate warning configs, fix few more warnings * fourmolu
1 parent eab156c commit b3c18fe

File tree

32 files changed

+80
-84
lines changed

32 files changed

+80
-84
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package lsp
1515

1616
package lsp-types
1717
-- This makes a big difference here as lsp-types
18-
-- has very many independent modules
18+
-- has very many independent modules
1919
ghc-options: -j4
2020

2121
-- We allow filepath-1.5, this lets us actually test it. There is no problem

lsp-test/bench/SimpleBench.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE DuplicateRecordFields #-}
22
{-# LANGUAGE GADTs #-}
33
{-# LANGUAGE OverloadedStrings #-}
4-
{-# LANGUAGE RankNTypes #-}
54

65
module Main where
76

lsp-test/example/Test.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Language.LSP.Protocol.Message
66
import Language.LSP.Protocol.Types
77
import Language.LSP.Test
88

9+
main :: IO ()
910
main = runSession "lsp-demo-reactor-server" fullCaps "test/data/" $ do
1011
doc <- openDoc "Rename.hs" "haskell"
1112

lsp-test/func-test/FuncTest.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ import Control.Monad.IO.Class
1515
import Data.Aeson qualified as J
1616
import Data.Maybe
1717
import Data.Proxy
18-
import Data.Set qualified as Set
1918
import Language.LSP.Protocol.Lens qualified as L
2019
import Language.LSP.Protocol.Message
2120
import Language.LSP.Protocol.Types
2221
import Language.LSP.Server
2322
import Language.LSP.Test qualified as Test
2423
import System.Exit
25-
import System.IO
2624
import System.Process
2725
import Test.Hspec
2826
import UnliftIO

lsp-test/lsp-test.cabal

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ source-repository head
3131
type: git
3232
location: https://github.com/haskell/lsp
3333

34+
common warnings
35+
ghc-options: -Wunused-packages
36+
3437
library
38+
import: warnings
3539
hs-source-dirs: src
3640
default-language: GHC2021
3741
exposed-modules: Language.LSP.Test
@@ -66,7 +70,6 @@ library
6670
, mtl >=2.2 && <2.4
6771
, parser-combinators ^>=1.3
6872
, process ^>=1.6
69-
, row-types ^>=1.0
7073
, some ^>=1.0
7174
, text >=1 && <2.2
7275
, time >=1.10 && <1.13
@@ -90,6 +93,7 @@ library
9093
ghc-options: -W
9194

9295
test-suite tests
96+
import: warnings
9397
type: exitcode-stdio-1.0
9498
hs-source-dirs: test
9599
main-is: Test.hs
@@ -115,6 +119,7 @@ test-suite tests
115119
, unliftio
116120

117121
test-suite func-test
122+
import: warnings
118123
type: exitcode-stdio-1.0
119124
hs-source-dirs: func-test
120125
default-language: GHC2021
@@ -123,7 +128,6 @@ test-suite func-test
123128
, base
124129
, aeson
125130
, co-log-core
126-
, containers
127131
, hspec
128132
, lens
129133
, lsp
@@ -133,6 +137,7 @@ test-suite func-test
133137
, unliftio
134138

135139
test-suite example
140+
import: warnings
136141
type: exitcode-stdio-1.0
137142
hs-source-dirs: example
138143
default-language: GHC2021
@@ -145,11 +150,12 @@ test-suite example
145150
build-tool-depends: lsp:lsp-demo-reactor-server
146151

147152
benchmark simple-bench
153+
import: warnings
148154
type: exitcode-stdio-1.0
149155
hs-source-dirs: bench
150156
default-language: GHC2021
151157
main-is: SimpleBench.hs
152-
ghc-options: -Wall -O2 -eventlog -rtsopts
158+
ghc-options: -Wall -O2 -rtsopts
153159
build-depends:
154160
, base
155161
, extra

lsp-test/src/Language/LSP/Test.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE LambdaCase #-}
45
{-# LANGUAGE OverloadedStrings #-}
5-
{-# LANGUAGE TypeInType #-}
66

77
{- |
88
Module : Language.LSP.Test
@@ -559,7 +559,7 @@ createDoc file languageId contents = do
559559
let pred :: SomeRegistration -> [TRegistration Method_WorkspaceDidChangeWatchedFiles]
560560
pred (SomeRegistration r@(TRegistration _ SMethod_WorkspaceDidChangeWatchedFiles _)) = [r]
561561
pred _ = mempty
562-
regs = concatMap pred $ Map.elems dynCaps
562+
regs = concatMap pred dynCaps
563563
watchHits :: FileSystemWatcher -> Bool
564564
watchHits (FileSystemWatcher (GlobPattern (InL (Pattern pattern))) kind) =
565565
-- If WatchKind is excluded, defaults to all true as per spec
@@ -740,7 +740,7 @@ getCodeActionContext doc = do
740740
Note that this does not wait for more to come in.
741741
-}
742742
getCurrentDiagnostics :: TextDocumentIdentifier -> Session [Diagnostic]
743-
getCurrentDiagnostics doc = fromMaybe [] . Map.lookup (toNormalizedUri $ doc ^. L.uri) . curDiagnostics <$> get
743+
getCurrentDiagnostics doc = Map.findWithDefault [] (toNormalizedUri $ doc ^. L.uri) . curDiagnostics <$> get
744744

745745
-- | Returns the tokens of all progress sessions that have started but not yet ended.
746746
getIncompleteProgressSessions :: Session (Set.Set ProgressToken)

lsp-test/src/Language/LSP/Test/Compat.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE DuplicateRecordFields #-}
4-
{-# LANGUAGE OverloadedLabels #-}
54
{-# LANGUAGE OverloadedStrings #-}
65
-- For some reason ghc warns about not using
76
-- Control.Monad.IO.Class but it's needed for
@@ -103,7 +102,7 @@ cleanupProcess (mb_stdin, mb_stdout, mb_stderr, ph) = do
103102
return ()
104103
where ignoreSigPipe = ignoreIOError ResourceVanished ePIPE
105104
ignorePermDenied = ignoreIOError PermissionDenied eACCES
106-
105+
107106
ignoreIOError :: IOErrorType -> Errno -> IO () -> IO ()
108107
ignoreIOError ioErrorType errno =
109108
C.handle $ \e -> case e of

lsp-test/src/Language/LSP/Test/Decoding.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TypeInType #-}
44

55
module Language.LSP.Test.Decoding where
66

@@ -10,7 +10,6 @@ import Data.Aeson
1010
import Data.Aeson.Types
1111
import Data.ByteString.Lazy.Char8 qualified as B
1212
import Data.Foldable
13-
import Data.Functor.Const
1413
import Data.Functor.Product
1514
import Data.Maybe
1615
import Language.LSP.Protocol.Lens qualified as L
@@ -82,7 +81,7 @@ decodeFromServerMsg reqMap bytes = unP $ parse p obj
8281
let (mm, newMap) = pickFromIxMap lid reqMap
8382
in case mm of
8483
Nothing -> Nothing
85-
Just m -> Just $ (m, Pair m (Const newMap))
84+
Just m -> Just (m, Pair m (Const newMap))
8685
unP (Success (FromServerMess m msg)) = (reqMap, FromServerMess m msg)
8786
unP (Success (FromServerRsp (Pair m (Const newMap)) msg)) = (newMap, FromServerRsp m msg)
8887
unP (Error e) = error $ "Error decoding " <> show obj <> " :" <> e

lsp-test/src/Language/LSP/Test/Files.hs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TypeInType #-}
44

55
module Language.LSP.Test.Files (
66
swapFiles,
@@ -83,18 +83,13 @@ mapUris f event =
8383
swapDocumentChangeUri (InR (InR (InL renameFile))) = InR $ InR $ InL $ L.newUri .~ f (renameFile ^. L.newUri) $ renameFile
8484
swapDocumentChangeUri (InR (InR (InR deleteFile))) = InR $ InR $ InR $ swapUri id deleteFile
8585
in e
86-
& L.changes . _Just %~ swapKeys f
86+
& L.changes . _Just %~ M.mapKeys f
8787
& L.documentChanges . _Just . traversed %~ swapDocumentChangeUri
8888

89-
swapKeys :: (Uri -> Uri) -> M.Map Uri b -> M.Map Uri b
90-
swapKeys f = M.foldlWithKey' (\acc k v -> M.insert (f k) v acc) M.empty
91-
9289
swapUri :: L.HasUri b Uri => Lens' a b -> a -> a
93-
swapUri lens x =
94-
let newUri = f (x ^. lens . L.uri)
95-
in (lens . L.uri) .~ newUri $ x
90+
swapUri lens = (lens . L.uri) %~ f
9691

97-
-- \| Transforms rootUri/rootPath.
92+
-- Transforms rootUri/rootPath.
9893
transformInit :: InitializeParams -> InitializeParams
9994
transformInit x =
10095
let modifyRootPath p =

lsp-test/src/Language/LSP/Test/Parsing.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE OverloadedStrings #-}
4-
{-# LANGUAGE TypeInType #-}
55

66
module Language.LSP.Test.Parsing (
77
-- $receiving

0 commit comments

Comments
 (0)