This repository should help you get up and running with Haskell in Visual Studio Code.
You will need WSL2 and Docker Desktop for Windows for this, so install those if you haven't already.
Open the root of this repository in Visual Studio Code. VS Code should detect that the folder contains Docker configuration files, so follow the instructions to set up a container.
- Create a package folder under the
packages
directory, e.g.packages/chapters/02
. - Add an entry to the root
stack.yaml
for the new package, e.g.:
packages:
- packages/chapters/01
- packages/chapters/02
- In VS Code, open a new
bash
terminal. - In the terminal,
cd
to your new folder, e.g.cd packages/chapters/02
. - Run
stack new {package-name} --bare
, e.g.stack new chapter-two --bare
.
- In the
bash
terminal,cd
to the project root. - Run
stack build {package-name}
, e.g.stack build chapter-two
.
To run the new package, use stack run {package-name}-exe
, e.g. stack run chapter-two-exe
.
The terminal should output the result of running the main
function in app/Main.hs
, which by default prints someFunc
to the console.
Before starting work on a new package, it's worth ensuring the Haskell Language Server is up and running. Without it, you won't see any syntax highlighting, which is extremely useful for writing and inspecting Haskell code.
To do this:
Open one of the modules within the new package, e.g. src/Lib.hs
, and mouse over a function - if the language server is running, you should see a function definition appear above the cursor.
If you don't see a definition, try restarting the language server by doing the following:
- Use
Ctrl + Shift + P
to open the Command Palette in VS Code. - Click 'Haskell: Restart Haskell LSP Server'.
You can also set a keyboard shortcut for this command by going to File > Preferences > Keyboard Shortcuts, finding the command and adding a keybinding, such as Ctrl + Shift + A
.
If restarting the language server fails to resolve the issue:
- Ensure you have added an entry to the root
stack.yaml
for the new package path (see above). - Try closing VS Code and reopening the project folder, making sure to choose the folder suffixed with [Dev Container].