Search code examples
haskellvisual-studio-codeidecode-completion

Using Haskell with VS Code


I can't get my VS Code to show Haskell type hovers. Also, there's no autocompletion. All I see is just a small, empty box just above the element I hover with my mouse (see the small box right about "getArgs" function).

my VS Code with "Hakelly" installed The extension I use is "Haskelly", though I've tried extensions for Atom editor as well and the result was similar.

Has anyone had a similar issue before ? I use:

  • VS Code: 1.27.1
  • ghc: 8.0.2
  • ghc-mod: 5.8.0.0
  • haskelly: 0.5.4
  • Intero: 0.1.32
  • OS: Linux Mint 19

Disclaimer: I'm quite new to Haskell, so it might be the case that I'm doing something terribly wrong here. Sorry, still learning ;).

EDIT:

As suggested in a comment I've switched to Haskero and managed to make a small progress. There is a type hover, but it contains some garbage.

enter image description here

One thing that might matter: I'm following this tutorial: https://www.youtube.com/watch?v=a7R-2vtPLDM, so I use cabal, not stack. Does it matter at all ?

EDIT 2:

I've tried using stack, but the result was even worse. The VS Code extension crashed with the following code:

The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: MyProject

Warning: Didn't find expected autogen file:
         <path_to_project>/MyProject/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/autogen/cabal_macros.h

Warning: Didn't find expected autogen file:
         <path_to_project>/MyProject/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/MyProject-exe/autogen/cabal_macros.h
<home>/.stack/programs/x86_64-linux/ghc-8.4.3/lib/ghc-8.4.3/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!)


  Code: -32603 

EDIT 3:

Still no good, but a bit closer. For built-in values and within the same package I can see pretty type hovers. However, I see errors for values from my modules when referenced in the other modules (even though they live next to each other and everything compiles just fine):

enter image description here

Any ideas how to help with this ?


Solution

  • I know it's been a long time, but I'd like to share my past experience. Maybe someone takes the advantage of it and won't need to go through the same list of problems.

    After spending hours reading articles and talking to various people I came up with the conclusion that the best way to get started with Haskell is... just to get started with Haskell. I installed ghc platform and cabal, use the cabal new-style commands and that seems to be enough. At least for now. Also, I decided to use VSCode with just a simple syntax-highlighting extension.

    I found out that any attempt to introduce more IDE-like features are unlikely to succeed, as Haskell is a very complex language. "hie" is a nice little idea, but it's missing stability and reliability to me - over the time I learnt how to install it, but for me it works only for simple cases and crashes with more real-life applications.

    Recently I've been trying to create a very simple DB + Web API App now and I've been having hard times in making the two monads talk to each other properly. I think there's no IDE that could do this for me anyway. When I find it difficult to write down the correct type of a function, then I use "cabal new-repl", load my module, check the desired type with ":t" and make an attempt to decypher the output. Not a perfect solution, but again - good enough.

    EDIT 12-Jan-2021

    I've spent even more time with Haskell and my understanding increased. I moved to NixOS which seems to handle everything nicely.

    Here's a link to a repo with my NixOS config files: https://github.com/bratfizyk/dotFiles/tree/master/nixos

    Using it "as it is" installs VS Code with HIE support enabled. Youi might only need to install the VS Code extension itself, as I found this feature problematic in nix, but it's a straightforward process.

    Obviously, change a user name :). Otherwise you'll keep on using mine.

    I'm going to update the repo over time.

    EDIT 09-Jan-2024

    I've restructured my dot files repo and migrated to home-manager and flakes: https://github.com/bratfizyk/dotFiles. Also, now I'm using NixOS full time on my personal machine, so the repo will be regularly maintained until I lose the remains of sanity I migrate to another distro (no plans for now)