Cabal mixins and custom preludes using stack
HLS is not able to resolve symbols in custom preludes (e.g. relude) when the mixins way is used to replace Prelude:
mixins: base hiding (Prelude)
, relude (Relude as Prelude)
Other methods, such as base-noprelude or NoImplicitPrelude are instead correctly supported.
N.
also (last I checked) you can't have multiple Prelude modules in a project with multiple packages, even if they're not exposed in the cabal conf
@awgn thanks for the bug report, could you include the logs suggested in the issue template?
Are you using stack to build the project?, it does not support well mixins for stack repl (and hls uses it underneath), see #823
Hello @jneira,
Yes, I'm using stack to build the project and it works. However, here's the HLS log:
/Users/admin/Library/Application\ Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-darwin-8.10.3 --debug
haskell-language-server version: 0.9.0.0 (GHC: 8.10.3) (PATH: /Users/admin/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-darwin-8.10.3) (GIT hash: 46d2a3dc7ef49ba57b2706022af1801149ab3f2b)
(haskell-language-server)Ghcide setup tester in /Users/admin/GitLab/Aggr.
Report bugs at https://github.com/haskell/haskell-language-server/issues
Tool versions found on the $PATH
cabal: 2.4.1.0
stack: 2.5.1
ghc: Not found
Step 1/4: Finding files to test in /Users/admin/GitLab/Aggr
Found 4 files
Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
Step 3/4: Initializing the IDE
Step 4/4: Type checking the files
[INFO] Consulting the cradle for "src/Options.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtInfo, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Options.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).\nYou should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error."}})
Output from setting up the cradle Cradle {cradleRootDir = "/Users/admin/GitLab/Aggr", cradleOptsProg = CradleAction: Stack}
> Using main module: 1. Package `aggr' component aggr:exe:aggr with main-is file: /Users/admin/GitLab/Aggr/src/Main.hs
> WARNING: Ignoring aggr's bounds on base (>=4.13.0.0 && <4.14); using base-4.14.1.0.
> Reason: allow-newer enabled.
> WARNING: Ignoring aggr's bounds on relude (^>=0.6.0.0); using relude-0.7.0.0.
> Reason: allow-newer enabled.
> The following GHC options are incompatible with GHCi and have not been passed to it: -O2 -threaded
> Configuring GHCi with the following packages: aggr
> /Users/admin/GitLab/Aggr/.stack-work/install/x86_64-osx/d8736836b7c8b2987496aca0156b54e80ba9783d0ac19f73563d18c936043ff7/8.10.3/pkgdb:/Users/admin/.stack/snapshots/x86_64-osx/d8736836b7c8b2987496aca0156b54e80ba9783d0ac19f73563d18c936043ff7/8.10.3/pkgdb:/Users/admin/.stack/programs/x86_64-osx/ghc-8.10.3/lib/ghc-8.10.3/package.conf.d
[INFO] Using interface files cache dir: ghcide
[INFO] Making new HscEnv[main]
[INFO] Consulting the cradle for "Setup.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtInfo, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for Setup.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).\nYou should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error."}})
Output from setting up the cradle Cradle {cradleRootDir = "/Users/admin/GitLab/Aggr", cradleOptsProg = CradleAction: Stack}
File: /Users/admin/GitLab/Aggr/Setup.hs
Hidden: no
Range: 1:1-2:1
Source: cradle
Severity: DsError
Message:
Multi Cradle: No prefixes matched
pwd: /Users/admin/GitLab/Aggr
filepath: /Users/admin/GitLab/Aggr/Setup.hs
prefixes:
("./src/Main.hs",Stack {component = Just "aggr:exe:aggr", stackYaml = Nothing})
("./src/Options.hs",Stack {component = Just "aggr:exe:aggr", stackYaml = Nothing})
("./src/Colors.hs",Stack {component = Just "aggr:exe:aggr", stackYaml = Nothing})
("./src/Paths_aggr.hs",Stack {component = Just "aggr:exe:aggr", stackYaml = Nothing})
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 96:19-96:27
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
mapMaybe
:: (SC.ByteString -> Maybe a5) -> [SC.ByteString] -> [A.Object]
• Perhaps you meant one of these:
‘M.mapMaybe’ (imported from Data.Map.Strict),
‘H.mapMaybe’ (imported from Data.HashMap.Strict)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 102:5-102:10
Source: typecheck
Severity: DsError
Message: Variable not in scope:forM_ :: [(T.Text, Int)] -> ((T.Text, a4) -> IO ()) -> IO ()
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 121:24-121:30
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
foldl'
:: (AggrMap -> [T.Text] -> AggrMap)
-> M.Map k2 a12 -> [[T.Text]] -> M.Map k a
• Perhaps you meant one of these:
‘M.foldl'’ (imported from Data.Map.Strict),
‘C.foldl'’ (imported from Data.ByteString.Lazy.Char8),
‘T.foldl'’ (imported from Data.Text)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 126:62-126:68
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
sortBy :: t2 -> [(k0, a6)] -> [(T.Text, Info)]
• Perhaps you meant ‘SC.sort’ (imported from Data.ByteString.Char8)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 126:78-126:82
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
on :: (a10 -> a10 -> Ordering) -> ((a7, b4) -> b4) -> t2
• Perhaps you meant ‘or’ (imported from Prelude)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 127:61-127:67
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
sortBy :: t3 -> [(k1, a8)] -> [(T.Text, Info)]
• Perhaps you meant ‘SC.sort’ (imported from Data.ByteString.Char8)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 127:77-127:81
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
on :: (a11 -> a11 -> Ordering) -> ((a9, b5) -> b5) -> t3
• Perhaps you meant ‘or’ (imported from Prelude)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 191:32-191:37
Source: typecheck
Severity: DsError
Message: Variable not in scope:forM_ :: [(T.Text, Info)] -> ((T.Text, Info) -> IO b2) -> IO ()
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 198:5-198:11
Source: typecheck
Severity: DsError
Message: Variable not in scope: unless :: Bool -> IO () -> IO b2
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 199:37-199:43
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
sortBy :: t1 -> [(T.Text, Info)] -> [(T.Text, Info)]
• Perhaps you meant ‘SC.sort’ (imported from Data.ByteString.Char8)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 199:53-199:57
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
on :: (a3 -> a3 -> Ordering) -> ((a2, b3) -> b3) -> t1
• Perhaps you meant one of these:
‘n’ (line 191), ‘or’ (imported from Prelude)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 203:33-203:38
Source: typecheck
Severity: DsError
Message: Variable not in scope:forM_ :: [(T.Text, Info)] -> ((T.Text, Info) -> IO b0) -> IO ()
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 209:5-209:11
Source: typecheck
Severity: DsError
Message: Variable not in scope: unless :: Bool -> IO () -> IO b0
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 210:38-210:44
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
sortBy :: t0 -> [(T.Text, Info)] -> [(T.Text, Info)]
• Perhaps you meant ‘SC.sort’ (imported from Data.ByteString.Char8)
File: /Users/admin/GitLab/Aggr/src/Main.hs
Hidden: no
Range: 210:54-210:58
Source: typecheck
Severity: DsError
Message:
• Variable not in scope:
on :: (a1 -> a1 -> Ordering) -> ((a0, b1) -> b1) -> t0
• Perhaps you meant one of these:
‘n’ (line 203), ‘or’ (imported from Prelude)
[INFO] finish: User TypeCheck (took 0.89s)
Files that failed:
* /Users/admin/GitLab/Aggr/Setup.hs
Completed (3 files worked, 1 file failed)
The variables reported as not found are not explicitly imported because Relude imports them automatically.
N.
Thanks for pasting the logs, maybe it would not be strictly neccesary but good to have it to let other users compare with theirs.
I am gonna label it as blocked upstream as, in the current state of hie-bios we depend on stack repl support directly.
To confirm it definitely, the same error throwed by hls should be throwed if you load the file with stack repl.
The upstream issue would be https://github.com/commercialhaskell/stack/issues/5077 The obvious workaround for now could be using cabal instead (although we aim to support stack)
As a thread bump, I'll note that the workaround with base-noprelude can be crossed out: it's not viable anymore, because the package is no longer updated for recent versions of base.
Which leaves us HLS users with:
-
-XNoImplicitPrelude— defeats the entire idea of having a localPreludemodule; - switching from Stack to Cabal — not OK in some projects/teams;
- disappointment & reversal to explicit
import MyLocalPreludein every module.
GHC bug #10920 seems also relevant.