haskell-ghc-mod icon indicating copy to clipboard operation
haskell-ghc-mod copied to clipboard

Option to automatically build ghc-mod and hlint inside Stack-based projects

Open varosi opened this issue 8 years ago • 24 comments

I have written about that elsewhere, but this is what EclipseFP was doing before in Eclipse for cabal-based projects into a sandbox. It think that this will help with easier use of atom-haskell and closer to "just works" concept. If we're using multiple projects inside same Atom editor - it could use different ghc-mod executables for each project depending on its stack resolver. Currently I do this by hand each time outside Atom.

varosi avatar Jun 15 '16 13:06 varosi

Recent enough versions of stack (tested with 1.1.2) should generally install ghc-mod into snapshot. So, in general, you should only need to do this once per resolver. Unless you update to nightlies daily (which doesn't sound good), it should be bearable.

Automatic builds come with a lot of caveats, I say that from my (admittedly limited) experience with SublimeHaskell plugin, which attempts (or at least attempted) to build ghc-mod automatically. Suffice to say, it didn't work all that well.

There's also an issue of newcomers to Haskell. Long story short, if ghc-mod would fail to build automatically, it would be a nightmare to debug this with someone who has a very vague idea of what's going on. Current setup process, while cumbersome, at least makes this explicit.

Lastly, it's really hard to judge user intent w.r.t. stack vs cabal without explicit user input.

What I'm trying to say is, this kind of thing is really, really hard to get right. And between fragmented PATH settings in ide-haskell packages and ghc-8 support I really don't think I can spare the kind of time and thought this really needs right now.

PRs are welcome, but for now this is "wontfix".

2016-06-15 16:27 GMT+03:00 varosi [email protected]:

I have written about that elsewhere, but this is what EclipseFP was doing before in Eclipse for cabal-based projects into a sandbox. It think that this will help with easier use of atom-haskell and closer to "just works" concept. If we're using multiple projects inside same Atom editor - it could use different ghc-mod executables for each project depending on its stack resolver. Currently I do this by hand each time outside Atom.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/atom-haskell/haskell-ghc-mod/issues/159, or mute the thread https://github.com/notifications/unsubscribe/AG8EZhcNYOg8d0rONH-x7aAipClqBJOpks5qL_3UgaJpZM4I2Wuo .

lierdakil avatar Jun 16 '16 04:06 lierdakil

This could be an option to choose. I just want to think in a direction for easy to setup Haskell working environment with a few steps. The ideal case will be "Next...Next...Finish".

Thanks for the full answer on that.

varosi avatar Jun 16 '16 17:06 varosi

Is it possible to make an option to select custom path to ghc-mod depending on GHC version? I mean if current project is built with GHC 7.10.3 to set path to ghd-mod built with it. If I have project with GHC 8.0.1 to use different path to ghc-mod built with this GHC. This will save me a lot of time of rebuilding ghc-mod when I switch projects. Ideally this should work with multiple Haskell projects folders opened in Atom.

varosi avatar Nov 28 '16 13:11 varosi

I'll see what I can do.

lierdakil avatar Dec 01 '16 09:12 lierdakil

Coool!

varosi avatar Dec 01 '16 17:12 varosi

This will be great option! It's everyday problem when one works on multiple projects each built with different LTS.

varosi avatar Apr 21 '17 14:04 varosi

Actually, working on different projects should "just work", regardless of resolver used, since ghc-mod is installed into snapshot, so all projects using a given resolver can share it...

lierdakil avatar Jul 02 '17 22:07 lierdakil

Yes, only if it is already installed per project. This is a very common task and it'll be great if it's automated by the IDE.

varosi avatar Jul 03 '17 11:07 varosi

This feature of Stack could help a lot on that issue - https://github.com/commercialhaskell/intero/issues/324

varosi avatar Dec 28 '17 20:12 varosi

Other related issue - https://github.com/commercialhaskell/stack/issues/3717

varosi avatar Dec 28 '17 20:12 varosi

Cool. Thanks for the heads-up.

lierdakil avatar Dec 28 '17 23:12 lierdakil

So, after God knows how long, this is finally implemented in v2.2.0. Thanks for your patience. In my defense, this became viable only recently due to massive internal changes. And by recently I mean around v2.0.10.

Implementation might be rough around the edges, and is strictly opt-in for now (which will be changed once the feature is tested "in the wild" and most prominent kinks are ironed out)

You can opt-in by enabling this option in h-g-m settings: image

A few caveats exist:

  • Building ghc-mod is only suggested when you have ide-haskell-cabal, and you have chosen builder to be stack.
  • It runs stack --copy-compiler-tool build ghc-mod, so you need recent enough stack. Note this might be somewhat suboptimal, since it won't update ghc-mod if a newer version lands in a new resolver. On another hand, rebuilding ghc-mod on every resolver change doesn't sound like much fun either (although that's exactly what we've been doing for a while now)

When Atom detects version mismatch, it does this: image

One rather important thing, from the top of my head, is missing. It doesn't prioritize stack/cabal sandbox depending on chosen builder. In some setups (admittedly, somewhat exotic, both stack.yaml and cabal-sandbox.config, ghc-mod installed into cabal sandbox), this may lead to some frustration.

lierdakil avatar Dec 29 '17 04:12 lierdakil

Great! I have tried it after updating of Atom and plug-ins. But I hit a problem when I deleted ghc-mod installed on PATH. Plug-in failed with:

Haskell-ghc-mod: ghc-mod failed to launch. It is probably missing or misconfigured. ENOENT

i.e. it even does not proposed me to build it. The new option is already enabled. May be it is not executed via stack, like:

stack exec -- ghc-mod ...

varosi avatar Dec 29 '17 21:12 varosi

It runs stack --copy-compiler-tool build ghc-mod, so you need recent enough stack.

About this problem - stack version could be verified automatically with: stack --version

varosi avatar Dec 29 '17 21:12 varosi

To be clear, did you get 'Failed to check compiler versions' error among other things?

lierdakil avatar Dec 29 '17 21:12 lierdakil

Addition: when I have done:

stack build --copy-compiler-tool ghc-mod

It executed ghc-mod. So the problem is when it is not built at both places.

But later I got:

EXCEPTION: browse: ghc-mod: can't find a package database at C:\stack\snapshots\726bcf65\pkgdb EXCEPTION: info: ghc-mod: can't find a package database at C:\stack\snapshots\726bcf65\pkgdb ghc-mod: ghc-mod: can't find a package database at C:\stack\snapshots\726bcf65\pkgdb EXCEPTION: types:

varosi avatar Dec 29 '17 21:12 varosi

I don't find any "Failed to check compiler versions" message in the console. It's only that exception message.

varosi avatar Dec 29 '17 21:12 varosi

See if v2.2.2 works any better. Thanks for testing by the way!

lierdakil avatar Dec 29 '17 22:12 lierdakil

Thanks for working on this issue! New version gives the same error. But the error is giving wrong path "C:\stack...". Currently after update to some later Stack it's located under "C:\sr". So I have deleted .stack-work subfolder and after a long running wait process (where nothing is seen because there were no output during the process - only at the end) it is WORKING!!! Cool! It looks like it built the project from scratch, that is way it was long running process!

varosi avatar Dec 29 '17 23:12 varosi

Is it possible HLint to be built with ghc-mod, too? It's used in haskell-ghc-mod plug-in and it could be built automatically.

varosi avatar Dec 30 '17 12:12 varosi

btw, installing of most recent ghc-mod (8.2.2, 8.2.1, 8.0.2, 8.0.1) could happen on plug-in install time as people expect there to be lost most of installing time. But it's just a proposition.

varosi avatar Dec 30 '17 12:12 varosi

I'm testing here at different projects and it's working very well! It's one of the best and useful features of haskell-ghc-mod!

varosi avatar Dec 30 '17 15:12 varosi

Is it possible HLint to be built with ghc-mod, too? It's used in haskell-ghc-mod plug-in and it could be built automatically.

It's a dependency of ghc-mod. Hence, it's built anyway. And h-g-m doesn't call the binary directly.

lierdakil avatar Dec 30 '17 22:12 lierdakil

Okay, great!

varosi avatar Dec 30 '17 22:12 varosi