Skip to content

Commit 438f699

Browse files
authored
Merge pull request #497 from michaelpj/imp/config-readme
Expand explanation of how to configure HLS
2 parents 801b4ec + 030da6b commit 438f699

File tree

1 file changed

+85
-43
lines changed

1 file changed

+85
-43
lines changed

README.md

+85-43
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,18 +409,21 @@ 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

393421
Install from
394422
[the VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=haskell.haskell), or manually from the repository [vscode-haskell](https://github.com/haskell/vscode-haskell).
395423
The `haskell-language-server` and `haskell-language-server-wrapper` binaries will be automatically downloaded on an ad-hoc basis, but if you have them already installed on your PATH then it will just use them instead.
396424

425+
Configuration is done via the "Haskell" section of "Settings".
426+
397427
### Using Haskell Language Server with Sublime Text
398428

399429
- Install [LSP](https://packagecontrol.io/packages/LSP) using [Package Control](https://packagecontrol.io/)
@@ -465,7 +495,7 @@ and issuing a `:PlugInstall` command within Neovim or Vim.
465495
As an alternative to using [vim-plug](https://github.com/junegunn/vim-plug) shown above, clone [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
466496
into `~/.vim/pack/XXX/start/`, where `XXX` is just a name for your "plugin suite".
467497

468-
##### Sample `~/.vimrc`
498+
##### Configuration and sample `~/.vimrc` sections
469499

470500
```vim
471501
set rtp+=~/.vim/pack/XXX/start/LanguageClient-neovim
@@ -506,6 +536,9 @@ it may also be helpful to also specify root markers:
506536
let g:LanguageClient_rootMarkers = ['*.cabal', 'stack.yaml']
507537
```
508538

539+
Further configuration can be done by pointing the [`g:LanguageClient_settingsPath`](https://github.com/autozimu/LanguageClient-neovim/blob/0e5c9546bfddbaa2b01e5056389c25aefc8bf989/doc/LanguageClient.txt#L221)
540+
variable to the file in which you want to keep your LSP settings.
541+
509542
### Using Haskell Language Server with Atom
510543

511544
Install the two Atom packages [atom-ide-ui](https://atom.io/packages/atom-ide-ui) and [haskell](https://atom.io/packages/haskell),
@@ -532,7 +565,7 @@ such as the path to the server binary.
532565

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

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

538571
``` emacs-lisp
@@ -553,8 +586,8 @@ Enable the `haskell` layer and the `lsp` layer in your Spacemacs config file:
553586
```emacs-lisp
554587
dotspacemacs-configuration-layers
555588
'(
556-
haskell
557-
lsp
589+
haskell
590+
lsp
558591
;; ...
559592
)
560593
```
@@ -648,3 +681,12 @@ To do every time you changed code and want to test it:
648681
- With Stack: `stack build haskell-language-server:exe:haskell-language-server`
649682
- Restart HLS
650683
- With VS Code: `Haskell: Restart Haskell LSP Server`
684+
685+
### Adding support for a new editor
686+
687+
Adding support for new editors is fairly easy if the editor already has good support for generic LSP-based extensions.
688+
In that case, there will likely be an editor-specific support system for this (like `lsp-mode` for Emacs).
689+
This will typically provide instructions for how to support new languages.
690+
691+
In some cases you may need to write a small bit of additional client support, or expose a way for the user to set the server's [configuration options](#configuring-haskell-language-server) and
692+
for them to configure how the server is started.

0 commit comments

Comments
 (0)