@@ -73,6 +73,7 @@ main = defaultMainWithRerun $ testGroup "HIE"
73 , positionMappingTests
73 , positionMappingTests
74 , watchedFilesTests
74 , watchedFilesTests
75 , cradleTests
75 , cradleTests
78initializeResponseTests :: TestTree
79initializeResponseTests :: TestTree
@@ -2046,6 +2047,42 @@ loadCradleOnlyonce = testGroup "load cradle only once"
2046 liftIO $ length msgs @?= 0
2047 liftIO $ length msgs @?= 0
2050+dependentFileTest :: TestTree
2051+dependentFileTest = testGroup "addDependentFile"
2052+ [testGroup "file-changed" [testSession' "test" test]
2056+ -- If the file contains B then no type error
2057+ -- otherwise type error
2058+ liftIO $ writeFile (dir </> "dep-file.txt") "A"
2059+ let fooContent = T.unlines
2060+ [ "{-# LANGUAGE TemplateHaskell #-}"
2061+ , "module Foo where"
2062+ , "import Language.Haskell.TH.Syntax"
2065+ , " qAddDependentFile \"dep-file.txt\""
2066+ , " f <- qRunIO (readFile \"dep-file.txt\")"
2067+ , " if f == \"B\" then [| 1 |] else lift f)"
2069+ let bazContent = T.unlines ["module Baz where", "import Foo"]
2070+ _ <-createDoc "Foo.hs" "haskell" fooContent
2071+ doc <- createDoc "Baz.hs" "haskell" bazContent
2073+ [("Foo.hs", [(DsError, (4, 6), "Couldn't match expected type")])]
2074+ -- Now modify the dependent file
2075+ liftIO $ writeFile (dir </> "dep-file.txt") "B"
2076+ let change = TextDocumentContentChangeEvent
2077+ { _range = Just (Range (Position 2 0) (Position 2 6))
2078+ , _rangeLength = Nothing
2081+ -- Modifying Baz will now trigger Foo to be rebuilt as well
2082+ changeDoc doc [change]
2083+ expectDiagnostics [("Foo.hs", [])]
2049cradleLoadedMessage :: Session FromServerMessage
2086cradleLoadedMessage :: Session FromServerMessage
2050cradleLoadedMessage = satisfy $ \case
2087cradleLoadedMessage = satisfy $ \case
2051 NotCustomServer (NotificationMessage _ (CustomServerMethod m) _) -> m == cradleLoadedMethod
2088 NotCustomServer (NotificationMessage _ (CustomServerMethod m) _) -> m == cradleLoadedMethod