• This repository has been archived on 02/Jan/2021
  • Stars
    star
    584
  • Rank 76,554 (Top 2 %)
  • Language
    Haskell
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated almost 4 years ago

Reviews

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

Repository Details

A library for building Haskell IDE tooling

Moved

This project is now a historical artifact. It has been merged and all issues transferred into:

https://github.com/haskell/haskell-language-server

ghcide - A library for building Haskell IDE tooling

Our vision is that you should build an IDE by combining:

vscode

  • hie-bios for determining where your files are, what are their dependencies, what extensions are enabled and so on;
  • ghcide (i.e. this library) for defining how to type check, when to type check, and producing diagnostic messages;
  • A bunch of plugins that haven't yet been written, e.g. hie-hlint and hie-ormolu, to choose which features you want;
  • haskell-lsp for sending those messages to a Language Server Protocol (LSP) server;
  • An LSP client for your editor.

There are more details about our approach in this blog post.

Features

ghcide already exports the following features via the lsp protocol:

Feature LSP name
Display error messages (parse errors, typecheck errors, etc.) and enabled warnings. diagnostics
Go to definition in local package definition
Display type and source module of values hover
Remove redundant imports, replace suggested typos for values and module imports, fill type holes, insert missing type signatures, add suggested ghc extensions codeAction (quickfix)

Limitations to Multi-Component support

ghcide supports loading multiple components into the same session so that features such as go-to definition work across components. However, there are some limitations to this.

  1. You will get much better results currently manually specifying the hie.yaml file. Until tools like cabal and stack provide the right interface to support multi-component projects, it is always advised to specify explicitly how your project partitions.
  2. Cross-component features only work if you have loaded at least one file from each component.
  3. There is a known issue where if you have three components, such that A depends on B which depends on C then if you load A and C into the session but not B then under certain situations you can get strange errors about a type coming from two different places. See this repo for a simple reproduction of the bug.

Using it

ghcide is not an end-user tool, don't use ghcide directly (more about the rationale here).

haskell-language-server is an LSP server built on top of ghcide with additional features and a user friendly deployment model. To get it, simply install the Haskell extension in VS Code, or download prebuilt binaries from the haskell-language-server project page.

The instructions below are meant for developers interested in setting up ghcide as an LSP server for testing purposes.

Install ghcide

With Nix

Note that you need to compile ghcide with the same ghc as the project you are working on.

  1. If the ghc you are using matches the version (or better is) from nixpkgs itโ€˜s easiest to use the ghcide from nixpkgs. You can do so via

    nix-env -iA haskellPackages.ghcide
    

    or e.g. including pkgs.haskellPackages.ghcide in your projects shell.nix. Depending on your nixpkgs channel that might not be the newest ghcide, though.

  2. If your ghc does not match nixpkgs you should try the ghcide-nix repository which provides a ghcide via the haskell.nix infrastructure.

With Cabal or Stack

First install the ghcide binary using stack or cabal, e.g.

  1. git clone https://github.com/haskell/ghcide.git
  2. cd ghcide
  3. cabal install or stack install (and make sure ~/.local/bin is on your $PATH)

It's important that ghcide is compiled with the same compiler you use to build your projects.

Test ghcide

Next, check that ghcide is capable of loading your code. Change to the project directory and run ghcide, which will try and load everything using the same code as the IDE, but in a way that's much easier to understand. For example, taking the example of shake, running ghcide gives some error messages and warnings before reporting at the end:

Files that failed:
 * .\model\Main.hs
 * .\model\Model.hs
 * .\model\Test.hs
 * .\model\Util.hs
 * .\output\docs\Main.hs
 * .\output\docs\Part_Architecture_md.hs
Completed (152 worked, 6 failed)

Of the 158 files in Shake, as of this moment, 152 can be loaded by the IDE, but 6 can't (error messages for the reasons they can't be loaded are given earlier). The failing files are all prototype work or test output, meaning I can confidently use Shake.

