on master help sign in
Integrate Emacs instructions into README (#1831)

* Integrate Emacs instructions into README * Fix a grammatical error

commit0452205859801135e937b0556991e13d7df712b4 authorShayne Fletcher <shayne.fletcher@digitalasset.com> dateSun 23 Jun 2019, 17:59 (7 years ago) parentb448af5
2 files changed+61−61
README.md+61−11 hie-core-in-emacs.md−50
README.md+61−11
@@ -1,34 +1,66 @@
1−# Haskell IDE Core
1+# `hie-core` (Haskell IDE Core)
22
33Our vision is that you should build an IDE by combining:
44
5−* [hie-bios](https://github.com/mpickering/hie-bios) for determining where your files are, what the dependencies, what extensions are enabled etc.
6−* `hie-core` - this library - for defining how to type check, when to type check, and producing messages.
7−* `haskell-lsp` for sending those messages to an LSP server.
8−* A VS Code extension, e.g. `extension` in this directory.
5+* [`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;
6+* `hie-core` (i.e. this library) for defining how to type check, when to type check, and producing messages;
7+* [`haskell-lsp`](https://github.com/alanz/haskell-lsp) for sending those messages to an LSP ([Language Server Protocol](https://microsoft.github.io/language-server-protocol/)) server;
8+* A [VS Code extension](https://code.visualstudio.com/api), e.g. `extension` in this directory (although the above components enable Haskell IDE features in other editors too).
99
10−There are more details [in this blog post](https://4ta.uk/p/shaking-up-the-ide).
10+There are more details about our approach [in this blog post](https://4ta.uk/p/shaking-up-the-ide).
1111
1212## How to use it
1313
14−### Installing the binary
14+### VS Code
15+
16+#### Installing the binary
1517
16181. `git clone https://github.com/digital-asset/daml.git`
17192. `cd daml/compiler/hie-core`
18203. `stack build`
1921
20−### Installing the VSCode extension
22+#### Installing the VSCode extension
2123
22241. `cd compiler/hie-core/extension`
23252. `npm ci`
24263. `vsce package`
25274. `code --install-extension hie-core-0.0.1.vsix`
2628
27−### Installing in Emacs
29+### Emacs
30+
31+The frst step is to install required Emacs packages. If you don't already have [Melpa](https://melpa.org/#/) package installation configured in your `.emacs`, put this stanza at the top.
32+```elisp
33+;;Melpa packages support
34+(require 'package)
35+(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
36+ (not (gnutls-available-p))))
37+ (proto (if no-ssl "http" "https")))
38+ (when no-ssl
39+ (warn "\
40+Your version of Emacs does not support SSL connections,
41+which is unsafe because it allows man-in-the-middle attacks.
42+There are two things you can do about this warning:
43+1. Install an Emacs version that does support SSL and be safe.
44+2. Remove this warning from your init file so you won't see it again."))
45+ ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
46+ (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
47+ ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
48+ (when (< emacs-major-version 24)
49+ ;; For important compatibility libraries like cl-lib
50+ (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
51+(package-initialize)
52+;; Remember : to avoid package-not-found errors, refresh the package
53+;; database now and then with M-x package-refresh-contents.
54+ ```
55+When this is in your `.emacs` and evaluated, `M-x package-refresh-contents` to get the package database downloaded and then `M-x package-list-packages` to display the available packages. Click on a package to install it. You'll need to install the following packages:
56+ - `lsp-haskell`
57+ - `lsp-ui`
58+ - `flycheck`
59+ - `yasnippet`
2860
29−1. Install lsp and haskell-lsp
30−2. Add this elisp to your .emacs.el
61+When done with this, add the following lines to your `.emacs` :
3162```elisp
63+;; LSP support for Haskell
3264(require 'lsp)
3365(require 'lsp-haskell)
3466(require 'yasnippet)
@@ -36,3 +68,21 @@ There are more details [in this blog post](https://4ta.uk/p/shaking-up-the-ide).
3668(setq lsp-haskell-process-path-hie "hie-core")
3769(setq lsp-haskell-process-args-hie '())
3870```
71+
72+Optionally, you may wish to add the following conveniences:
73+```elisp
74+;; Enable LSP logging (helpful for debugging)
75+(setq lsp-log-io t)
76+
77+;; Keyboard mappings for goto next/previous error
78+(define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
79+(define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)
80+```
81+
82+Next stop is to build `hie-core`. In the `daml` repository, navigate to `//compiler/hie-core` and invoked `stack build`. This will install the `hie-core` executable into a location along the lines of `$HOME/path/to/daml/compiler/hie-core/.stack-work/install/x86_64-osx/nightly-2019-05-20/8.6.5/bin/hie-core`. You want to get this executable in your `$PATH`. I achieved this with a command like `ln -s ~/path/to/compiler/hie-core/.stack-work/install/x86_64-osx/nightly-2019-05-20/8.6.5/bin/hie-core ~/.local/bin/hie-core` (because `~/.local/bin` is put into my `PATH` in my `~/.bashrc`).
83+
84+Time to test things out. It's important to note that for this to work, your programs need to be compiled with the same compiler used to build `hie-core`. For testing, I've been using the `ghc-lib-gen` target of the [`ghc-lib` project](https://github.com/digital-asset/ghc-lib). Navigate to the root of `ghc-lib` and create an `hie.yaml` file with contents
85+```yaml
86+cradle: {cabal: {component: "exe:ghc-lib-gen"}}
87+```
88+Invoke `cabal new-configure -w ~/.stack/programs/~/.stack/programs/x86_64-osx/ghc-8.6.5/bin/ghc` (this is the `ghc` used by `stack` to build `hie-core` - consult `//compiler/hie-core/stack.yaml` to help work out what you should write here). This last step will create a file `cabal.project.local` with contents pointing `cabal` to use the desired `ghc`. You can build `ghc-lib-gen` from the `ghc-lib` directory with the command `cabal new-build` as you like. After creating `cabal.project.local`, you should be all set. Open `ghc-lib/ghc-lib-gen/src/Main.hs` in an Emacs buffer and, for example, hover should bring up type/definition info.
hie-core-in-emacs.mddeleted−50
@@ -1,50 +0,0 @@
1−# How to get `hie-core` working in Emacs
2−
3−First step is to install required Emacs packages. If you don't already have Melpa config stuff in your `.emacs`, put this stanza at the top.
4−```
5−;;Melpa packages support
6−(require 'package)
7−(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
8− (not (gnutls-available-p))))
9− (proto (if no-ssl "http" "https")))
10− (when no-ssl
11− (warn "\
12−Your version of Emacs does not support SSL connections,
13−which is unsafe because it allows man-in-the-middle attacks.
14−There are two things you can do about this warning:
15−1. Install an Emacs version that does support SSL and be safe.
16−2. Remove this warning from your init file so you won't see it again."))
17− ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
18− (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
19− ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
20− (when (< emacs-major-version 24)
21− ;; For important compatibility libraries like cl-lib
22− (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
23−(package-initialize)
24−;; Remember : to avoid package-not-found errors, refresh the package
25−;; database now and then with M-x package-refresh-contents.
26−```
27−
28−When this is in your `.emacs` and it's been evaluated, `M-x package-refresh-contents` to get the package database downloaded and then `M-x package-list-packages` to display the available packages. Click on a package to install it. You'll need to install the following packages.
29−- `lsp-haskell`
30−- `lsp-ui`
31−- `flycheck`
32−- `yasnippet`
33−
34−When done with this, add the following lines to your `.emacs` :
35−```
36−;; lsp-haskell
37−(require 'lsp)
38−(require 'lsp-haskell)
39−(require 'yasnippet)
40−(add-hook 'haskell-mode-hook #'lsp)
41−(setq lsp-haskell-process-path-hie "hie-core")
42−(setq lsp-haskell-process-args-hie '())
43−(setq lsp-log-io t) ;; Inspect comms betweeen lsp client/server
44−```
45−
46−Next stop is to build `hie-core`. In the `daml` repository, navigate to `//compiler/hie-core` and invoked `stack build`. This will install the `hie-core` executable into a location along the lines of `/Users/shaynefletcher/project/daml.git/compiler/hie-core/.stack-work/install/x86_64-osx/nightly-2019-05-20/8.6.5/bin/hie-core`. You want to get this executable in your `$PATH`. I achieved this by `ln -s /Users/shaynefletcher/project/daml.git/compiler/hie-core/.stack-work/install/x86_64-osx/nightly-2019-05-20/8.6.5/bin/hie-core ~/.local/bin/hie-core` (because `~/.local/bin` is put in my `PATH` in my `~/.bashrc`).
47−
48−Time to test things out. It's important to note that you for this to work, your programs need to be compiled with the same compiler used to build `hie-core`. For testing, I've been using the `ghc-lib-gen` target of the `ghc-lib` project). Navigate to the root of `ghc-lib`, create an `hie.yaml` file with contents `cradle: {cabal: {component: "exe:ghc-lib-gen"}}`. Invoke `cabal new-configure -w ~/.stack/programs/~/.stack/programs/x86_64-osx/ghc-8.6.5/bin/ghc` (this is the `ghc` used by `stack` to build `hie-core` - consult `//compiler/hie-core/stack.yaml` to help work out what you should write here). This last step will create a file `cabal.project.local` with contents pointing `cabal` to use the desired `ghc`. You can build `ghc-lib-gen` from the `ghc-lib` directory with the command `cabal new-build` as you like.
49−
50−After the last step, you should be all set. Open `ghc-lib/ghc-lib-gen/src/Main.hs` in an Emacs buffer and, for example, hover should bring up type/definition info.