@@ -9,17 +9,26 @@ import Control.Lens.Fold ((^?))
9
9
import qualified Data.Maybe as Maybe
10
10
import qualified Data.Text as T
11
11
import qualified Data.Text.Internal.Search as T
12
+ import qualified Data.Text.IO as T
12
13
import Distribution.Utils.Generic (safeHead )
13
14
import Ide.Plugin.Cabal.CabalAdd (hiddenPackageSuggestion )
14
15
import qualified Language.LSP.Protocol.Lens as L
15
- import Language.LSP.Protocol.Types (Diagnostic (.. ), mkRange )
16
+ import Language.LSP.Protocol.Types (Diagnostic (.. ),
17
+ DidChangeWatchedFilesParams (.. ),
18
+ FileChangeType (FileChangeType_Changed ),
19
+ FileEvent (.. ), filePathToUri ,
20
+ mkRange )
16
21
import System.FilePath
17
- import Test.Hls (Session , TestTree , _R , anyMessage ,
18
- assertEqual , documentContents ,
22
+ import Test.Hls (SMethod (SMethod_WorkspaceDidChangeWatchedFiles ),
23
+ Session , TestTree , _R , anyMessage ,
24
+ assertEqual , assertFailure ,
25
+ documentContents ,
19
26
executeCodeAction ,
20
27
getAllCodeActions ,
21
28
getDocumentEdit , liftIO , openDoc ,
22
- skipManyTill , testCase , testGroup ,
29
+ sendNotification , skipManyTill ,
30
+ testCase , testGroup ,
31
+ type (|? ) (InR ),
23
32
waitForDiagnosticsFrom , (@?=) )
24
33
import Utils
25
34
@@ -141,6 +150,9 @@ cabalAddTests =
141
150
, (" AAI" , " 0.1" )
142
151
, (" AWin32Console" , " 1.19.1" )
143
152
]
153
+
154
+ , runShiftedRootInTmpDirTestCaseSession " Reload HLS after cabal file changes - without cabal plugin" (" cabal-add-testdata" </> " cabal-add-lib" )
155
+ (generateReloadHlsAfterCabalChangeTestSession " cabal-add-lib.cabal" (" src" </> " MyLib.hs" ))
144
156
]
145
157
where
146
158
generateAddDependencyTestSession :: FilePath -> FilePath -> T. Text -> [Int ] -> Session ()
@@ -183,3 +195,17 @@ cabalAddTests =
183
195
cas <- Maybe. mapMaybe (^? _R) <$> getAllCodeActions hsdoc
184
196
let selectedCas = filter (\ ca -> " Add dependency" `T.isPrefixOf` (ca ^. L. title)) cas
185
197
liftIO $ assertEqual " PackageYAML" [] selectedCas
198
+
199
+ generateReloadHlsAfterCabalChangeTestSession :: FilePath -> FilePath -> FilePath -> Session ()
200
+ generateReloadHlsAfterCabalChangeTestSession cabalFile haskellFile root = do
201
+ hsdoc <- openDoc haskellFile " haskell"
202
+ _ <- waitForDiagnosticsFrom hsdoc
203
+ cabalContent <- liftIO $ T. readFile cabalFile
204
+ let fix = T. replace " build-depends: base" " build-depends: base, split"
205
+ liftIO $ T. writeFile cabalFile (fix cabalContent)
206
+ sendNotification SMethod_WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams
207
+ [ FileEvent (filePathToUri $ root </> cabalFile) FileChangeType_Changed ]
208
+ diagnostics <- waitForDiagnosticsFrom hsdoc
209
+ case diagnostics of
210
+ [diagnostic] -> liftIO $ assertEqual " Wrong diagnostic after HLS restarts" (Just $ InR " GHC-66111" ) (diagnostic ^. L. code)
211
+ _ -> liftIO $ assertFailure $ " Expect one diagnostic but got " <> show (length diagnostics)
0 commit comments