I configured hie-bios with a hie.yaml containing cradle: {stack} and ran stack exec hie-bios check test/ParserTest.hs command with success. (See snippet 1 below.)
When running a similar stack exec ghcide test/ParserTest.hs command (see snippet 2), it gives a bunch of It is a member of the hidden package ... errors for various packages that are listed as dependencies for the test suite only in both package.yaml and the project's .cabal file.
For convenience, I've aligned stack.yaml with that of ghcide.
$ stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5
$ stack exec hie-bios version
hie-bios version 0.2.0 compiled by GHC 8.6.5
$ stack exec ghcide -- --help 2>&1 | head -n 1
Starting ghcide (GHC v8.6)
$ stack exec hie-bios check test/ParserTest.hs
cradle
Cradle {cradleRootDir = "/home/simon/Projects/hs-jq", cradleOptsProg = CradleAction: stack}
setTargets
(test/ParserTest.hs , test/ParserTest.hs)
[*test/ParserTest.hs]
modGraph
[ModSummary {
ms_hs_date = 2019-09-19 02:13:56.86183751 UTC
ms_mod = ParserTest,
ms_textual_imps = [(Nothing, Prelude),
(Nothing, Data.Aeson.Jq.Parser), (Nothing, Data.Aeson.Jq.Expr),
(Nothing, Test.Tasty.Hspec), (Nothing, Text.RawString.QQ),
(Nothing, Text.Megaparsec), (Nothing, Test.Hspec.Megaparsec),
(Nothing, Hedgehog), (Nothing, Data.Void), (Nothing, Data.Text),
(Nothing, Data.Text), (Nothing, Data.Foldable),
(Nothing, Data.Char)]
ms_srcimps = []
}]
modGraph
[ModLocation {ml_hs_file = Just "test/ParserTest.hs", ml_hi_file = "/home/simon/.cache/haskell-ide-engine/d7028de75ffc3bc45b7e23b3c3d3bfaedfe6d7bb/ParserTest.hi", ml_obj_file = "/tmp/ghc14235_0/ghc_1.o"}]
hidir
Just [/, h, o, m, e, /, s, i, m, o, n, /, ., c, a, c, h, e, /, h,
a, s, k, e, l, l, -, i, d, e, -, e, n, g, i, n, e, /, d, 7, 0, 2,
8, d, e, 7, 5, f, f, c, 3, b, c, 4, 5, b, 7, e, 2, 3, b, 3, c, 3,
d, 3, b, f, a, e, d, f, e, 6, d, 7, b, b]
test/ParserTest.hs:6:1:Warning: The import of ‘Data.Char’ is redundant except perhaps to import instances from ‘Data.Char’To import instances alone, use: import Data.Char()
test/ParserTest.hs:7:1:Warning: The import of ‘Data.Foldable’ is redundant except perhaps to import instances from ‘Data.Foldable’To import instances alone, use: import Data.Foldable()
test/ParserTest.hs:12:1:Warning: The import of ‘Hedgehog’ is redundant except perhaps to import instances from ‘Hedgehog’To import instances alone, use: import Hedgehog()
$ stack exec ghcide test/ParserTest.hs
Starting ghcide (GHC v8.6)
/home/simon/Projects/hs-jq
[1/6] Finding hie-bios cradle
Cradle {cradleRootDir = "/home/simon/Projects/hs-jq", cradleOptsProg = CradleAction: stack}
[2/6] Converting Cradle to GHC session
[3/6] Initialising IDE session
[4/6] Finding interesting files
Found 1 files
[5/6] Setting interesting files
[DEBUG] Set files of interest to: [NormalizedFilePath "test/ParserTest.hs"]
[DEBUG] Starting shakeRun (aborting the previous one took 0.00s)
[6/6] Loading interesting files
[DEBUG] Finishing shakeRun (took 0.00s, exception: thread killed)
[DEBUG] Starting shakeRun (aborting the previous one took 0.00s)
File: test/ParserTest.hs
Range: 12:17-12:25
Source: not found
Severity: DsError
Message:
Could not load module ‘Hedgehog’
It is a member of the hidden package ‘hedgehog-1.0’.
You can run ‘:set -package hedgehog’ to expose it.
(Note: this unloads all the modules in the current scope.)
File: test/ParserTest.hs
Range: 13:17-13:38
Source: not found
Severity: DsError
Message:
Could not load module ‘Test.Hspec.Megaparsec’
It is a member of the hidden package ‘hspec-megaparsec-2.0.1’.
You can run ‘:set -package hspec-megaparsec’ to expose it.
(Note: this unloads all the modules in the current scope.)
File: test/ParserTest.hs
Range: 15:17-15:34
Source: not found
Severity: DsError
Message:
Could not load module ‘Text.RawString.QQ’
It is a member of the hidden package ‘raw-strings-qq-1.1’.
You can run ‘:set -package raw-strings-qq’ to expose it.
(Note: this unloads all the modules in the current scope.)
File: test/ParserTest.hs
Range: 16:17-16:33
Source: not found
Severity: DsError
Message:
Could not load module ‘Test.Tasty.Hspec’
It is a member of the hidden package ‘tasty-hspec-1.1.5.1’.
You can run ‘:set -package tasty-hspec’ to expose it.
(Note: this unloads all the modules in the current scope.)
[DEBUG] Finishing shakeRun (took 0.07s, completed)
Files that worked: 0
Files that failed: 1
* test/ParserTest.hs
Done
A temporary fix is to add the test dependencies to the library dependencies. This is of course no permanent solution, but allows to keep developing while this issue gets fixed.
This is an issue in haskell-ide-engine too: https://github.com/haskell/haskell-ide-engine/issues/1362
A temporary fix is to add the test dependencies to the library dependencies.
... needing to touch another file that is version-controlled by the project, just to be able to edit properly.
(Already need to do this for stack.yaml (sometimes multiple ones for multiple versions of GHC) in order to get the warnings you want).
... and then you have to be very careful not to commit your modifications accidentally, and juggle them whenever you need to rebase. In short, a nightmare, which really degrades the development experience.
A temporary fix is to add the test dependencies to the library dependencies.
Yes, I did that. Thanks.
needing to touch another file that is version-controlled by the project
Yes, it is not a durable solution that the IDE needs so much control over the codebase of a project to function properly; for projects that can't allow this littering, you must constantly add and remove these IDE tweaks, either as uncommitted changes, stashed or in feature branches where you remove them again before merging to master.
Since the packages I work on are not released, this is not a big problem for me.
But I'm sure that those who have used ghcide with more success have found a way to avoid the red wobbly lines that signify dependency problems in all test files? Do they ignore dependency checking in test files?
@sshine I always use direct cradles and a global Cabal install - but that's the approach I've always used with ghcide too. It's simple, effective and gives a great developer experience (until it all goes wrong, and then I just give up and reinstall GHC).
@ndmitchell: Do you have an example of a direct cradle that works for your test directories?
I think this is the cradel @ndmitchell was referring to: https://github.com/digital-asset/ghcide/blob/master/hie.yaml
Closing as a duplicate of the issue on multi-component support #113.
Most helpful comment
A temporary fix is to add the test dependencies to the library dependencies. This is of course no permanent solution, but allows to keep developing while this issue gets fixed.