@@ -1,34 +1,66 @@
1−# Haskell IDE Core
1+# `hie-core` (Haskell IDE Core)
3Our vision is that you should build an IDE by combining:
3Our vision is that you should build an IDE by combining:
5−* [hie-bios](https://github.com/mpickering/hie-bios) for determining where your files are, what the dependencies, what extensions are enabled etc.
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` - this library - for defining how to type check, when to type check, and producing messages.
6+* `hie-core` (i.e. 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.
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, e.g. `extension` in this directory.
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).
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).
12## How to use it
12## How to use it
14−### Installing the binary
16+#### Installing the binary
161. `git clone https://github.com/digital-asset/daml.git`
181. `git clone https://github.com/digital-asset/daml.git`
172. `cd daml/compiler/hie-core`
192. `cd daml/compiler/hie-core`
183. `stack build`
203. `stack build`
20−### Installing the VSCode extension
22+#### Installing the VSCode extension
221. `cd compiler/hie-core/extension`
241. `cd compiler/hie-core/extension`
232. `npm ci`
252. `npm ci`
243. `vsce package`
263. `vsce package`
254. `code --install-extension hie-core-0.0.1.vsix`
274. `code --install-extension hie-core-0.0.1.vsix`
27−### Installing in Emacs
29+### Emacs
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.
33+;;Melpa packages support
35+(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
36+ (not (gnutls-available-p))))
37+ (proto (if no-ssl "http" "https")))
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/")))))
52+;; Remember : to avoid package-not-found errors, refresh the package
53+;; database now and then with M-x package-refresh-contents.
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:
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` :
63+;; LSP support for Haskell
32(require 'lsp)
64(require 'lsp)
33(require 'lsp-haskell)
65(require 'lsp-haskell)
34(require 'yasnippet)
66(require 'yasnippet)
@@ -36,3 +68,21 @@ There are more details [in this blog post](https://4ta.uk/p/shaking-up-the-ide).
36(setq lsp-haskell-process-path-hie "hie-core")
68(setq lsp-haskell-process-path-hie "hie-core")
37(setq lsp-haskell-process-args-hie '())
69(setq lsp-haskell-process-args-hie '())
72+Optionally, you may wish to add the following conveniences:
74+;; Enable LSP logging (helpful for debugging)
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)
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`).
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
86+cradle: {cabal: {component: "exe:ghc-lib-gen"}}
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.