Skip to content

Commit 0b63299

Browse files
committed
Install notification handlers for cabal files
The cabal formatters read the file contents from the shake VFS. Thus, we need to make sure there are notification handlers that add the cabal files to the VFS! Formatters have to depend on the `hls-cabal-plugin` to have the necessary notification handlers installed during test time.
1 parent afb0023 commit 0b63299

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

haskell-language-server.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ library hls-cabal-fmt-plugin
137137
, process-extras
138138
, text
139139

140+
-- The `hls-cabal-plugin` is needed for tests, as we need to install notification handlers
140141
test-suite hls-cabal-fmt-plugin-tests
141142
import: defaults, pedantic, test-defaults, warnings
142143
if !flag(cabalfmt)
@@ -148,7 +149,9 @@ test-suite hls-cabal-fmt-plugin-tests
148149
, base
149150
, directory
150151
, filepath
152+
, haskell-language-server:hls-cabal-plugin
151153
, haskell-language-server:hls-cabal-fmt-plugin
154+
, hls-plugin-api == 2.9.0.1
152155
, hls-test-utils == 2.9.0.1
153156

154157
if flag(isolateCabalfmtTests)
@@ -192,6 +195,7 @@ library hls-cabal-gild-plugin
192195
, mtl
193196
, process-extras
194197

198+
-- The `hls-cabal-plugin` is needed for tests, as we need to install notification handlers
195199
test-suite hls-cabal-gild-plugin-tests
196200
import: defaults, pedantic, test-defaults, warnings
197201
if !flag(cabalgild)
@@ -203,7 +207,9 @@ test-suite hls-cabal-gild-plugin-tests
203207
, base
204208
, directory
205209
, filepath
210+
, haskell-language-server:hls-cabal-plugin
206211
, haskell-language-server:hls-cabal-gild-plugin
212+
, hls-plugin-api == 2.9.0.1
207213
, hls-test-utils == 2.9.0.1
208214

209215
if flag(isolateCabalGildTests)

plugins/hls-cabal-fmt-plugin/test/Main.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
module Main
45
( main
56
) where
67

8+
import Ide.Logger
9+
import qualified Ide.Plugin.Cabal as Cabal
710
import qualified Ide.Plugin.CabalFmt as CabalFmt
811
import System.Directory (findExecutable)
912
import System.FilePath
1013
import Test.Hls
1114

15+
data TestLog
16+
= LogCabalFmt CabalFmt.Log
17+
| LogCabal Cabal.Log
18+
19+
instance Pretty TestLog where
20+
pretty = \case
21+
LogCabalFmt msg -> pretty msg
22+
LogCabal msg -> pretty msg
23+
1224
data CabalFmtFound = Found | NotFound
1325

1426
isTestIsolated :: Bool
@@ -30,8 +42,11 @@ main = do
3042
foundCabalFmt <- isCabalFmtFound
3143
defaultTestRunner (tests foundCabalFmt)
3244

33-
cabalFmtPlugin :: PluginTestDescriptor CabalFmt.Log
34-
cabalFmtPlugin = mkPluginTestDescriptor CabalFmt.descriptor "cabal-fmt"
45+
cabalFmtPlugin :: PluginTestDescriptor TestLog
46+
cabalFmtPlugin = mconcat
47+
[ mkPluginTestDescriptor (CabalFmt.descriptor . cmapWithPrio LogCabalFmt) "cabal-fmt"
48+
, mkPluginTestDescriptor (Cabal.descriptor . cmapWithPrio LogCabal) "cabal"
49+
]
3550

3651
tests :: CabalFmtFound -> TestTree
3752
tests found = testGroup "cabal-fmt"

plugins/hls-cabal-gild-plugin/test/Main.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
module Main
45
( main
56
) where
67

8+
import Ide.Logger
9+
import qualified Ide.Plugin.Cabal as Cabal
710
import qualified Ide.Plugin.CabalGild as CabalGild
811
import System.Directory (findExecutable)
912
import System.FilePath
1013
import Test.Hls
1114

15+
data TestLog
16+
= LogCabalGild CabalGild.Log
17+
| LogCabal Cabal.Log
18+
19+
instance Pretty TestLog where
20+
pretty = \case
21+
LogCabalGild msg -> pretty msg
22+
LogCabal msg -> pretty msg
23+
1224
data CabalGildFound = Found | NotFound
1325

1426
isTestIsolated :: Bool
@@ -30,8 +42,11 @@ main = do
3042
foundCabalFmt <- isCabalFmtFound
3143
defaultTestRunner (tests foundCabalFmt)
3244

33-
cabalGildPlugin :: PluginTestDescriptor CabalGild.Log
34-
cabalGildPlugin = mkPluginTestDescriptor CabalGild.descriptor "cabal-gild"
45+
cabalGildPlugin :: PluginTestDescriptor TestLog
46+
cabalGildPlugin = mconcat
47+
[ mkPluginTestDescriptor (CabalGild.descriptor . cmapWithPrio LogCabalGild) "cabal-gild"
48+
, mkPluginTestDescriptor (Cabal.descriptor . cmapWithPrio LogCabal) "cabal"
49+
]
3550

3651
tests :: CabalGildFound -> TestTree
3752
tests found = testGroup "cabal-gild"

0 commit comments

Comments
 (0)