ghciwatch
ghciwatch copied to clipboard
Parse Haskell source paths more reliably
Haskell source paths, as GHC understands them, are remarkably permissive: they must end with one of the source extensions (now more accurately listed here, with references to the upstream GHC code), but can otherwise contain quirks up to and including multiple extensions, whitespace, and newlines.
GHCi is actually even more lenient than this in what it accepts; it'll automatically append .hs
and .lhs
to paths you give it and check if those exist, but fortunately they get printed out in :show targets
and diagnostics as the resolved source paths:
ghci> :add src/MyLib
[1 of 1] Compiling MyLib ( src/MyLib.hs, interpreted )
ghci> :show targets
src/MyLib.hs
ghci> :add src/Foo
target ‘src/Foo’ is not a module name or a source file
ghci> :add src/MyLib.lhs
File src/MyLib.lhs not found
ghci> :add "src/ Foo.hs"
File src/ Foo.hs not found
ghci> :add "src\n/Foo.hs"
File src
/Foo.hs not found
Split off of #297