The ghcide executable mostly relies on hie-bios to do the difficult work of setting up your GHC environment. If it doesn't work, see the hie-bios manual to get it working. My default fallback is to figure it out by hand and create a direct style hie.yaml listing the command line arguments to load the project.

If you can't get ghcide working outside the editor, see this setup troubleshooting guide. Once you have got ghcide working outside the editor, the next step is to pick which editor to integrate with.

Optimal project setup

ghcide has been designed to handle projects with hundreds or thousands of modules. If ghci can handle it, then ghcide should be able to handle it. The only caveat is that this currently requires GHC >= 8.6, and that the first time a module is loaded in the editor will trigger generation of support files in the background if those do not already exist.

Configuration

ghcide accepts the following lsp configuration options:

{
  // When to check the dependents of a module
  // AlwaysCheck means retypechecking them on every change
  // CheckOnSave means dependent/parent modules will only be checked when you save
  // "CheckOnSaveAndClose" by default
  checkParents : "NeverCheck" | "CheckOnClose" | "CheckOnSaveAndClose" | "AlwaysCheck" | ,
  // Whether to check the entire project on initial load
  // true by default
  checkProject : boolean

}

Using with VS Code

The Haskell extension has a setting for ghcide.

Using with Atom

You can follow the instructions to install with apm.

Using with Sublime Text

  • Install LSP
  • Press Ctrl+Shift+P or Cmd+Shift+P in Sublime Text and search for Preferences: LSP Settings, then paste these settings
{
  "clients":
  {
    "ghcide":
    {
      "enabled"   : true,
      "languageId": "haskell",
      "command"   : ["ghcide", "--lsp"],
      "scopes"    : ["source.haskell"],
      "syntaxes"  : ["Packages/Haskell/Haskell.sublime-syntax"]
    }
  }
}

Using with Emacs

If you don't already have MELPA package installation configured, visit MELPA getting started page to get set up. Then, install use-package.

Now you have a choice of two different Emacs packages which can be used to communicate with the ghcide LSP server:

  • lsp-ui
  • eglot (requires Emacs 26.1+)

In each case, you can enable support by adding the shown lines to your .emacs:

lsp-ui

;; LSP
(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode t))
(use-package yasnippet
  :ensure t)
(use-package lsp-mode
  :ensure t
  :hook (haskell-mode . lsp)
  :commands lsp)
(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode)
(use-package lsp-haskell
 :ensure t
 :config
 (setq lsp-haskell-process-path-hie "ghcide")
 (setq lsp-haskell-process-args-hie '())
 ;; Comment/uncomment this line to see interactions between lsp client/server.
 ;;(setq lsp-log-io t)
)

eglot

(use-package eglot
  :ensure t
  :config
  (add-to-list 'eglot-server-programs '(haskell-mode . ("ghcide" "--lsp"))))

Using with Vim/Neovim

LanguageClient-neovim

Install LanguageClient-neovim

Add this to your vim config:

let g:LanguageClient_rootMarkers = ['*.cabal', 'stack.yaml']
let g:LanguageClient_serverCommands = {
    \ 'rust': ['rls'],
    \ 'haskell': ['ghcide', '--lsp'],
    \ }

Refer to :he LanguageClient for more details on usage and configuration.

vim-lsp

Install vim-lsp.

Add this to your vim config:

au User lsp_setup call lsp#register_server({
    \ 'name': 'ghcide',
    \ 'cmd': {server_info->['/your/path/to/ghcide', '--lsp']},
    \ 'whitelist': ['haskell'],
    \ })

To verify it works move your cursor over a symbol and run :LspHover.

coc.nvim

Install coc.nvim

Add this to your coc-settings.json (which you can edit with :CocConfig):

{
  "languageserver": {
    "haskell": {
      "command": "ghcide",
      "args": [
        "--lsp"
      ],
      "rootPatterns": [
        ".stack.yaml",
        ".hie-bios",
        "BUILD.bazel",
        "cabal.config",
        "package.yaml"
      ],
      "filetypes": [
        "hs",
        "lhs",
        "haskell"
      ]
    }
  }
}

