ndmitchell / ghcid

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

GHCJS support? #171

Open NickSeagull opened 6 years ago

NickSeagull commented 6 years ago

I'm currently trying to use ghcid for a project, while for the backend it works perfectly, the frontend ghcjsi doesnt seem to be reloaded on file changes. Is there a reason for this?

What would it take to make ghcid work with GHCJS? I'd be happy to submit a PR to fix it :smile:

ndmitchell commented 6 years ago

I don't know what the problem is, but would accept a PR to fix it. If you pass --verbose to ghcid it should say what it's sending, which might give you some clues.

NickSeagull commented 6 years ago

It spits out some errors:

Loading cabal new-repl frontend ...
%STDERR: Warning: don't know how to find change monitoring files for the installed
%STDOUT2: Warning: don't know how to find change monitoring files for the installed
Warning: don't know how to find change monitoring files for the installed
%STDERR: package databases for ghcjs
%STDOUT2: package databases for ghcjs
package databases for ghcjs
%STDOUT: Resolving dependencies...
%STDOUT2: Resolving dependencies...
Resolving dependencies...
%STDOUT: Build profile: -w ghcjs-0.2.0 -O1
%STDOUT2: Build profile: -w ghcjs-0.2.0 -O1
Build profile: -w ghcjs-0.2.0 -O1

Any pointers about where should I start to look @ndmitchell ?

ndmitchell commented 6 years ago

It spits out some messages, but not sure any of those are fatal - Ghcid is just echoing them from the underlying command. I'd look elsewhere - or perhaps share a complete log.

NickSeagull commented 6 years ago

Taking a go with the complete log, perhaps you can see something obvious I cant :smile:

full log

ndmitchell commented 6 years ago

Does :set prompt foo work in new-repl? How much like normal ghci is the experience? I would be expecting stdin lines to be in the output, but I can't find them. Which version of ghcid are you using?

For info, the prefix of my session says:

C:\Neil\hlint>ghcid --verbose
Loading ghci -fno-code -fno-break-on-exception -fno-break-on-error -v1 -ferror-spans -j ...
%STDOUT: GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
%STDOUT2: GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
%STDIN: import qualified System.IO as INTERNAL_GHCID
%STDIN: :set prompt #~GHCID-START~#
%STDIN: :set -fno-break-on-exception
%STDIN: :set -fno-break-on-error
%STDIN: :set -v1
%STDIN: :set -fno-hide-source-paths
%STDIN: INTERNAL_GHCID.putStrLn ['#','~','G','H','C','I','D','-','F','I','N','I','S','H','-','1','~','#']
INTERNAL_GHCID.hPutStrLn INTERNAL_GHCID.stderr ['#','~','G','H','C','I','D','-','F','I','N','I','S','H','-','1','~','#']
GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help

e.g. full of STDIN.

NickSeagull commented 6 years ago

Yes, setting the prompt works.

cabal new-repl is exactly like cabal repl except that it uses the package management capabilities of cabal to behave like stack.

Looks like the problem is definitely ghcjs, as if I run ghcid -c 'cabal new-repl' on the backend cabal project, it works.

ndmitchell commented 6 years ago

Can you confirm you are on the latest ghcid version? And which version that is? ghcid --version should tell you.

Does putStrLn "foo" work in ghcjs, or does the output go to a web browser?

NickSeagull commented 6 years ago

Forgot to mention the version, I got ghcid v0.7 from Stackage. Should I stack install the one in this repo?

On the other hand, yes, it does print to STDOUT, the output doesnt go to the browser.

ndmitchell commented 6 years ago

0.7 is fine. I'm not really sure why it doesn't work, or why mine shows the stdin lines. Does yours show stdin lines in the cases it does work?

NickSeagull commented 6 years ago

Yep, with regular ghc it shows STDIN

ndmitchell commented 6 years ago

Reading the logs more closely, I found why it wasn't printing out stdout (just read the diff above and it will be obvious!). Can you compile HEAD and confirm that it works in practice?

NickSeagull commented 6 years ago

Now the STDIN part shows up! :smile:

Although it still doesnt reload the code :(

Here's the log:

https://gist.github.com/NickSeagull/66b00654d9304e935b54150e3723dd95

ndmitchell commented 6 years ago

Progress!

Next problem is it seems that INTERNAL_GHCID.hPutStrLn INTERNAL_GHCID.stderr ['#','~','G','H','C','I','D','-','F','I','N','I','S','H','-','1','~','#'] doesn't result in a message being put on stderr. Can you try that by hand (with just hPutStrLn stderr "hello") and confirm?

NickSeagull commented 6 years ago

Looks like it worked properly:

*Main System.IO> hPutStrLn stderr "hello"
hello
ndmitchell commented 6 years ago

Can we confirm the message ends up on stderr and not stdout? Perhaps run ghcijs piping stderr to a file, eg "ghcijs 2> stderr.txt" - then we can see if it ends up on the screen or not.

NickSeagull commented 6 years ago

Looks like stderr ends up in stdout as it prints the string on screen. Any ideas what could be done next?

ndmitchell commented 6 years ago

Could that be fixed in ghcjs? I can think of a workaround, but always better to fix at the source.

NickSeagull commented 6 years ago

Ok, let me see if I can open an issue for them

ndmitchell commented 6 years ago

Cheers, please cc me on the issue as well.

ndmitchell commented 6 years ago

See https://github.com/ghcjs/ghcjs/issues/671