Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9021c39

Browse files
authoredFeb 8, 2024
Add -Wunused-packages to common warnings (#4053)
* Add -Wunused-packages to common warnings * Get rid of common deps * Wrapper needs process on windows * Refine * Does it work like this? * More cleanups in ghcide * Fix build with stack * Also fix stack --test * Less noisy workaround * Fix new warnings
1 parent 03efae6 commit 9021c39

File tree

5 files changed

+88
-162
lines changed

5 files changed

+88
-162
lines changed
 

‎ghcide/ghcide.cabal

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ homepage:
1414
https://github.com/haskell/haskell-language-server/tree/master/ghcide#readme
1515

1616
bug-reports: https://github.com/haskell/haskell-language-server/issues
17-
tested-with: GHC == 9.8.1 || ==9.6.4 || ==9.4.8 || ==9.2.8
17+
tested-with: GHC ==9.8.1 || ==9.6.4 || ==9.4.8 || ==9.2.8
1818
extra-source-files:
1919
CHANGELOG.md
2020
README.md
@@ -215,11 +215,8 @@ library
215215
Development.IDE.Types.Action
216216

217217
if flag(pedantic)
218-
-- We eventually want to build with Werror fully, but we haven't
219-
-- finished purging the warnings, so some are set to not be errors
220-
-- for now
221218
ghc-options:
222-
-Werror -Wwarn=unused-packages
219+
-Werror
223220

224221
if flag(ekg)
225222
build-depends:
@@ -283,13 +280,6 @@ executable ghcide
283280
if !flag(executable)
284281
buildable: False
285282

286-
if flag(ekg)
287-
build-depends:
288-
, ekg-core
289-
, ekg-wai
290-
291-
cpp-options: -DMONITORING_EKG
292-
293283
test-suite ghcide-tests
294284
import: warnings
295285
type: exitcode-stdio-1.0
@@ -310,14 +300,6 @@ test-suite ghcide-tests
310300
, extra
311301
, filepath
312302
, fuzzy
313-
--------------------------------------------------------------
314-
-- The MIN_VERSION_ghc macro relies on MIN_VERSION pragmas
315-
-- which require depending on ghc. So the tests need to depend
316-
-- on ghc if they need to use MIN_VERSION_ghc. Maybe a
317-
-- better solution can be found, but this is a quick solution
318-
-- which works for now.
319-
--------------------------------------------------------------
320-
, ghc
321303
, ghcide
322304
, hls-plugin-api
323305
, lens

‎haskell-language-server.cabal

Lines changed: 73 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,13 @@ common defaults
4242
common test-defaults
4343
ghc-options: -threaded -rtsopts -with-rtsopts=-N
4444

45-
common common-deps
46-
build-depends:
47-
, base >=4.16 && <5
48-
, directory
49-
, extra
50-
, filepath
51-
, text
52-
, prettyprinter >= 1.7
53-
5445
-- Default warnings in HLS
5546
common warnings
56-
ghc-options: -Wall -Wredundant-constraints -Wno-name-shadowing -Wno-unticked-promoted-constructors
47+
ghc-options: -Wall
48+
-Wredundant-constraints
49+
-Wunused-packages
50+
-Wno-name-shadowing
51+
-Wno-unticked-promoted-constructors
5752

5853
flag pedantic
5954
description: Enable -Werror
@@ -63,7 +58,14 @@ flag pedantic
6358
-- Allow compiling in pedantic mode
6459
common pedantic
6560
if flag(pedantic)
66-
ghc-options: -Werror
61+
ghc-options:
62+
-Werror
63+
-- Note [unused-packages] Some packages need CPP conditioned on MIN_VERSION_ghc(x,y,z).
64+
-- MIN_VERSION_<pkg> is CPP macro that cabal defines only when <pkg> is declared as a dependency.
65+
-- But -Wunused-packages still reports it as unused dependency if it's not imported.
66+
-- For packages with such "unused" dependencies we demote -Wunused-packages error
67+
-- (enabled by --flag=pedantic) to warning via -Wwarn=unused-packages.
68+
-Wwarn=unused-packages
6769

6870
-- Plugin flags are designed for 'cabal install haskell-language-server':
6971
-- - Bulk flags should be default:False
@@ -389,9 +391,6 @@ library hls-eval-plugin
389391
, unliftio
390392
, unordered-containers
391393

392-
if flag(pedantic)
393-
ghc-options: -Wwarn=redundant-constraints
394-
395394
default-extensions:
396395
DataKinds
397396

@@ -430,7 +429,7 @@ flag importLens
430429
manual: True
431430

432431
library hls-explicit-imports-plugin
433-
import: defaults, warnings, pedantic
432+
import: defaults, pedantic, warnings
434433
exposed-modules: Ide.Plugin.ExplicitImports
435434
hs-source-dirs: plugins/hls-explicit-imports-plugin/src
436435
build-depends:
@@ -447,13 +446,12 @@ library hls-explicit-imports-plugin
447446
, mtl
448447
, text
449448
, transformers
450-
, unordered-containers
451449

452450
default-extensions:
453451
DataKinds
454452

455453
test-suite hls-explicit-imports-plugin-tests
456-
import: defaults, test-defaults, warnings
454+
import: defaults, pedantic, test-defaults, warnings
457455
type: exitcode-stdio-1.0
458456
hs-source-dirs: plugins/hls-explicit-imports-plugin/test
459457
main-is: Main.hs
@@ -490,8 +488,6 @@ library hls-rename-plugin
490488
, base >=4.12 && <5
491489
, containers
492490
, extra
493-
, ghc
494-
, ghc-exactprint
495491
, ghcide == 2.6.0.0
496492
, hashable
497493
, hiedb
@@ -538,15 +534,14 @@ common retrie
538534
cpp-options: -Dhls_retrie
539535

540536
library hls-retrie-plugin
541-
import: defaults, warnings
537+
import: defaults, warnings
542538
exposed-modules: Ide.Plugin.Retrie
543539
hs-source-dirs: plugins/hls-retrie-plugin/src
544540
build-depends:
545541
, aeson
546542
, base >=4.12 && <5
547543
, bytestring
548544
, containers
549-
, deepseq
550545
, directory
551546
, extra
552547
, ghc
@@ -574,7 +569,6 @@ test-suite hls-retrie-plugin-tests
574569
hs-source-dirs: plugins/hls-retrie-plugin/test
575570
main-is: Main.hs
576571
build-depends:
577-
, aeson
578572
, base
579573
, containers
580574
, filepath
@@ -814,7 +808,7 @@ common splice
814808
cpp-options: -Dhls_splice
815809

816810
library hls-splice-plugin
817-
import: defaults, warnings
811+
import: defaults, pedantic, warnings
818812
exposed-modules:
819813
Ide.Plugin.Splice
820814
Ide.Plugin.Splice.Types
@@ -823,8 +817,6 @@ library hls-splice-plugin
823817
build-depends:
824818
, aeson
825819
, base >=4.12 && <5
826-
, containers
827-
, dlist
828820
, extra
829821
, foldl
830822
, ghc
@@ -835,18 +827,16 @@ library hls-splice-plugin
835827
, lens
836828
, lsp
837829
, mtl
838-
, retrie
839830
, syb
840831
, text
841832
, transformers
842833
, unliftio-core
843-
, unordered-containers
844834

845835
default-extensions:
846836
DataKinds
847837

848838
test-suite hls-splice-plugin-tests
849-
import: defaults, test-defaults, warnings
839+
import: defaults, pedantic, test-defaults, warnings
850840
type: exitcode-stdio-1.0
851841
hs-source-dirs: plugins/hls-splice-plugin/test
852842
main-is: Main.hs
@@ -933,22 +923,17 @@ common qualifyImportedNames
933923
cpp-options: -Dhls_qualifyImportedNames
934924

935925
library hls-qualify-imported-names-plugin
936-
import: defaults, warnings
926+
import: defaults, warnings
937927
exposed-modules: Ide.Plugin.QualifyImportedNames
938928
hs-source-dirs: plugins/hls-qualify-imported-names-plugin/src
939929
build-depends:
940-
, aeson
941930
, base >=4.12 && <5
942931
, containers
943-
, deepseq
944-
, ghc
945932
, ghcide == 2.6.0.0
946-
, hls-graph
947933
, hls-plugin-api == 2.6.0.0
948934
, lens
949935
, lsp
950936
, text
951-
, unordered-containers
952937
, dlist
953938
, transformers
954939

@@ -1383,7 +1368,7 @@ library hls-ormolu-plugin
13831368

13841369

13851370
test-suite hls-ormolu-plugin-tests
1386-
import: defaults, test-defaults, warnings
1371+
import: defaults, pedantic, test-defaults, warnings
13871372
type: exitcode-stdio-1.0
13881373
hs-source-dirs: plugins/hls-ormolu-plugin/test
13891374
main-is: Main.hs
@@ -1558,7 +1543,7 @@ common semanticTokens
15581543
cpp-options: -Dhls_semanticTokens
15591544

15601545
library hls-semantic-tokens-plugin
1561-
import: defaults, warnings
1546+
import: defaults, pedantic, warnings
15621547
buildable: True
15631548
exposed-modules:
15641549
Ide.Plugin.SemanticTokens
@@ -1573,20 +1558,16 @@ library hls-semantic-tokens-plugin
15731558

15741559
hs-source-dirs: plugins/hls-semantic-tokens-plugin/src
15751560
build-depends:
1576-
, aeson
15771561
, base >=4.12 && <5
15781562
, containers
15791563
, extra
1580-
, hiedb
15811564
, text-rope
15821565
, mtl >= 2.2
15831566
, ghcide == 2.6.0.0
15841567
, hls-plugin-api == 2.6.0.0
15851568
, lens
15861569
, lsp >=2.3
1587-
, sqlite-simple
15881570
, text
1589-
, unordered-containers
15901571
, transformers
15911572
, bytestring
15921573
, syb
@@ -1600,7 +1581,7 @@ library hls-semantic-tokens-plugin
16001581
default-extensions: DataKinds
16011582

16021583
test-suite hls-semantic-tokens-plugin-tests
1603-
import: defaults, test-defaults, warnings
1584+
import: defaults, pedantic, test-defaults, warnings
16041585
type: exitcode-stdio-1.0
16051586
hs-source-dirs: plugins/hls-semantic-tokens-plugin/test
16061587
main-is: Main.hs
@@ -1609,23 +1590,19 @@ test-suite hls-semantic-tokens-plugin-tests
16091590
, aeson
16101591
, base
16111592
, containers
1612-
, extra
16131593
, filepath
16141594
, haskell-language-server:hls-semantic-tokens-plugin
16151595
, hls-test-utils == 2.6.0.0
16161596
, ghcide-test-utils
16171597
, hls-plugin-api
16181598
, lens
16191599
, lsp
1620-
, ghc
16211600
, text-rope
16221601
, lsp-test
16231602
, text
16241603
, data-default
1625-
, bytestring
16261604
, ghcide == 2.6.0.0
16271605
, hls-plugin-api == 2.6.0.0
1628-
, template-haskell
16291606
, data-default
16301607

16311608
-----------------------------
@@ -1634,7 +1611,6 @@ test-suite hls-semantic-tokens-plugin-tests
16341611

16351612
library
16361613
import: defaults
1637-
, common-deps
16381614
, warnings
16391615
, pedantic
16401616
-- plugins
@@ -1676,33 +1652,27 @@ library
16761652
autogen-modules: Paths_haskell_language_server
16771653
hs-source-dirs: src
16781654
build-depends:
1679-
, async
1680-
, base16-bytestring
1681-
, bytestring
1682-
, containers
1683-
, cryptohash-sha1
1655+
, aeson-pretty
1656+
, base >=4.16 && <5
16841657
, data-default
1658+
, directory
1659+
, extra
1660+
, filepath
16851661
, ghc
16861662
, ghcide == 2.6.0.0
16871663
, githash >=0.1.6.1
1688-
, lsp >= 2.3.0.0
16891664
, hie-bios
1690-
, hiedb
16911665
, hls-plugin-api == 2.6.0.0
16921666
, optparse-applicative
16931667
, optparse-simple
1668+
, prettyprinter >= 1.7
16941669
, process
1695-
, hls-graph
1696-
, safe-exceptions
1697-
, sqlite-simple
1698-
, unordered-containers
1699-
, aeson-pretty
1670+
, text
17001671

17011672
default-extensions: DataKinds
17021673

17031674
executable haskell-language-server
17041675
import: defaults
1705-
, common-deps
17061676
, warnings
17071677
, pedantic
17081678
main-is: Main.hs
@@ -1729,42 +1699,17 @@ executable haskell-language-server
17291699
ghc-options: -dynamic
17301700

17311701
build-depends:
1732-
, aeson
1733-
, async
1734-
, base16-bytestring
1735-
, binary
1736-
, bytestring
1737-
, containers
1738-
, cryptohash-sha1
1739-
, deepseq
1740-
, ghc
1741-
, ghc-boot-th
1742-
, ghcide
1743-
, hashable
1702+
, base >=4.16 && <5
17441703
, haskell-language-server
1745-
, lsp
1746-
, hie-bios
1747-
, hiedb
1748-
, lens
1749-
, regex-tdfa
1750-
, optparse-applicative
17511704
, hls-plugin-api
1752-
, lens
1753-
, mtl
1754-
, regex-tdfa
1755-
, safe-exceptions
1756-
, hls-graph
1757-
, sqlite-simple
1758-
, stm
1759-
, temporary
1760-
, transformers
1761-
, unordered-containers
1705+
, lsp
1706+
, prettyprinter >= 1.7
1707+
, text
17621708

17631709
default-extensions: DataKinds
17641710

17651711
executable haskell-language-server-wrapper
17661712
import: defaults
1767-
, common-deps
17681713
, warnings
17691714
, pedantic
17701715
main-is: Wrapper.hs
@@ -1780,33 +1725,31 @@ executable haskell-language-server-wrapper
17801725
"-with-rtsopts=-I0 -A128M"
17811726

17821727
build-depends:
1728+
, base >=4.16 && <5
17831729
, data-default
1784-
, ghc
1785-
, ghc-paths
1730+
, directory
1731+
, extra
1732+
, filepath
17861733
, ghcide
1787-
, gitrev
17881734
, haskell-language-server
17891735
, hie-bios
17901736
, hls-plugin-api
17911737
, lsp
17921738
, lsp-types
1793-
, mtl
1794-
, optparse-applicative
1795-
, optparse-simple
1796-
, process
1739+
, text
17971740
, transformers
17981741
, unliftio-core
17991742
if !os(windows)
18001743
build-depends:
1801-
unix
1744+
, unix
18021745
, containers
1803-
1804-
1746+
else
1747+
build-depends:
1748+
, process
18051749

18061750
test-suite func-test
18071751
import: defaults
18081752
, test-defaults
1809-
, common-deps
18101753
, warnings
18111754
, pedantic
18121755
, refactor
@@ -1816,22 +1759,23 @@ test-suite func-test
18161759
ghcide:ghcide-test-preprocessor
18171760

18181761
build-depends:
1762+
, aeson
1763+
, base >=4.16 && <5
18191764
, bytestring
1820-
, data-default
1765+
, containers
18211766
, deepseq
1822-
, hashable
1823-
, lens
1824-
, lens-aeson
1767+
, extra
1768+
, filepath
18251769
, ghcide
18261770
, ghcide-test-utils
1827-
, hls-test-utils == 2.6.0.0
1828-
, lsp-types
1829-
, aeson
1771+
, hashable
18301772
, hls-plugin-api
1773+
, hls-test-utils == 2.6.0.0
1774+
, lens
18311775
, lsp-test
1832-
, containers
1776+
, lsp-types
1777+
, text
18331778
, unordered-containers
1834-
, row-types
18351779

18361780
hs-source-dirs: test/functional test/utils
18371781

@@ -1860,7 +1804,7 @@ test-suite func-test
18601804
cpp-options: -Dhls_ormolu
18611805

18621806
test-suite wrapper-test
1863-
import: defaults, common-deps
1807+
import: defaults
18641808
, warnings
18651809
, pedantic
18661810
type: exitcode-stdio-1.0
@@ -1869,14 +1813,16 @@ test-suite wrapper-test
18691813
haskell-language-server:haskell-language-server
18701814

18711815
build-depends:
1872-
process
1816+
, base >=4.16 && <5
1817+
, extra
18731818
, hls-test-utils
1819+
, process
18741820

18751821
hs-source-dirs: test/wrapper
18761822
main-is: Main.hs
18771823

18781824
benchmark benchmark
1879-
import: defaults, warnings, common-deps
1825+
import: defaults, warnings
18801826
-- Depends on shake-bench which is unbuildable after this point
18811827
if impl(ghc >= 9.5)
18821828
buildable: False
@@ -1894,15 +1840,19 @@ benchmark benchmark
18941840
ViewPatterns
18951841

18961842
build-depends:
1897-
aeson,
1898-
containers,
1899-
data-default,
1900-
ghcide-bench,
1901-
haskell-language-server,
1902-
hls-plugin-api,
1903-
lens,
1904-
lens-aeson,
1905-
optparse-applicative,
1906-
shake,
1907-
shake-bench == 0.2.*,
1908-
yaml
1843+
, aeson
1844+
, base >=4.16 && <5
1845+
, containers
1846+
, data-default
1847+
, directory
1848+
, extra
1849+
, filepath
1850+
, ghcide-bench
1851+
, haskell-language-server
1852+
, hls-plugin-api
1853+
, lens
1854+
, lens-aeson
1855+
, shake
1856+
, shake-bench == 0.2.*
1857+
, text
1858+
, yaml

‎plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import Control.Monad.Except (ExceptT, liftEither,
1818
import Control.Monad.Trans (lift)
1919
import Control.Monad.Trans.Except (runExceptT)
2020
import qualified Data.Map.Strict as M
21-
import qualified Data.Set as S
2221
import Development.IDE (Action,
2322
GetDocMap (GetDocMap),
2423
GetHieAst (GetHieAst),

‎plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import Development.IDE.Graph.Classes (Hashable)
1818
import GHC.Generics (Generic)
1919
import Language.LSP.Protocol.Types
2020
-- import template haskell
21-
import Data.Map.Strict (Map)
22-
import Data.Set (Set)
2321
import Language.Haskell.TH.Syntax (Lift)
2422

2523

‎plugins/hls-semantic-tokens-plugin/test/Main.hs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE DataKinds #-}
32
{-# LANGUAGE OverloadedStrings #-}
43

54
import Control.Lens ((^?))
65
import Control.Monad.IO.Class (liftIO)
7-
import Data.Aeson (KeyValue (..), Value (..),
8-
object)
6+
import Data.Aeson (KeyValue (..), Object)
7+
import qualified Data.Aeson.KeyMap as KV
98
import Data.Default
109
import Data.Functor (void)
1110
import Data.Map.Strict as Map hiding (map)
@@ -14,6 +13,9 @@ import Data.Text hiding (length, map,
1413
unlines)
1514
import qualified Data.Text as Text
1615
import qualified Data.Text.Utf16.Rope as Rope
16+
import Development.IDE (Pretty)
17+
import Development.IDE.GHC.Compat (GhcVersion (..),
18+
ghcVersion)
1719
import Development.IDE.Plugin.Test (WaitForIdeRuleResult (..))
1820
import Development.IDE.Test (waitForBuildQueue)
1921
import Ide.Plugin.SemanticTokens
@@ -22,13 +24,12 @@ import Ide.Plugin.SemanticTokens.Types
2224
import Ide.Types
2325
import Language.LSP.Protocol.Types (SemanticTokenTypes (..),
2426
_L)
25-
import Language.LSP.Test (Session (..),
27+
import Language.LSP.Test (Session,
2628
SessionConfig (ignoreConfigurationRequests),
2729
openDoc)
2830
import qualified Language.LSP.Test as Test
2931
import Language.LSP.VFS (VirtualFile (..))
3032
import System.FilePath
31-
import qualified Test.Hls as Test
3233
import Test.Hls (PluginTestDescriptor,
3334
TestName, TestTree,
3435
TextDocumentIdentifier,
@@ -65,6 +66,7 @@ semanticTokensPlugin = Test.Hls.mkPluginTestDescriptor enabledSemanticDescriptor
6566
}
6667
}
6768

69+
goldenWithHaskellAndCapsOutPut :: Pretty b => Config -> PluginTestDescriptor b -> TestName -> FS.VirtualFileTree -> FilePath -> String -> (TextDocumentIdentifier -> Session String) -> TestTree
6870
goldenWithHaskellAndCapsOutPut config plugin title tree path desc act =
6971
goldenGitDiff title (FS.vftOriginalRoot tree </> path <.> desc) $
7072
runSessionWithServerInTmpDir config plugin tree $
@@ -118,13 +120,11 @@ semanticTokensValuePatternTests =
118120
goldenWithSemanticTokensWithDefaultConfig "pattern bind" "TPatternbind"
119121
]
120122

121-
mkSemanticConfig :: Value -> Config
123+
mkSemanticConfig :: Object -> Config
122124
mkSemanticConfig setting = def{plugins = Map.insert "SemanticTokens" conf (plugins def)}
123125
where
124-
conf = def{plcConfig = (\(Object obj) -> obj) setting }
126+
conf = def{plcConfig = setting }
125127

126-
modifySemantic :: Value -> Session ()
127-
modifySemantic setting = Test.setHlsConfig $ mkSemanticConfig setting
128128

129129

130130
directFile :: FilePath -> Text -> [FS.FileTree]
@@ -138,7 +138,7 @@ semanticTokensConfigTest = testGroup "semantic token config test" [
138138
testCase "function to variable" $ do
139139
let content = Text.unlines ["module Hello where", "go _ = 1"]
140140
let fs = mkFs $ directFile "Hello.hs" content
141-
let funcVar = object ["functionToken" .= var]
141+
let funcVar = KV.fromList ["functionToken" .= var]
142142
var :: String
143143
var = "variable"
144144
do
@@ -158,8 +158,7 @@ semanticTokensConfigTest = testGroup "semantic token config test" [
158158

159159
semanticTokensTests :: TestTree
160160
semanticTokensTests =
161-
testGroup
162-
"other semantic Token test"
161+
testGroup "other semantic Token test" $
163162
[ testCase "module import test" $ do
164163
let file1 = "TModula𐐀bA.hs"
165164
let file2 = "TModuleB.hs"
@@ -194,11 +193,9 @@ semanticTokensTests =
194193
goldenWithSemanticTokensWithDefaultConfig "type family" "TTypefamily",
195194
goldenWithSemanticTokensWithDefaultConfig "TUnicodeSyntax" "TUnicodeSyntax",
196195
goldenWithSemanticTokensWithDefaultConfig "TQualifiedName" "TQualifiedName"
197-
-- it is not supported in ghc92
198-
#if MIN_VERSION_ghc(9,4,0)
199-
, goldenWithSemanticTokensWithDefaultConfig "TDoc" "TDoc"
200-
#endif
201196
]
197+
-- not supported in ghc92
198+
++ [goldenWithSemanticTokensWithDefaultConfig "TDoc" "TDoc" | ghcVersion > GHC92]
202199

203200
semanticTokensDataTypeTests :: TestTree
204201
semanticTokensDataTypeTests =

0 commit comments

Comments
 (0)
Please sign in to comment.