haskell-ide-engine
haskell-ide-engine copied to clipboard
How to use hie with GHCI setup (no cabal, no stack)
I would like to use hie in vscode on a project where I used to be using ghci/ghcid (no cabal, no stack).
I am having trouble getting import XXXX
of my other modules to be resolved. Here is the important pieces from my .ghci
file
:set -fwarn-unused-binds
:set -fwarn-unused-imports
:set -isrc
:set -icis194/week12
:load main.hs
I need hie to know that src
and cis194/week12
should be searched by GHC.
How do I tell hie that?
I tried a hie.yaml
on the form
cradle:
direct:
arguments:
- -Wunused-binds
- -Wunused-imports
- -Worphans
- -isrc
- -icis194/week12
The server crashes 5 times on this one.
Also is it supported to have
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
on the source files, or is
IIRC, hie.yaml
should have the form:
cradle:
direct:
arguments:
- -Wunused-binds
- -Wunused-imports
- -Worphans
- -isrc
- -icis194/week12
But then this ought to work. Can you try it, too? If it does not work, please link the output of hie --debug .
here.
Also is it supported to have
{-# OPTIONS_GHC -Wall #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
on the source files, or is
Yes, that is supported. If not, please open ticket :)
Thanks for the quick response:smile:
I searched for "direct hie.yaml", and found something in a github repo almost similar to your suggestion
cradle:
direct:
arguments:
#- -hide-package=ghc-boot-th
#- -hide-package=template-haskell
#- -package=ghc-lib-parser
- -fwarn-incomplete-patterns
- -fwarn-unused-binds
- -fwarn-unused-imports
- -fwarn-orphans
- -isrc
- -icis194/week12
If I uncomment all the hide pkg's compiler options(-hide-package=...) then it is almost similar.
So -fwarn-unused-binds
is similar to -Wunused-imports
?
It is woriking, thanks!
Question
Is this the correct approach if I want to use hie
(or ghcide
or some other hie-bios
powered tool)?
When using ghcid and hlint I only had to configure .ghci
. Now I have to configure hie.yaml
as well, but do get 'goto definition', 'hover tool tips', 'show references'. Is this correct?
What is the default, if running without a hie.yaml
, and not using cabal or stack?
It is woriking, thanks!
Glad to hear it :)
Is this the correct approach if I want to use hie (or ghcide or some other hie-bios powered tool)?
The hie.yaml
is the correct approach, yeah.
I think you can actually pass in the .ghci script via -ghci-script=...
to repeating yourself.
What is the default, if running without a hie.yaml, and not using cabal or stack?
In hie, we assume a direct
cradle which is more or less identical to:
cradle:
direct:
arguments:
- -i.
Additionally, it passes the file to load to ghc. That can not be expressed via this hie.yaml
.
Source: https://github.com/haskell/haskell-ide-engine/blob/b32ff3a56c33514ffeed70387988ba2c179398ec/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L467
I am about to start the data61 (NICTA) course
The project is ghci based (no stack, no cabal, by default), with compiler setings defined in this .ghci. I wasn't able to define the hie.yaml
like this
cradle:
direct:
arguments:
- -ghci-script=.ghci
Maybe I am doing something wrong?
Instead I wrote
cradle:
direct:
arguments:
- -package time
- -package containers
- -fwarn-incomplete-patterns
- -fwarn-unused-binds
- -fwarn-unused-imports
- -fwarn-orphans
- -isrc
- -Wall
- -fno-warn-unused-binds
- -fno-warn-unused-do-bind
- -fno-warn-unused-imports
- -fno-warn-type-defaults
- -XNoImplicitPrelude
- -XScopedTypeVariables
- -XOverloadedStrings
- -XRebindableSyntax
# :l src/Course.hs src/Test/Loader.hs
# :m + Test.Loader
Do you know if I need the :load src/Course.hs src/Test/Loader.hs
line, and the :m + Test.Loader
line?
I couldn't find anything with any of the below
ghc --show-options | grep load
ghc --show-options | grep module
The project is ghci based (no stack, no cabal, by default), with compiler setings defined in this .ghci. I wasn't able to define the
hie.yaml
like thiscradle: direct: arguments: - -ghci-script=.ghci
What is the error message? E.g. Output of hie --debug
.
Do you know if I need the :load src/Course.hs src/Test/Loader.hs line, and the :m + Test.Loader line?
Lines such as :load
are definitely for the ghci script and do not work with hie.yaml
. As a rule of thumb, the command ghc <arguments> File.hs
should succeed.
This is the output
The Setup.hs
contains
import Distribution.Simple
main = defaultMain
It should definitely be ignored, but its in a ./support
directory, and .ghci
is only adding ./src
via -i
option?
To ignore a specific file, take a look at the none cradle.
E.g. assuming that your project root is /Users/maxfire/Projects/haskell/fp-course
, your hie.yaml
could look like this:
cradle:
multi:
- path: ./
config:
cradle:
direct:
arguments: [...]
- path: ./support/Setup.hs
config:
cradle:
none:
The so-called none
-cradle tells HIE to not even attempt to load the files associated with it.
I can't get it working with the -ghci-script=.ghci
compiler option
Also
$ ghc --show-options | grep ghci
-fghci-history
-fghci-leak-check
-fghci-sandbox
-fno-ghci-history
-fno-ghci-leak-check
-fno-ghci-sandbox
I see no such option, even though I can find it documented online?
I can't get it working with the -ghci-script=.ghci compiler option
How does it manifest? In the logs you posted, I think you were missing the stderr and the result claims that everything works as expected. It ought to work, stack provides such a script as well.
I see no such option, even though I can find it documented online?
Sorry, not my expertise.