fpco / ide-backend

ide-backend drives the GHC API to build, query, and run your code
120 stars 17 forks source link

qAddDependentFile no longer triggers recompile #313

Open snoyberg opened 8 years ago

snoyberg commented 8 years ago

Minimal reproducing test case:

{-# LANGUAGE OverloadedStrings #-}
import IdeSession
import Data.Monoid
import Data.String

foo_hs, foo_txt1, foo_txt2 :: IsString a => a
foo_hs =
    "{-# LANGUAGE TemplateHaskell #-}\n\
    \import Language.Haskell.TH.Syntax\n\
    \main = print $(do\n\
    \    let fp = \"foo.txt\"\n\
    \    qAddDependentFile fp\n\
    \    str <- qRunIO $ readFile fp\n\
    \    lift str)"
foo_txt1 = "version1"
foo_txt2 = "version2"

wdir = do
    writeFile "foo.hs" foo_hs
    writeFile "foo.txt" foo_txt1
    return (conf, update, mupdate2)
  where
    conf = defaultSessionConfig { configLocalWorkingDir = Just "." }
    update = mempty
    mupdate2 = do
        writeFile "foo.txt" foo_txt2
        return mempty

nowdir =
    return (defaultSessionConfig, update, mupdate2)
  where
    update = updateSourceFile "foo.hs" foo_hs
          <> updateDataFile "foo.txt" foo_txt1
    mupdate2 = return $ updateDataFile "foo.txt" foo_txt2

main :: IO ()
main = do
    putStrLn "Working directory"
    go wdir

    putStrLn "===========\nNo working directory"
    go nowdir

go mtriple = do
    (conf, update, mupdate2) <- mtriple

    sess <- initSession defaultSessionInitParams conf

    updateSession sess
        (updateTargets (TargetsInclude ["foo.hs"]) <>
         updateCodeGeneration True <>
         update)
        print

    runIt sess

    putStrLn "\n\nUpdating file"
    update2 <- mupdate2
    updateSession sess update2 print
    runIt sess

runIt sess = do
    getSourceErrors sess >>= print
    ra <- runStmt sess "Main" "main"
    let loop = do
            res <- runWait ra
            case res of
                Left bs -> print bs >> loop
                Right x -> print x
    loop

I at first thought this was a problem with the working directory case, but turns out the non-working-directory case also demonstrates the issue. This was working in the past, and I thought there were test cases for it.

Originally reported in urbanslug/wai-devel#6

rvion commented 8 years ago

Any news about this ?

urbanslug commented 8 years ago

@rvion Not yet, sorry.