Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

cabal project with multiple targets #1006

Closed
sboehler opened this issue Dec 23, 2018 · 6 comments
Closed

cabal project with multiple targets #1006

sboehler opened this issue Dec 23, 2018 · 6 comments
Milestone

Comments

@sboehler
Copy link

sboehler commented Dec 23, 2018

I am using nix, HIE (via https://github.com/domenkozar/hie-nix) & emacs to hack on my project here: https://github.com/sboehler/beans/tree/6524a34f85b758d055eaa923fa9005463f7b91d1. My workflow is to enter a nix-shell (see shell.nix for exact config) to to use cabal new-style build commands. I also start emacs with the recommended lsp-* packages from within the nix-shell.

When I edit any Haskell file under /src (cabal's lib:beans target), all imports are correctly detected. However, when opening a file located under /app (exe:beans target) or /tests (test:test target), HIE willl not recognize imports which are not listed under the dependencies of lib:beans in beans.cabal / package.yaml. For eample, the tasty test framework is only listed as a dependency of test:test, hence HIE reports imports from tasty as unknown.

It seems that for some reasons, only dependencies for the library target in a cabal file are detected. I am not familiar with how HIE works and whether this behavior is expected. Ideally, HIE should be aware of the corresponding cabal target of a source file and use the correct dependency list.

(Edit: replaced link to project with link to specific commit where the issue is reproducible)

@alanz alanz added this to the 2019-01 milestone Dec 24, 2018
@alanz
Copy link
Collaborator

alanz commented Dec 28, 2018

I managed to get this project set up without nix or stack, and using new-build. It complains about a missing optparse-applicative library when opening app/Main.hs, which is because ghc-mod / cabal-helper are not constructing the right GHC options for it, using the ones for the lib instead of the exe.

I will have to investigate.

@sboehler
Copy link
Author

Many thanks for investigating!

I wouldn't mind to get started hacking on HIE, but for now the interplay between cabal, ghc_mod, HIE and emacs remains a bit of a mystery to me. If you have any concrete pointer as to how to tackle this issue, I'd be happy to get involved.

For now, my workaround is to add all dependencies globally in the package.yaml, which causes hpack to add them to each target.

@alanz
Copy link
Collaborator

alanz commented Dec 28, 2018

I will be investigating this in detail, it is a problem with the new-build support. And that is a very complex beast, with lots of moving parts.

@alanz alanz modified the milestones: 2019-01, 2019-02 Feb 2, 2019
@alanz alanz modified the milestones: 2019-02, 2019-03 Mar 2, 2019
@alanz alanz modified the milestones: 2019-03, 2019-04 Apr 6, 2019
@alanz alanz modified the milestones: 2019-04, 2019-05 May 4, 2019
@alanz alanz modified the milestones: 2019-05, 2019-06 Jun 1, 2019
@alanz alanz modified the milestones: 2019-06, Some time Jul 7, 2019
@freckletonj
Copy link

freckletonj commented Sep 19, 2019

I have this same problem on Emacs 26.1+LTS-14.5. Intero is correctly reading targets, but something in the HIE stack won't use a test target, meaning dependencies break, and testing modules can't be found.

I loooove HIE and want to make it work, any guesses?

EDIT: seems related #644

it looks like this may be from ghcmod complaining that it can't find targets: DanielG/ghc-mod#668

@freckletonj
Copy link

K. solved for now at least, just gotta start fresh:

rm -r .stack-work
stack test # I think I needed to run this before ghcmod could pick up the test targets
emacs

@fendor
Copy link
Collaborator

fendor commented Dec 20, 2019

Fixed now with #1126 afaict. Please reopen if it isnt.

@fendor fendor closed this as completed Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants