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

Error when working with stack projects #65

Closed welf closed 8 years ago

welf commented 8 years ago

Every time I open an *.hs file within stack generated project and save this file, I get such error:

ghc-mod-error

This error exists only when working with project files generated by command stack new project (and followed by stack setup and stack build). When I work with standalone *.hs file I don't get such error.

OSX El Capitan 10.11.1 Atom 1.2.0 haskell-ghc-mod 1.1.3 ide-haskell 1.3.5 stack 0.1.6.0 x86_64 ghc-mod version 5.4.0.0 compiled by GHC 7.10.2

Here is a log from developer console: -1447626365072.txt

welf commented 8 years ago

I've also installed Haskell platform with all cabals, ghc-mod, hlint etc., changed paths to it in package settings, but still get the same error. I've also tried to open same files with emacs which works with ghc-mod too, and in emacs everything goes fine.

WillSewell commented 8 years ago

I get the same error.

lierdakil commented 8 years ago

@welf, I'm confused about your PATH settings. /Users/AW/.stack/programs/x86_64-osx/ghc-7.10.2/lib/ghc-7.10.2/bin/ghc this doesn't seem like a directory name?..

lierdakil commented 8 years ago

As for this error, it seems ghc-mod tries to run cabal and fails. Do you have it in your PATH?

welf commented 8 years ago

I'm confused about your PATH settings. /Users/AW/.stack/programs/x86_64-osx/ghc-7.10.2/lib/ghc-7.10.2/bin/ghc this doesn't seem like a directory name?..

It is the PATH to globally installed by stack GHC. When I change a PATH not to GHC, but to the directory which contains GHC, I get the same error.

As for this error, it seems ghc-mod tries to run cabal and fails. Do you have it in your PATH?

When I've tried to make it work with Haskell Platform, yes, it was the PATHes to Platform's GHC and to cabal in my .bash_profile file (and I changed appropriate PATHes in haskell-ghc-mod settings). After I saw I still get the same error, I've uninstalled Haskell Platform, leaving only stack. But before it I've tried how ghc-mod works in emacs, to define whether the problem is in ghc-mod itself or in haskell-ghc-mod for Atom. It worked fine, including REPL, so emacs saw the PATH to cabal in .bash_profile.

lierdakil commented 8 years ago

Well, on OSX, Atom doesn't pick up on PATH in .bash_profile unless it's started from terminal (and that's primary reason why additionalPathDirectories setting exists at all). Would that make sense?

As for path to ghc, specifying path to a file instead of directory in additionalPathDirectories can lead to problems on certain platforms. I would advise you remove it. What you actually need to do is to duplicate your .bash_profile PATH there (using comma instead of colon as a separator, and dropping $PATH or other environment variables)

See https://github.com/atom/atom/issues/6956 for more details and other solutions.

Also see https://github.com/kazu-yamamoto/ghc-mod/wiki for more information on ghc-mod with stack. In particular,

Make sure the dist/setup-config file doesn't exist in your project directory (the directory also containing your *.cabal file). When this file exists ghc-mod assumes you want to use cabal-install instead of Stack.

WillSewell commented 8 years ago

I have set it up like you say. What I find odd now is that when I run Ghc-Mod -> Check, I get this error:

screen shot 2015-11-18 at 14 13 45

And it creates directory dist in the root of my project. Although I get this error even when I manually remove dist.

(this does not happen if I run ghc-mod standalone)

welf commented 8 years ago

I've tried to start atom from terminal and it works without errors, thanks.

It worked without errors also when Atom started not from terminal, after I've copy-pasted the whole PATH string from my .bash_profile file to the Additional Path Directories field in haskell-ghc-mode settings (replacing : separator to , separator). Setting only PATH to GHC in Additional Path Directories field doesn't helped, but when I've set there all PATHes from my .bash_profile file, it started to work without errors.

Thank you a lot again!

@WillSewell Make sure that you have set the right PATH to GHC globally installed by stack, executing printf '%s\n' ~/.stack/programs/*/ghc-*/bin/ in terminal.

@lierdakil

As for path to ghc, specifying path to a file instead of directory in additionalPathDirectories can lead to problems on certain platforms. I would advise you remove it.

Please change the description of Additional Path Directories field, because it is confusing at the moment, asking to indicate PATH to ghc, but not to the directory it contains:

screenshot
lierdakil commented 8 years ago

@welf, oops. Sorry about that. I'm on it.

lierdakil commented 8 years ago

Okay, v1.1.5 should have a more clear description. Hope it is satisfactory.

WillSewell commented 8 years ago

@welf thank you! I did what you said and also installed cabal-install with stack and added its directory to Additional Path Directories. Seems to be working great now!

lierdakil commented 8 years ago

@WillSewell, in general, you shouldn't need cabal-install with stack. Just saying.

welf commented 8 years ago

Yes, I've installed cabal-install with stack too a few days ago. Don't know whether it works without it.

thunky-monk commented 8 years ago

I have the same issue as @WillSewell without cabal-install