ndmitchell / ghcid

Very low feature GHCi based IDE
Other
1.13k stars 114 forks source link

Execute on save? #305

Closed GrayStrider closed 4 years ago

GrayStrider commented 4 years ago

I'm new to Haskell, coming from TypeScript background, trying to set up hot-reload environment; This seem to work nicely for error checking (and lightning fast), but there's seems to be no way to evaluate print / putStrLn expressions. I suppose because it only compiles and not runs. The best solution I've found so far that doesn't involve this tool: stack build --fast && stack exec playground-exe, but that requires a file watcher set up. Some automatic test runner would be nice to have, too. Any comments?

ndmitchell commented 4 years ago

Are you looking for --test? That can cause it to run something on every save.

GrayStrider commented 4 years ago

Thanks, that works great. Sorry for not RTFM.

If you could be bothered to answer one more question, perhaps would be better suited on SO: with --test main I can run main module from app/Main.hs:

module Main where

import Lib

main :: IO ()
main = someFunc

what about test/Spec.hs, how would I go about running that on save?

main :: IO ()
main = putStrLn "Test suite not yet implemented"

I see it doesn't have module defined, is it only meant to be executed from stack? Thanks for the help.

GrayStrider commented 4 years ago

I think I got it, I have :load Main defined in config. So I would just have to specify a different module and run it separately?

ndmitchell commented 4 years ago

Probably best asked on SO, since I do things quite different to most people. The lack of a module means the test is implicitly module Main where, and GHC can't cope with two modules named the same thing. I always adjust the module name to module Test where and then use the GHC flag -main-is to get it to compile. But I'm different to most people, so recommend getting the official advaice.