Skip to content

Commit a52b7ba

Browse files
committed
Refine
1 parent 7b6676a commit a52b7ba

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

haskell-language-server.cabal

+15-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ common test-defaults
4646
common warnings
4747
ghc-options: -Wall
4848
-Wredundant-constraints
49+
-- Note [unused-packages] Some packages need CPP conditioned on MIN_VERSION_ghc(x,y,z).
50+
-- MIN_VERSION_<pkg> is CPP macro that cabal defines only when <pkg> is declared as a dependency.
51+
-- But -Wunused-packages still reports it as unused dependency it it's not imported.
52+
-- For packages with such "unused" dependencies we demote -Wunused-packages error
53+
-- (enabled by --flag=pedantic) to warning via -Wwarn=unused-packages.
4954
-Wunused-packages
5055
-Wno-name-shadowing
5156
-Wno-unticked-promoted-constructors
@@ -428,6 +433,9 @@ library hls-explicit-imports-plugin
428433
import: defaults, pedantic, warnings
429434
exposed-modules: Ide.Plugin.ExplicitImports
430435
hs-source-dirs: plugins/hls-explicit-imports-plugin/src
436+
ghc-options:
437+
--See Note [unused-packages]
438+
-Wwarn=unused-packages
431439
build-depends:
432440
, aeson
433441
, base >=4.12 && <5
@@ -808,6 +816,9 @@ library hls-splice-plugin
808816
exposed-modules:
809817
Ide.Plugin.Splice
810818
Ide.Plugin.Splice.Types
819+
ghc-options:
820+
--See Note [unused-packages]
821+
-Wwarn=unused-packages
811822

812823
hs-source-dirs: plugins/hls-splice-plugin/src
813824
build-depends:
@@ -1364,10 +1375,13 @@ library hls-ormolu-plugin
13641375

13651376

13661377
test-suite hls-ormolu-plugin-tests
1367-
import: defaults, test-defaults, warnings
1378+
import: defaults, pedantic, test-defaults, warnings
13681379
type: exitcode-stdio-1.0
13691380
hs-source-dirs: plugins/hls-ormolu-plugin/test
13701381
main-is: Main.hs
1382+
ghc-options:
1383+
-- See Note [unused-packages]
1384+
-Wwarn=unused-packages
13711385
build-tool-depends:
13721386
ormolu:ormolu
13731387
build-depends:
@@ -1592,7 +1606,6 @@ test-suite hls-semantic-tokens-plugin-tests
15921606
, hls-plugin-api
15931607
, lens
15941608
, lsp
1595-
, ghc
15961609
, text-rope
15971610
, lsp-test
15981611
, text

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

+13-16
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)