@@ -73,6 +73,7 @@ main = defaultMainWithRerun $ testGroup "HIE"
7373 , positionMappingTests
7474 , watchedFilesTests
7575 , cradleTests
76+ , dependentFileTest
7677 ]
7778
7879initializeResponseTests :: TestTree
@@ -2046,6 +2047,42 @@ loadCradleOnlyonce = testGroup "load cradle only once"
20462047 liftIO $ length msgs @?= 0
20472048
20482049
2050+dependentFileTest :: TestTree
2051+dependentFileTest = testGroup "addDependentFile"
2052+ [testGroup "file-changed" [testSession' "test" test]
2053+ ]
2054+ where
2055+ test dir = do
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"
2063+ , "foo :: Int"
2064+ , "foo = 1 + $(do"
2065+ , " qAddDependentFile \"dep-file.txt\""
2066+ , " f <- qRunIO (readFile \"dep-file.txt\")"
2067+ , " if f == \"B\" then [| 1 |] else lift f)"
2068+ ]
2069+ let bazContent = T.unlines ["module Baz where", "import Foo"]
2070+ _ <-createDoc "Foo.hs" "haskell" fooContent
2071+ doc <- createDoc "Baz.hs" "haskell" bazContent
2072+ expectDiagnostics
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
2079+ , _text = "f = ()"
2080+ }
2081+ -- Modifying Baz will now trigger Foo to be rebuilt as well
2082+ changeDoc doc [change]
2083+ expectDiagnostics [("Foo.hs", [])]
2084+
2085+
20492086cradleLoadedMessage :: Session FromServerMessage
20502087cradleLoadedMessage = satisfy $ \case
20512088 NotCustomServer (NotificationMessage _ (CustomServerMethod m) _) -> m == cradleLoadedMethod