Here's a nice article on setting up neovim and coc: Vim and Haskell in 2019 (this is actually for haskell-ide, not ghcide)

Here is a Docker container that pins down the build and configuration for Neovim and ghcide on a minimal Debian 10 base system: docker-ghcide-neovim.

SpaceVim

In the autocomplete layer, add the autocomplete_method option to force the use of coc:

[[layers]]
  name = 'autocomplete'
  auto-completion-return-key-behavior = "complete"
  auto-completion-tab-key-behavior = "smart"
  [options]
    autocomplete_method = "coc"

Add this to your coc-settings.json (which you can edit with :CocConfig):

{
  "languageserver": {
    "haskell": {
      "command": "ghcide",
      "args": [
        "--lsp"
      ],
      "rootPatterns": [
        ".stack.yaml",
        ".hie-bios",
        "BUILD.bazel",
        "cabal.config",
        "package.yaml"
      ],
      "filetypes": [
        "hs",
        "lhs",
        "haskell"
      ]
    }
  }
}

This example above describes a setup in which ghcide is installed using stack install ghcide within a project.

Using with Kakoune

Install kak-lsp.

Change kak-lsp.toml to include this:

[language.haskell]
filetypes = ["haskell"]
roots = ["Setup.hs", "stack.yaml", "*.cabal", "cabal.project", "hie.yaml"]
command = "ghcide"
args = ["--lsp"]

Hacking on ghcide

To build and work on ghcide itself, you should use cabal, e.g., running cabal test will execute the test suite. You can use stack test too, but note that some tests will fail, and none of the maintainers are currently using stack.

If you are using Nix, there is a Cachix nix-shell cache for all the supported platforms: cachix use haskell-ghcide.

If you are using Windows, you should disable the auto.crlf setting and configure your editor to use LF line endings, directly or making it use the existing .editor-config.

If you are chasing down test failures, you can use the tasty-rerun feature by running tests as

cabal test --test-options"--rerun"

This writes a log file called .tasty-rerun-log of the failures, and only runs those. See the tasty-rerun documentation for other options.

If you are touching performance sensitive code, take the time to run a differential benchmark between HEAD and master using the benchHist script. This assumes that "master" points to the upstream master.

Run the benchmarks with cabal bench.

It should take around 15 minutes and the results will be stored in the bench-results folder. To interpret the results, see the comments in the bench/hist/Main.hs module.

More details in bench/README

History and relationship to other Haskell IDE's

The teams behind this project and the haskell-ide-engine have agreed to join forces under the haskell-language-server project, see the original announcement. The technical work is ongoing, with the likely model being that this project serves as the core, while plugins and integrations are kept in the haskell-language-server project.

The code behind ghcide was originally developed by Digital Asset as part of the DAML programming language. DAML is a smart contract language targeting distributed-ledger runtimes, based on GHC with custom language extensions. The DAML programming language has an IDE, and work was done to separate off a reusable Haskell-only IDE (what is now ghcide) which the DAML IDE then builds upon. Since that time, there have been various non-Digital Asset contributors, in addition to continued investment by Digital Asset. The project has been handed over to Haskell.org as of September 2020.

The Haskell community has various IDE choices, but the one that had been gathering momentum is haskell-ide-engine. Our project owes a debt of gratitude to the haskell-ide-engine. We reuse libraries from their ecosystem, including hie-bios (a likely future environment setup layer in haskell-ide-engine), haskell-lsp and lsp-test (the haskell-ide-engine LSP protocol pieces). We make heavy use of their contributions to GHC itself, in particular the work to make GHC take string buffers rather than files.

The best summary of the architecture of ghcide is available this talk (slides), given at MuniHac 2019. However, since that talk the project has renamed from hie-core to ghcide, and the repo has moved to this location.

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

vscode-haskell

VS Code extension for Haskell, powered by haskell-language-server
TypeScript
561
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