Skip to content

Setting Up Debugger for Haskell in Vscode

It's not easy as the other languages which owns an IDE so click the button is the only thing need to do. Using Vscode, I installed several plugins and dependencies, then clicked debug button, oops, nothing happened! The debugger bar flashes and disappear, then nothing happened except the confusing people at the front of screen.

To be frank, I gave up several times when I was attacked by such a messy event. However, another afflict when I want to diagnose my program. After plowing in the troublesome problems, I finally set up it successfully. However, it becomes more messy when I changed my Desktop from Intel to M1, which means I need to set it up AGAIN.

This blog records some hints for setting up Haskell Debugger. I hope I will never set it up with so many trouble again.

Overview: How to Find Hints to Diagnose Problems

Clicked the debug button but got no response, how to deal with the problem? Definitely, there is something wrong, however, what's the detail? We need to know VScode utilizes LSP to interact between UI and the backend. When there is no reponse, it reveals the messages are discarded. Hence, first we need to check the status of haskell lsp. Press cmd+shift+p and then search lsp to restart/start the lsp server.

After that, running again reported cabal: unrecognized 'repl' option--repl-no-load'as theghciCmd` is:

cabal repl -w ghci-dap --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl

This error blocks me a long of time, because an unknown flag is tricky. To solve it, typically see what it does. The cabal is a tool, then the ghci-dap is another tool, hence the flag is used by ghci-dap tool. As the flag cannot be recongized, it might cases:

  • the command hasn't passed the flag correctly.
  • the ghci-dap has problems

I tried to add double dashes in ghciCmd to change the passing way, but it didn't work.

cabal repl -w ghci-dap -- --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl
As a result, I need to check whether the ghci-dap version is correct. I run ghci-dap --version and it outputed normally, which gives no hint to me.

Hence, I started to look up the correctness of Haskell toolchains. Then, I found when installing there are some warnings which should be error as cabal cannot install them correctly. Hence, after I reinstall the Haskell toolchain with recommended way, it fixes the debug.

cabal install haskell-dap ghci-dap haskell-debug-adapter

Tip1: Never Install GHCI by Homebrew

Don't use homebrew to install ghci, use ghcup instead.

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Tip2: Use GHCUP TUI to Manage All Dependencies

After installing ghcup, using ghcup tui to manage all dependecies, such as ghci, cabal and so on...

Tip3: Install Dependencies with Compatiable Versions

Some compositions don't support the debugger, hence we need to pick up a compitable set of toolchains.

  • HLS: 2.4.0.0
  • cabal: 3.10.2.0
  • GHC 9.4.7