Skip to content

hasufell/vscode-haskell

 
 

Repository files navigation

Haskell for Visual Studio Code

vsmarketplacebadge

This extension adds language support for Haskell, powered by the Haskell Language Server. As almost all features are provided by the server you might find interesting read its documentation.

Features

You can watch demos for some of these features here.

Requirements

  • For standalone .hs/.lhs files, ghc must be installed and on the PATH. The easiest way to install it is with ghcup or Chocolatey on Windows.
  • For Cabal based projects, both ghc and cabal-install must be installed and on the PATH. It can also be installed with ghcup or Chocolatey on Windows.
  • For Stack based projects, stack must be installed and on the PATH.
  • If you are installing from an offline VSIX file, you need to install language-haskell too after installation (either from the marketplace or offline).

Configuration options

For a general picture about the server configuration, including the project setup, you can consult the server documentation about the topic.

Path to server executable

If your server is manually installed and not on your path, you can also manually set the path to the executable.

"haskell.serverExecutablePath": "~/.local/bin/haskell-language-server"

There are a few placeholders which will be expanded:

  • ~, ${HOME} and ${home} will be expanded into your users' home folder.
  • ${workspaceFolder} and ${workspaceRoot} will expand into your current project root.

Security warning

The option has resource scope so it can be changed per workspace. This supposes it could be used to execute arbitrary programs adding a .vscode/settings.json in the workspace folder including this option with the appropiate path. For this reason its scope will be changed to machine so users only will be able to change it globally. See #387 for more details.

Set additional environment variables for the server

You can add additional environment variables for the lsp server using the configuration option haskell.serverEnvironment. For example, to change the cache directory used by the server you could set:

{ "haskell.serverEnvironment": { "XDG_CACHE_HOME": "/path/to/my/cache" } }

as the server uses the XDG specification for cache directories.

The environment only will be visible for the lsp server, not for other extension tasks like find the server executable.

Downloaded binaries

This extension will download haskell-language-server binaries to a specific location depending on your system.

It will download the newest version of haskell-language-server which has support for the required ghc. That means it could use an older version than the latest one, without the last features and bug fixes. For example, if a project needs ghc-8.10.4 the extension will download and use haskell-language-server-1.4.0, the lastest version which supported ghc-8.10.4. Even if the lastest global haskell language-server version is 1.5.1.

If you find yourself running out of disk space, you can try deleting old versions of language servers in this directory. The extension will redownload them, no strings attached.

Platform Path
macOS ~/Library/Application\ Support/Code/User/globalStorage/haskell.haskell/
Windows %APPDATA%\Code\User\globalStorage\haskell.haskell
Linux $HOME/.config/Code/User/globalStorage/haskell.haskell

Note that if haskell-language-server-wrapper/haskell-language-server is already on the PATH or you have set the haskell.serverExecutablePath option, then the extension will launch it directly instead of downloading binaries, even if the version of the former is older then the latter.

Supported GHC versions

These are the versions of GHC that there are binaries of haskell-language-server-1.5.1 for. Building from source may support more versions!

GHC Linux macOS Windows
9.0.1 (limited)
8.10.7
8.10.6
8.10.5
8.8.4
8.8.3
8.6.5

The exact list of binaries can be checked in the last release of haskell-language-server: https://github.com/haskell/haskell-language-server/releases/latest

You can check the current GHC versions support status and the policy followed for deprecations here.

Using multi-root workspaces

First, check out what multi-root workspaces are. The idea of using multi-root workspaces, is to be able to work on several different Haskell projects, where the GHC version or stackage LTS could differ, and have it work smoothly.

The language server is now started for each workspace folder you have in your multi-root workspace, and several configurations are on a resource (i.e. folder) scope, instead of window (i.e. global) scope.

Investigating and reporting problems

  1. Go to extensions and right click Haskell and choose Extensions Settings
  2. Scroll down to Haskell › Trace: Server and set it to messages.
  3. Set Haskell › Trace: Client to debug. It will print all the environment variables so take care it does not contain any sensible information before sharing it.
  4. Restart vscode and reproduce your problem
  5. Go to the main menu and choose View -> Output (Ctrl + Shift + U)
  6. On the new Output panel that opens on the right side in the drop down menu choose Haskell (<your project>)

Please include the output when filing any issues on the haskell-language-server issue tracker.

Troubleshooting

Check issues and tips in the haskell-language-server project

Restarting the language server

  • Sometimes the language server might get stuck in a rut and stop responding to your latest changes. Should this occur you can try restarting the language server with Ctrl shift P/ shift P > Restart Haskell LSP Server.

Cradle requires ghc/cabal/stack but it isn't installed

  • In Linux/MacOS systems, opening vscode in the windows system could not use the $PATH set in the shell so it will not see required tools as ghc, cabal or stack. This usually happens if you have installed them via ghcup.
  • It could be fixed changing the $PATH variable in the init config file used by the windows system (f.e. ~/.profile, but i can vary depending on your system setup).
  • See this stackoverflow question for more tricks.

Contributing

If you want to help, get started by reading Contributing for more details.

Release Notes

See the Changelog for more details.

About

VS Code extension for Haskell, powered by haskell-language-server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 94.0%
  • JavaScript 2.8%
  • Haskell 2.6%
  • Nix 0.6%