How to make HLS show warnings?


I’m wondering how to make HLS show the warnings that you would get from compiling a file with {-# OPTIONS_GHC -W #-} at the top, without adding that header to every file in my project.

I’m relatively new to Haskell and am not using Stack/Cabal because I’m not using any external dependencies. I just have a few modules in files.



You can create a hie.yaml file in your directory, listing the exact GHC arguments you want your modules to be compiled with, see GitHub - haskell/hie-bios: Set up a GHC API session for various Haskell Projects
Note, the documentation currently misses the fact, you have to explicitly list all modules you want to compile, even though GHC would succeed without you listing each module individually.

1 Like

Ahh, this works. Thank you!

1 Like

I usually add a cabal.project or cabal.project.local file with

package YourPackageName
   ghc-options: -Wall

this works too (rebuild/restart HLS after you added this) - tested with VS Code.

1 Like

Right, that’s the best approach imho; however, the post mentions they don’t use either stack or cabal, so this isn’t an option in this particular case, afaict.

sorry - missed that bit of information

Is there also a way to make ghcide also show these warnings? (With the hie.yaml)

Currently what I have is

    arguments: ["-W", "Main" {- Modules ommitted -}]

Well, instead of -W use -Wall, or what is the question? Which warnings you are referring to?

After using the hie.yaml, my IDE (now) shows warnings for things like redundant imports that wouldn’t trigger warnings. However ghcide doesn’t show anything.

Are you really using ghcide? Or do you mean haskell-language-server? Ah, you mean ghcid. Be careful with names because ghcide is the engine of haskell-language-server, something entirely different to ghcid :smiley:

I have trouble parsing that sentence, the IDE (which is HLS, right?) shows the warning, but you don’t expect these warnings in ghcid? That makes sense, the hie.yaml is only parsed by haskell-language-server. I think you’d have to specify the same warnings for your ghcid invocation, e.g. ghcid -c 'ghci -W Main'

There is currently no way to easily feed the flags from hie.yaml to ghcid directly, since that’s kind of a rare use-case.

1 Like

Ohh ok! Thank you for explaining that. I passed the flag to ghcid :slight_smile: and it works.

1 Like