Skip to content

Commit 3845726

Browse files
committed
Expand explanation of how to configure HLS
This topic tends to confuse people, which is unsurprising since there are several parts which can in principle be configured separately. I've tried to explain this a bit better. I also tried to give some brief documentation on the language server settings that we provide. In the process I found that a few of them seem to be currently unused, so I'm not sure what to say about them.
1 parent a6e6c0b commit 3845726

File tree

1 file changed

+79
-42
lines changed

1 file changed

+79
-42
lines changed

README.md

+79-42
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,14 @@ background](https://neilmitchell.blogspot.com/2020/01/one-haskell-ide-to-rule-th
2727
- [Building](#building)
2828
- [Install via cabal](#install-via-cabal)
2929
- [Install specific GHC Version](#install-specific-ghc-version)
30-
- [HLS LSP Configuration](#hls-lsp-configuration)
31-
- [Project Configuration](#project-configuration)
32-
- [Editor Integration](#editor-integration)
30+
- [Configuring haskell-language-server](#configuring-haskell-language-server)
31+
- [Configuring your project build](#configuring-your-project-build)
32+
- [Configuring your editor](#configuring-your-editor)
3333
- [VS Code](#using-haskell-language-server-with-vs-code)
3434
- [Sublime Text](#using-haskell-language-server-with-sublime-text)
3535
- [Vim or Neovim](#using-haskell-language-server-with-vim-or-neovim)
36-
- [Coc](#coc)
37-
- [LanguageClient-neovim](#languageclient-neovim)
38-
- [vim-plug](#vim-plug)
39-
- [Clone the LanguageClient-neovim repo](#clone-the-languageclient-neovim-repo)
40-
- [Sample `~/.vimrc`](#sample-vimrc)
4136
- [Atom](#using-haskell-language-server-with-atom)
4237
- [Emacs](#using-haskell-language-server-with-emacs)
43-
- [Doom emacs](#using-haskell-language-server-with-doom-emacs)
44-
- [Spacemacs](#using-haskell-language-server-with-spacemacs)
4538
- [Kakoune](#using-haskell-language-server-with-kakoune)
4639
- [Known limitations](#known-limitations)
4740
- [Preprocessor](#preprocessor)
@@ -253,44 +246,78 @@ If your desired ghc has been found, you use it to install haskell-language-serve
253246
./cabal-hls-install data
254247
```
255248

256-
## HLS LSP Configuration
249+
## Configuring `haskell-language-server`
257250

258-
haskell-language-server supports some forms of configuration.
251+
Language servers like `haskell-language-server` expose most of their configuration via the client (i.e. the editor).
252+
That means that the way in which you configure the settings will depend on the client.
259253

260-
This configuration is done via the LSP settings you provide with your editor and/or LSP client.
261-
Some examples include:
262-
* in VSCode/VSCodium this is done via the `Settings` tab
263-
* with `LanguageClient-neovim` you can point the [`g:LanguageClient_settingsPath`](https://github.com/autozimu/LanguageClient-neovim/blob/0e5c9546bfddbaa2b01e5056389c25aefc8bf989/doc/LanguageClient.txt#L221)
264-
variable to the file in which you want to keep your LSP settings
254+
Most clients (editors) already have an opinion about how settings should be configured!
255+
For example, in VS Code you use the graphical Settings tab or `settings.json`, whereas in Emacs you use customization variables.
256+
In the [editor configuration section](#configuring-your-editor) we give some pointers for popular editors, but you should consult the documentation for your specific editor if you have trouble.
265257

266-
### Formatting providers
267-
##### Raw LSP key name: `haskell.formattingProvider`
258+
However, we can say some high-level things about the kinds of configuration `haskell-language-server` uses, and how to use them.
259+
This can sound a bit confusing, but ultimately the client should present you with these options in a user-friendly way that makes sense for that editor.
268260

269-
By default, haskell-language-server is compiled with support for several different formatters.
261+
### Generic server options
270262

271-
These include
272-
* `floskell`
273-
* `fourmolu`
274-
* `ormolu`
275-
* `stylish-haskell`
276-
* `brittany` (if compiled with AGPL)
263+
The LSP protocol is designed to support many useful server configuration options generically.
264+
These are sent to the server by the client, and can be controlled without reference to a specific language.
277265

278-
## Project Configuration
266+
For example, there are protocol methods for highlighting matching identifiers throughout a document.
267+
This is a capability which any server can implement, so the client can decide generically whether to ask the server to do it or not.
268+
So your editor can provide a setting to turn this on or off globally, for any language server you might use.
279269

280-
**For a full explanation of possible configurations, refer to [hie-bios/README](https://github.com/mpickering/hie-bios/blob/master/README.md).**
270+
Settings like this are typically provided by the generic LSP client support for your editor, for example in Emacs by `lsp-mode`.
281271

282-
haskell-language-server has some limited support via hie-bios to detect automatically
283-
your project configuration and set up the environment for GHC.
272+
### Generic editor options
273+
274+
Your editor may provide some settings that affect how the information from the language server is used.
275+
For example, whether popups are shown, or whether code lenses appear by default.
276+
277+
Settings like this are typically provided by the generic LSP client support for your editor, for example in Emacs by `lsp-mode`.
278+
279+
### Language-specific server options
280+
281+
A specific language server can also have its own configuration options.
282+
These are still sent to the server by the client, but they can only be controlled by a specific client that knows about those options.
283+
284+
For example, `haskell-language-server` allows you to choose the formatting provider which will be used for formatting Haskell source.
285+
This option obviously would not make sense for language servers for other languages, or even for other Haskell language servers (which need not even support formatting).
286+
287+
Here is a list of the additional settings currently supported by `haskell-language-server`, along with their setting key (you may not need to know this) and default:
288+
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, `stylish-haskell`, or `brittany` (if compiled with AGPL)
289+
- Format on imports (`haskell.formatOnImportOn`, default true): whether to format after adding an import
290+
- Maximum number of problems to report (`haskell.maxNumberOfProblems`, default 100): the maximum number of problems the server will send to the client
291+
- Diagnostics on change (`haskell.diagnosticsOnChange`, default true): (currently unused)
292+
- Completion snippets (`haskell.completionSnippetsOn`, default true): whether to support completion snippets (currently unused until we have snippets to provide)
293+
- Liquid Haskell (`haskell.liquidOn`, default false): whether to enable Liquid Haskell support (currently unused until the Liquid Haskell support is functional again)
294+
- Hlint (`haskell.hlintOn`, default true): whether to enable Hlint support (currently unused until the Hlint support is functional again)
295+
296+
Settings like this are typically provided by the language-specific LSP client support for your editor, for example in Emacs by `lsp-haskell`.
297+
298+
### Client options
299+
300+
A particular client might also have some options of its own, for example to control how the server executable is started.
301+
302+
Settings like this are typically be provided by the language-specific LSP client support for your editor, for example in Emacs by `lsp-haskell`.
303+
304+
## Configuring your project build
305+
306+
`haskell-language-server` has to compile your project in order to give you diagnostics, which means that it needs to know how to do so.
307+
This is handled by the [`hie-bios`](https://github.com/mpickering/hie-bios) project.
308+
309+
**For a full explanation of how `hie-bios` determines the project build configuration, and how to configure it manually, refer to the [`hie-bios` README](https://github.com/mpickering/hie-bios/blob/master/README.md).**
310+
311+
At the moment, `haskell-language-server` has some limited support to automatically detect your project build configuration.
284312
The plan is to improve it to handle most use cases.
285313

286-
However, for now, the more reliable way is using a `hie.yaml` file in the root
287-
of the workspace to **explicitly** describe how to setup the environment.
288-
For that you need to know what *components* have your project and the path
289-
associated with each one. So you will need some knowledge about
314+
However, for now, the most reliable way is to manually configure `hie-bios` using a `hie.yaml` file in the root of the workspace.
315+
A `hie.yaml` file **explicitly** describes how to setup the environment to compile the various parts of your project.
316+
For that you need to know what *components* your project has, and the path associated with each one.
317+
So you will need some knowledge about
290318
[stack](https://docs.haskellstack.org/en/stable/build_command/#components) or [cabal](https://cabal.readthedocs.io/en/latest/cabal-commands.html?#cabal-v2-build) components.
291319

292-
You also can use [this utility](https://github.com/Avi-D-coder/implicit-hie
293-
) to generate automatically `hie.yaml` files for
320+
You also can use [this utility](https://github.com/Avi-D-coder/implicit-hie) to automatically generate `hie.yaml` files for
294321
the most common stack and cabal configurations
295322

296323
For example, to state that you want to use `stack` then the configuration file
@@ -382,11 +409,12 @@ dependencies:
382409
- someDep
383410
```
384411

385-
## Editor Integration
412+
## Configuring your editor
386413

387-
Note to editor integrators: there is a `haskell-language-server-wrapper` executable, which is installed alongside the `haskell-language-server` executable. When this is invoked in the project root directory, it attempts to work out the GHC version used in the project, and then launch the matching `haskell-language-server` executable.
414+
Most editors provide a Haskell-specific extension that provides support for launching `haskell-language-server` and talking to it, as well as [exposing configuration options](#configuring-haskell-language-server).
388415

389-
All of the editor integrations assume that you have already installed `haskell-language-server` (see above) and that the installation script put the `haskell-language-server` and `haskell-language-server-wrapper` binaries in your `PATH` (usually `~/.local/bin` or `~/.cabal/bin` on Linux and macOS, `%APPDATA%\local\bin` or `%APPDATA%\cabal\bin` on Windows).
416+
Editors typically assume that you have already installed `haskell-language-server` (see above) and that the installation script put the `haskell-language-server` and `haskell-language-server-wrapper` binaries in your `PATH` (usually `~/.local/bin` or `~/.cabal/bin` on Linux and macOS, `%APPDATA%\local\bin` or `%APPDATA%\cabal\bin` on Windows).
417+
The exception is VS Code, which can automatically install the binaries if they are not installed already.
390418

391419
### Using Haskell Language Server with VS Code
392420

@@ -532,7 +560,7 @@ such as the path to the server binary.
532560

533561
#### Using haskell-language-server with [doom-emacs](https://github.com/hlissner/doom-emacs/tree/develop/modules/lang/haskell#module-flags)
534562

535-
Manual installation of packages is not required.
563+
Manual installation of packages is not required.
536564
Enable the lsp module and the haskell lang module with lsp flag in `.doom.d/init.el`:
537565

538566
``` emacs-lisp
@@ -553,8 +581,8 @@ Enable the `haskell` layer and the `lsp` layer in your Spacemacs config file:
553581
```emacs-lisp
554582
dotspacemacs-configuration-layers
555583
'(
556-
haskell
557-
lsp
584+
haskell
585+
lsp
558586
;; ...
559587
)
560588
```
@@ -648,3 +676,12 @@ To do every time you changed code and want to test it:
648676
- With Stack: `stack build haskell-language-server:exe:haskell-language-server`
649677
- Restart HLS
650678
- With VS Code: `Haskell: Restart Haskell LSP Server`
679+
680+
### Adding support for a new editor
681+
682+
Adding support for new editors is fairly easy if the editor already has good support for generic LSP-based extensions.
683+
In that case, there will likely be an editor-specific support system for this (like `lsp-mode` for Emacs).
684+
This will typically include instructions for creating a new language server client.
685+
686+
Additionally, you should expose a way for the user to set the server's [configuration options](#configuring-haskell-language-server), and
687+
for them to configure how the server is started.

0 commit comments

Comments
 (0)