• Stars
    star
    561
  • Rank 79,400 (Top 2 %)
  • Language
    TypeScript
  • License
    Other
  • Created about 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

Table of Contents

Setup

This Extension comes with "batteries"-included and can manage your Haskell Language Server installations for you, powered by GHCup. Installation of GHCup can not happen automatically, so if you want your HLS installations to be managed by the Extension, you will have to follow the installation instructions for GHCup.

Note: Make sure you have a working ghcup installation, before launching the Extension.

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.
  • 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 and must be configured to use GHC binaries installed by GHCup.
  • If you are installing from an offline VSIX file, you need to install language-haskell too after installation (either from the marketplace or offline).
  • Alternatively, you can let the extension manage your entire toolchain automatically (you'll be asked on first startup) via ghcup, which should be pre-installed

Configuration options

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

For information on how to set configuration in VSCode, see here.

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 machine-overridable 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 appropriate path. 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 and the rest of the toolchain if you selected to use GHCup during first start. Check the haskell.manageHLS setting.

It will then 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 latest version which supported ghc-8.10.4. Even if the latest global haskell language-server version is 1.5.1.

If you have disk space issues, check ghcup gc --help.

You can also instruct the extension to use a different installation directory for the toolchain, e.g. to not interfere with system GHCup installation. Depending on your platform, add the full resolved path like so:

  "haskell.serverEnvironment": {
    "GHCUP_INSTALL_BASE_PREFIX": "/home/foo/.config/Code/User/globalStorage/haskell.haskell/"
  }

The internal storage paths for the extension depend on the platform:

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

If you want to manage HLS yourself, set haskell.manageHLS to PATH and make sure HLS is in your PATH or set haskell.serverExecutablePath (overrides all other settings) to a valid executable.

If you need to set mirrors for ghcup download info, check the settings haskell.metadataURL and haskell.releasesURL.

Setting a specific toolchain

When manageHLS is set to GHCup, you can define a specific toolchain (hls, ghc, cabal and stack), either globally or per project. E.g.:

{
  "haskell.toolchain": {
    "hls": "1.6.1.1",
    "cabal": "recommended",
    "stack": null
  }
}

This means:

  1. install the ghc version corresponding to the project (default, because it's omitted)
  2. install hls 1.6.1.1
  3. install the recommended cabal version from ghcup
  4. don't install any stack version

Another config could be:

{
  "haskell.toolchain": {
    "ghc": "9.2.2",
    "hls": "latest",
    "cabal": "recommended"
  }
}

Meaning:

  1. install ghc 9.2.2 regardless of what the project requires
  2. always install latest hls, even if it doesn't support the given GHC version
  3. install recommended cabal
  4. install latest stack (default, because it's omitted)

The defaults (when omitted) are as follows:

  1. install the project required ghc (corresponding to with-compiler setting in cabal.project for example)
  2. install the latest hls version that supports the project required ghc version
  3. install latest cabal
  4. install latest stack

When a the value is null, the extension will refrain from installing it.

At last, if you don't want ghcup to manage any of the external tools except hls, you can use:

{
  "haskell.toolchain": {
    "ghc": null,
    "cabal": null,
    "stack": null
  }
}

Supported GHC versions

You can check each GHC version's support status and the policy followed for deprecations here.

Building from source may support more versions!

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

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 sensitive 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.

FAQ

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.

Failed to get project GHC version on darwin M1 with stack

If you have installed stack via the official cannels, the binary will not be M1 native, but x86 and trigger the rosetta compatibility layer. GHCup provides real stack/HLS M1 binaries, so make sure you install stack via GHCup. Also see haskell/haskell-language-server#2864

GHC ABIs don't match

If you are using certain versions of GHC (such as 9.0.2 or 9.2.4) while running Stack, you may encounter this issue due to an outdated GHC bindist installed by Stack. The vscode-haskell extension does not support the use of GHC binaries managed by Stack. Therefore, it is recommended to configure Stack to allow GHCup to install these binaries instead. Please refer to the instructions provided by ghcup for this purpose.

If you really want to use GHC 9.0.2 managed by Stack, force it to install the fixed bindist (that includes profiling libs) by adding this to your stack.yaml (depending on your platform):

setup-info:
  ghc:
    linux64-tinfo6:
      9.0.2:
        url: 'https://downloads.haskell.org/ghc/9.0.2/ghc-9.0.2a-x86_64-fedora27-linux.tar.xz'

Now make sure to remove cached/installed libraries to avoid getting segfaults at runtime.

As a final workaround, you can try to compile HLS from source (the extension should pick it up) via ghcup, see https://haskell-language-server.readthedocs.io/en/stable/installation.html#ghcup. In any case, the recommended approach is to let GHCup install the GHC binaries.

Using an old configuration

If something just doesn't work, but you recall an old configuration that did, you may try forcing a particular setting, e.g. by disabling all automatic installations except HLS:

    "haskell.toolchain": {
        "hls": "1.6.1.0",
        "ghc": null,
        "cabal": null,
        "stack": null
    }

Stack/Cabal/GHC can not be found

Also make sure GHCup is installed and in $PATH. If you're not starting VSCode from the terminal, you might need to add ${HOME}/.ghcup/bin to PATH like so:

  "haskell.serverEnvironment": {
    "PATH": "${HOME}/.ghcup/bin:$PATH"
  }

Contributing

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

Release Notes

See the Changelog for more details.

More Repositories

1

haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Haskell
2,709
star
2

haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
Haskell
2,383
star
3

cabal

Official upstream development repository for Cabal and cabal-install
Haskell
1,623
star
4

haskell-mode

Emacs mode for Haskell
Emacs Lisp
1,329
star
5

aeson

A fast Haskell JSON library
Haskell
1,254
star
6

stylish-haskell

Haskell code prettifier
Haskell
986
star
7

parsec

A monadic parser combinator library
Haskell
844
star
8

ghcide

A library for building Haskell IDE tooling
Haskell
584
star
9

attoparsec

A fast Haskell library for parsing ByteStrings
Haskell
514
star
10

criterion

A powerful but simple library for measuring the performance of Haskell code.
Haskell
501
star
11

hackage-server

Hackage-Server: A Haskell Package Repository
Haskell
415
star
12

text

Haskell library for space- and time-efficient operations over Unicode text.
Haskell
406
star
13

haskell-platform

Distribution of Haskell with batteries included
Haskell
381
star
14

wreq

Haskell
379
star
15

lsp

Haskell library for the Microsoft Language Server Protocol
Haskell
366
star
16

mtl

The Monad Transformer Library
Haskell
366
star
17

vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Haskell
363
star
18

haddock

Haskell Documentation Tool
HTML
361
star
19

network

Low-level networking interface
Haskell
326
star
20

containers

Assorted concrete container types
Haskell
315
star
21

statistics

A fast, high quality library for computing with statistics in Haskell.
Haskell
300
star
22

alex

A lexical analyser generator for Haskell
Haskell
298
star
23

bytestring

An efficient compact, immutable byte string type (both strict and lazy) suitable for binary or 8-bit character data.
Haskell
291
star
24

happy

The Happy parser generator for Haskell
Haskell
287
star
25

ghcup-hs

Haskell
284
star
26

ghcup

DEPRECATED IN FAVOR OF haskell/ghcup-hs
Shell
263
star
27

haskeline

A Haskell library for line input in command-line programs.
Haskell
222
star
28

c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
Haskell
198
star
29

fgl

A Functional Graph Library for Haskell
Haskell
184
star
30

hie-bios

Set up a GHC API session for various Haskell Projects
Haskell
180
star
31

HTTP

Haskell HTTP package
Haskell
177
star
32

ThreadScope

A graphical tool for profiling parallel Haskell programs
Haskell
153
star
33

actions

Github actions for Haskell CI
TypeScript
147
star
34

critbit

A Haskell implementation of crit-bit trees.
Haskell
138
star
35

play-haskell

Haskell Playground
Haskell
129
star
36

time

A time library
Haskell
119
star
37

primitive

This package provides various primitive memory-related operations.
Haskell
114
star
38

unix

POSIX functionality
Haskell
107
star
39

binary

Efficient, pure binary serialisation using ByteStrings in Haskell.
Haskell
106
star
40

rfcs

This repo is archived, consider using https://github.com/ghc-proposals/ghc-proposals instead
TeX
98
star
41

win32

Haskell support for the Win32 API
Haskell
98
star
42

stm

Software Transactional Memory
Haskell
97
star
43

core-libraries-committee

95
star
44

haskell-report

Haskell Language Report
TeX
91
star
45

parallel

a library for parallel programming
Haskell
91
star
46

process

Library for dealing with system processes
Haskell
87
star
47

hoopl

Higher-order optimization library
Haskell
73
star
48

error-messages

72
star
49

pretty

Haskell Pretty-printer library
Haskell
69
star
50

filepath

Haskell FilePath core library
Haskell
66
star
51

docker-haskell

Dockerfile
63
star
52

directory

Platform-independent library for basic file system operations
Haskell
58
star
53

hackage-security

Hackage security framework based on TUF (The Update Framework)
Haskell
56
star
54

mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
Haskell
55
star
55

random

Random number library
Haskell
53
star
56

ecosystem-proposals

Proposals for the Haskell Ecosystem
51
star
57

text-icu

This package provides the Haskell Data.Text.ICU library, for performing complex manipulation of Unicode text.
Haskell
47
star
58

base64-bytestring

Fast base64 encoding and decoding for Haskell.
Haskell
45
star
59

security-advisories

Haskell
44
star
60

deepseq

Deep evaluation of data structures
Haskell
41
star
61

tar

Reading, writing and manipulating ".tar" archive files.
Haskell
40
star
62

math-functions

Special mathematical functions
Haskell
40
star
63

hsc2hs

Pre-processor for .hsc files
Haskell
38
star
64

pvp

Haskell Package Version Policy (PVP)
CSS
38
star
65

zlib

Compression and decompression in the gzip and zlib formats
C
35
star
66

ghc-events

Library and tool for parsing .eventlog files from GHC
Haskell
33
star
67

text-format

A Haskell text formatting library optimized for ease of use and high performance.
Haskell
32
star
68

ghcup-metadata

GHCup metadata repository
Haskell
32
star
69

cabal-userguide

A handy user guide for the Cabal build tool
Nix
28
star
70

base16-bytestring

Fast base16 (hexadecimal) encoding and decoding for Haskell bytestrings.
Haskell
27
star
71

network-uri

URI manipulation facilities
Haskell
25
star
72

entropy

Easy entropy source for Haskell users.
Haskell
23
star
73

winghci

Simple Windows GUI for GHCi.
C
17
star
74

double-conversion

A fast Haskell library for converting between double precision floating point numbers and text strings. It is implemented as a binding to the V8-derived C++ double-conversion library.
C++
15
star
75

file-io

File IO (read/write/open) for OsPath API
Haskell
11
star
76

terminfo

Haskell bindings to the terminfo API.
Haskell
10
star
77

array

Haskell
10
star
78

xhtml

XHTML combinator library
Haskell
9
star
79

old-time

This package provides the old time library.
Haskell
7
star
80

meta

A place for discussing & documenting the github.com/haskell organization
7
star
81

blog.haskell.org

Repository of the Haskell Blog
JavaScript
7
star
82

ghc-builder

ghc builder bot
Haskell
6
star
83

cabal-website

The http://www.haskell.org/cabal/ website
HTML
4
star
84

network-bsd

POSIX network database (<netdb.h>) API
Haskell
4
star
85

haskell-wiki-configuration

Issue tracking for Haskell Wiki
PHP
4
star
86

clc-stackage

Meta-package to facilitate impact assessment for CLC proposals
Nix
3
star
87

hiw

Haskell Implementors Workshop
TeX
3
star
88

text-test-data

Test data for the Haskell text project
Text
3
star
89

old-locale

This package provides the ability to adapt to locale conventions such as date and time formats.
Haskell
3
star
90

tokenize

Simple tokenizer for English text
Haskell
3
star
91

bzlib

Compression and decompression in the bzip2 format
Haskell
2
star
92

os-string

Haskell
2
star
93

hpc

1
star