atom-haskell-archive / haskell-ghc-mod

haskell-ghc-mod atom package
https://atom.io/packages/haskell-ghc-mod
MIT License
69 stars 20 forks source link

ghc-mod not working with stack project #164

Closed BillyBadBoy closed 8 years ago

BillyBadBoy commented 8 years ago

I have a simple project created using stack but ghc-mod is not being found. Info:

Haskell-ghc-mod: ghc-mod failed to launch. It is probably missing or misconfigured. ENOENT
Error: spawn ghc-mod ENOENT
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin
path: undefined
Path: undefined 
lierdakil commented 8 years ago

Could you open dev. console (View → Developer → Toggle Developer Tools) and look for warnings? I have a creeping suspicion Atom fails to find stack executable.

BillyBadBoy commented 8 years ago

console excerpt:

haskell-ghc-mod warning: No compiler found, expected minor version match with ghc-7.10.3 (x86_64) (based on resolver setting in /home/william/fib/stack.yaml).
Try running "stack setup" to install the correct GHC into /home/william/.stack/programs/x86_64-linux/

/home/william/.atom/packages/haskell-ghc-mod/lib/util.coffee:63 haskell-ghc-mod warning: Running stack path,--snapshot-install-root,--local-install-root failed with  Error: Command failed: stack path --snapshot-install-root --local-install-root(…)
/home/william/.atom/packages/haskell-ghc-mod/lib/util.coffee:63 haskell-ghc-mod warning: No stack sandbox found because  Error: Command failed: stack path --snapshot-install-root --local-install-root(…)
/home/william/.atom/packages/haskell-ghc-mod/lib/util.coffee:56 haskell-ghc-mod debug: PATH = function resolve() { [native code] }:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin
/home/william/.atom/packages/haskell-ghc-mod/lib/util.coffee:56 haskell-ghc-mod debug: Running ghc-mod version with opts =  Object
/home/william/.atom/packages/haskell-ghc-mod/lib/util.coffee:63 haskell-ghc-mod warning: Running ghc-mod version failed with  Error: spawn ghc-mod ENOENT(…)
BillyBadBoy commented 8 years ago

BTW if I run atom via stack exec atom then everything works fine.

BillyBadBoy commented 8 years ago

more info:

$ which stack
$ /usr/bin/stack
lierdakil commented 8 years ago

Okay, quick sanity check then. Check you stack version, and whether command stack path --snapshot-install-root --local-install-root produces meaningful output.

BillyBadBoy commented 8 years ago

stack version = 1.1.2

Where should I run the stack path command from ? project directory? home directory ?

lierdakil commented 8 years ago

Project directory

BillyBadBoy commented 8 years ago
$ stack path --snapshot-install-root --local-install-root
snapshot-install-root: /home/william/.stack/snapshots/x86_64-linux/lts-6.6/7.10.3
local-install-root: /home/william/myProj/.stack-work/install/x86_64-linux/lts-6.6/7.10.3
lierdakil commented 8 years ago

Huh. Okay. I think I figured out what the problem is. Do you happen to have 'Cabal Sandbox' option disabled? If so, then try updating haskell-ghc-mod to 1.15.1, it should probably work.

BillyBadBoy commented 8 years ago

That didn't help.

But I've noticed something strange. I'm using linux mint and normally start atom by clicking on a launch applet on my desktop. This launcher seems to be the problem. If I launch atom from a terminal (from any directory) then ghc-mod is OK.

lierdakil commented 8 years ago

This is really strange. Do you happen to have some stack- or PATH-related setup in your .bashrc/.zshrc?

BillyBadBoy commented 8 years ago

You're right - my .bashrc file contains entries I used to rely on in my pre-stack days:

export PATH="$HOME/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH"

If I comment this out then ghc-mod is broken regardless of how I launch atom.

lierdakil commented 8 years ago

Try running stack setup in your project directory.

BillyBadBoy commented 8 years ago

I tried removing the globally installed ghc and this causes atom to break from both my launcher and the command line. So it's the global ghc that somehow allows ghc-mod to work when I launch from the command line.

With the global ghc removed I ran stack setup which caused a local ghc to be installed. Atom ghc-mod still broken - but failing with completely different error messages.

I'm rebuilding local ghc-mod to see if this makes a difference.

BillyBadBoy commented 8 years ago

It now works!!!

After doing this it still did not work. The error was not atom related since I could reproduce it from the command line:

~/myProj $ stack exec ghc-mod check /home/william/myProj/src/Lib.hs
ghc-mod: /opt/ghc/7.10.3/lib/ghc-7.10.3/settings: openFile: does not exist (No such file or directory)

For some reason ghc-mod was trying to access a file from the deleted global ghc installation. I was unable to figure out where the invalid path was being stored, so in desperation I tried removing and then re-installing the stack executable (followed by stack setup), which seems to have fixed everything.


So, the end result is that haskell-ghc-mod now works on my machine but at the cost of having to remove my global ghc installation.

Thanks for all your help.

BillyBadBoy commented 8 years ago

Since my original problem is now fixed I'm closing this issue.