• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..15-Sep-2021-

bench/H15-Sep-2021-1,126873

bench-results/H15-Sep-2021-54

cbits/H15-Sep-2021-2217

docs/H15-Sep-2021-217142

exe/H15-Sep-2021-129100

img/H03-May-2022-

session-loader/Development/IDE/H15-Sep-2021-916547

src/H15-Sep-2021-16,44512,350

test/H15-Sep-2021-7,6116,495

.editorconfigH A D15-Sep-2021256 129

.ghciH A D15-Sep-2021652 3025

.gitignoreH A D15-Sep-2021209 1918

.hlint.yamlH A D15-Sep-20215.4 KiB151134

CHANGELOG.mdH A D15-Sep-202118.5 KiB342313

LICENSEH A D15-Sep-202111.1 KiB202169

README.mdH A D15-Sep-202115.4 KiB359265

azure-pipelines.ymlH A D15-Sep-2021337 1916

ghcide.cabalH A D15-Sep-202112.3 KiB454438

README.md

1# `ghcide` - A library for building Haskell IDE tooling
2
3Our vision is that you should build an IDE by combining:
4
5![vscode](https://raw.githubusercontent.com/haskell/ghcide/master/img/vscode2.png)
6
7* [`hie-bios`](https://github.com/mpickering/hie-bios) for determining where your files are, what are their dependencies, what extensions are enabled and so on;
8* `ghcide` (i.e. this library) for defining how to type check, when to type check, and producing diagnostic messages;
9* A bunch of plugins that haven't yet been written, e.g. [`hie-hlint`](https://github.com/ndmitchell/hlint) and [`hie-ormolu`](https://github.com/tweag/ormolu), to choose which features you want;
10* [`haskell-lsp`](https://github.com/alanz/haskell-lsp) for sending those messages to a [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) server;
11* An LSP client for your editor.
12
13There are more details about our approach [in this blog post](https://4ta.uk/p/shaking-up-the-ide).
14
15## Features
16
17`ghcide` already exports the following features via the lsp protocol:
18
19| Feature | LSP name |
20| - | - |
21| Display error messages (parse errors, typecheck errors, etc.) and enabled warnings. | diagnostics |
22| Go to definition in local package | definition  |
23| Display type and source module of values | hover |
24| Remove redundant imports, replace suggested typos for values and module imports, fill type holes, insert missing type signatures, add suggested ghc extensions  | codeAction (quickfix) |
25
26
27## Limitations to Multi-Component support
28
29`ghcide` supports loading multiple components into the same session so that
30features such as go-to definition work across components. However, there are
31some limitations to this.
32
331. You will get much better results currently manually specifying the hie.yaml file.
34Until tools like cabal and stack provide the right interface to support multi-component
35projects, it is always advised to specify explicitly how your project partitions.
362. Cross-component features only work if you have loaded at least one file
37from each component.
383. There is a known issue where if you have three components, such that A depends on B which depends on C
39then if you load A and C into the session but not B then under certain situations you
40can get strange errors about a type coming from two different places. See [this repo](https://github.com/fendor/ghcide-bad-interface-files) for
41a simple reproduction of the bug.
42
43## Using it
44
45`ghcide` is not an end-user tool, [don't use `ghcide`](https://neilmitchell.blogspot.com/2020/09/dont-use-ghcide-anymore-directly.html) directly (more about the rationale [here](https://github.com/haskell/ghcide/pull/939)).
46
47 [`haskell-language-server`](http://github.com/haskell/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](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) in VS Code, or download prebuilt binaries from the [haskell-language-server](https://github.com/haskell/haskell-language-server) project page.
48
49
50The instructions below are meant for developers interested in setting up ghcide as an LSP server for testing purposes.
51
52### Install `ghcide`
53
54#### With Nix
55
56Note that you need to compile `ghcide` with the same `ghc` as the project you are working on.
57
581. 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
59   ```
60   nix-env -iA haskellPackages.ghcide
61   ```
62   or e.g. including `pkgs.haskellPackages.ghcide` in your projects `shell.nix`.
63   Depending on your `nixpkgs` channel that might not be the newest `ghcide`, though.
64
652. If your `ghc` does not match nixpkgs you should try the [ghcide-nix repository](https://github.com/cachix/ghcide-nix)
66   which provides a `ghcide` via the `haskell.nix` infrastructure.
67
68#### With Cabal or Stack
69
70First install the `ghcide` binary using `stack` or `cabal`, e.g.
71
721. `git clone https://github.com/haskell/ghcide.git`
732. `cd ghcide`
743. `cabal install` or `stack install` (and make sure `~/.local/bin` is on your `$PATH`)
75
76It's important that `ghcide` is compiled with the same compiler you use to build your projects.
77
78### Test `ghcide`
79
80Next, 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`](https://github.com/ndmitchell/shake), running `ghcide` gives some error messages and warnings before reporting at the end:
81
82```console
83Files that failed:
84 * .\model\Main.hs
85 * .\model\Model.hs
86 * .\model\Test.hs
87 * .\model\Util.hs
88 * .\output\docs\Main.hs
89 * .\output\docs\Part_Architecture_md.hs
90Completed (152 worked, 6 failed)
91```
92
93Of 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.
94
95The `ghcide` executable mostly relies on [`hie-bios`](https://github.com/mpickering/hie-bios) to do the difficult work of setting up your GHC environment. If it doesn't work, see [the `hie-bios` manual](https://github.com/mpickering/hie-bios#readme) to get it working. My default fallback is to figure it out by hand and create a `direct` style [`hie.yaml`](https://github.com/ndmitchell/shake/blob/master/hie.yaml) listing the command line arguments to load the project.
96
97If you can't get `ghcide` working outside the editor, see [this setup troubleshooting guide](docs/Setup.md). Once you have got `ghcide` working outside the editor, the next step is to pick which editor to integrate with.
98
99### Optimal project setup
100
101`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.
102
103### Configuration
104
105`ghcide` accepts the following lsp configuration options:
106
107```typescript
108{
109  // When to check the dependents of a module
110  // AlwaysCheck means retypechecking them on every change
111  // CheckOnSave means dependent/parent modules will only be checked when you save
112  // "CheckOnSaveAndClose" by default
113  checkParents : "NeverCheck" | "CheckOnClose" | "CheckOnSaveAndClose" | "AlwaysCheck" | ,
114  // Whether to check the entire project on initial load
115  // true by default
116  checkProject : boolean
117
118}
119```
120
121### Using with VS Code
122
123The [Haskell](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) extension has a setting for ghcide.
124
125### Using with Atom
126
127You can follow the [instructions](https://github.com/moodmosaic/ide-haskell-ghcide#readme) to install with `apm`.
128
129### Using with Sublime Text
130
131* Install [LSP](https://packagecontrol.io/packages/LSP)
132* Press Ctrl+Shift+P or Cmd+Shift+P in Sublime Text and search for *Preferences: LSP Settings*, then paste these settings
133```
134{
135  "clients":
136  {
137    "ghcide":
138    {
139      "enabled"   : true,
140      "languageId": "haskell",
141      "command"   : ["ghcide", "--lsp"],
142      "scopes"    : ["source.haskell"],
143      "syntaxes"  : ["Packages/Haskell/Haskell.sublime-syntax"]
144    }
145  }
146}
147```
148
149### Using with Emacs
150
151If you don't already have [MELPA](https://melpa.org/#/) package installation configured, visit MELPA [getting started](https://melpa.org/#/getting-started) page to get set up. Then, install [`use-package`](https://melpa.org/#/use-package).
152
153Now you have a choice of two different Emacs packages which can be used to communicate with the `ghcide` LSP server:
154
155+ `lsp-ui`
156+ `eglot` (requires Emacs 26.1+)
157
158In each case, you can enable support by adding the shown lines to your `.emacs`:
159
160#### lsp-ui
161
162```elisp
163;; LSP
164(use-package flycheck
165  :ensure t
166  :init
167  (global-flycheck-mode t))
168(use-package yasnippet
169  :ensure t)
170(use-package lsp-mode
171  :ensure t
172  :hook (haskell-mode . lsp)
173  :commands lsp)
174(use-package lsp-ui
175  :ensure t
176  :commands lsp-ui-mode)
177(use-package lsp-haskell
178 :ensure t
179 :config
180 (setq lsp-haskell-process-path-hie "ghcide")
181 (setq lsp-haskell-process-args-hie '())
182 ;; Comment/uncomment this line to see interactions between lsp client/server.
183 ;;(setq lsp-log-io t)
184)
185```
186
187#### eglot
188
189````elisp
190(use-package eglot
191  :ensure t
192  :config
193  (add-to-list 'eglot-server-programs '(haskell-mode . ("ghcide" "--lsp"))))
194````
195
196### Using with Vim/Neovim
197
198#### LanguageClient-neovim
199Install [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
200
201Add this to your vim config:
202```vim
203let g:LanguageClient_rootMarkers = ['*.cabal', 'stack.yaml']
204let g:LanguageClient_serverCommands = {
205    \ 'rust': ['rls'],
206    \ 'haskell': ['ghcide', '--lsp'],
207    \ }
208```
209
210Refer to `:he LanguageClient` for more details on usage and configuration.
211
212#### vim-lsp
213Install [vim-lsp](https://github.com/prabirshrestha/vim-lsp).
214
215Add this to your vim config:
216
217```vim
218au User lsp_setup call lsp#register_server({
219    \ 'name': 'ghcide',
220    \ 'cmd': {server_info->['/your/path/to/ghcide', '--lsp']},
221    \ 'whitelist': ['haskell'],
222    \ })
223```
224
225To verify it works move your cursor over a symbol and run `:LspHover`.
226
227### coc.nvim
228
229Install [coc.nvim](https://github.com/neoclide/coc.nvim)
230
231Add this to your coc-settings.json (which you can edit with :CocConfig):
232
233```json
234{
235  "languageserver": {
236    "haskell": {
237      "command": "ghcide",
238      "args": [
239        "--lsp"
240      ],
241      "rootPatterns": [
242        ".stack.yaml",
243        ".hie-bios",
244        "BUILD.bazel",
245        "cabal.config",
246        "package.yaml"
247      ],
248      "filetypes": [
249        "hs",
250        "lhs",
251        "haskell"
252      ]
253    }
254  }
255}
256```
257
258Here's a nice article on setting up neovim and coc: [Vim and Haskell in
2592019](http://marco-lopes.com/articles/Vim-and-Haskell-in-2019/) (this is actually for haskell-ide, not ghcide)
260
261Here is a Docker container that pins down the build and configuration for
262Neovim and ghcide on a minimal Debian 10 base system:
263[docker-ghcide-neovim](https://github.com/carlohamalainen/docker-ghcide-neovim/).
264
265### SpaceVim
266
267In the `autocomplete` layer, add the `autocomplete_method` option to force the use of `coc`:
268
269```toml
270[[layers]]
271  name = 'autocomplete'
272  auto-completion-return-key-behavior = "complete"
273  auto-completion-tab-key-behavior = "smart"
274  [options]
275    autocomplete_method = "coc"
276```
277
278Add this to your coc-settings.json (which you can edit with :CocConfig):
279
280```json
281{
282  "languageserver": {
283    "haskell": {
284      "command": "ghcide",
285      "args": [
286        "--lsp"
287      ],
288      "rootPatterns": [
289        ".stack.yaml",
290        ".hie-bios",
291        "BUILD.bazel",
292        "cabal.config",
293        "package.yaml"
294      ],
295      "filetypes": [
296        "hs",
297        "lhs",
298        "haskell"
299      ]
300    }
301  }
302}
303```
304
305This example above describes a setup in which `ghcide` is installed
306using `stack install ghcide` within a project.
307
308### Using with Kakoune
309
310Install [kak-lsp](https://github.com/ul/kak-lsp).
311
312Change `kak-lsp.toml` to include this:
313
314```toml
315[language.haskell]
316filetypes = ["haskell"]
317roots = ["Setup.hs", "stack.yaml", "*.cabal", "cabal.project", "hie.yaml"]
318command = "ghcide"
319args = ["--lsp"]
320```
321
322## Hacking on ghcide
323
324To build and work on `ghcide` itself, you should use cabal, e.g.,
325running `cabal test` will execute the test suite. You can use `stack test` too, but
326note that some tests will fail, and none of the maintainers are currently using `stack`.
327
328If you are using Nix, there is a Cachix nix-shell cache for all the supported platforms: `cachix use haskell-ghcide`.
329
330If 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`.
331
332If you are chasing down test failures, you can use the tasty-rerun feature by running tests as
333
334    cabal test --test-options"--rerun"
335
336This writes a log file called `.tasty-rerun-log` of the failures, and only runs those.
337See the [tasty-rerun](https://hackage.haskell.org/package/tasty-rerun-1.1.17/docs/Test-Tasty-Ingredients-Rerun.html) documentation for other options.
338
339If you are touching performance sensitive code, take the time to run a differential
340benchmark between HEAD and master using the benchHist script. This assumes that
341"master" points to the upstream master.
342
343Run the benchmarks with `cabal bench`.
344
345It 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.
346
347More details in [bench/README](bench/README.md)
348
349
350## History and relationship to other Haskell IDE's
351
352The teams behind this project and the [`haskell-ide-engine`](https://github.com/haskell/haskell-ide-engine#readme) have agreed to join forces under the [`haskell-language-server` project](https://github.com/haskell/haskell-language-server), see the [original announcement](https://neilmitchell.blogspot.com/2020/01/one-haskell-ide-to-rule-them-all.html). 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](https://github.com/haskell/haskell-language-server).
353
354The code behind `ghcide` was originally developed by [Digital Asset](https://digitalasset.com/) as part of the [DAML programming language](https://github.com/digital-asset/daml). DAML is a smart contract language targeting distributed-ledger runtimes, based on [GHC](https://www.haskell.org/ghc/) with custom language extensions. The DAML programming language has [an IDE](https://webide.daml.com/), and work was done to separate off a reusable Haskell-only IDE (what is now `ghcide`) which the [DAML IDE then builds upon](https://github.com/digital-asset/daml/tree/master/compiler/damlc). Since that time, there have been various [non-Digital Asset contributors](https://github.com/haskell/ghcide/graphs/contributors), in addition to continued investment by Digital Asset. The project has been handed over to Haskell.org as of September 2020.
355
356The Haskell community [has](https://github.com/DanielG/ghc-mod) [various](https://github.com/chrisdone/intero) [IDE](https://github.com/rikvdkleij/intellij-haskell) [choices](http://leksah.org/), but the one that had been gathering momentum is [`haskell-ide-engine`](https://github.com/haskell/haskell-ide-engine#readme). Our project owes a debt of gratitude to the `haskell-ide-engine`. We reuse libraries from their ecosystem, including [`hie-bios`](https://github.com/mpickering/hie-bios#readme) (a likely future environment setup layer in `haskell-ide-engine`), [`haskell-lsp`](https://github.com/alanz/haskell-lsp#readme) and [`lsp-test`](https://github.com/bubba/lsp-test#readme) (the `haskell-ide-engine` [LSP protocol](https://microsoft.github.io/language-server-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.
357
358The best summary of the architecture of `ghcide` is available [this talk](https://www.youtube.com/watch?v=cijsaeWNf2E&list=PLxxF72uPfQVRdAsvj7THoys-nVj-oc4Ss) ([slides](https://ndmitchell.com/downloads/slides-making_a_haskell_ide-07_sep_2019.pdf)), given at [MuniHac 2019](https://munihac.de/2019.html). However, since that talk the project has renamed from `hie-core` to `ghcide`, and the repo has moved to [this location](https://github.com/haskell/ghcide/).
359