You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -253,44 +246,78 @@ If your desired ghc has been found, you use it to install haskell-language-serve
253
246
./cabal-hls-install data
254
247
```
255
248
256
-
## HLS LSP Configuration
249
+
## Configuring `haskell-language-server`
257
250
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.
259
253
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.
265
257
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.
268
260
269
-
By default, haskell-language-server is compiled with support for several different formatters.
261
+
### Generic server options
270
262
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.
277
265
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.
279
269
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`.
281
271
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.
284
312
The plan is to improve it to handle most use cases.
285
313
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
290
318
[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.
291
319
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
294
321
the most common stack and cabal configurations
295
322
296
323
For example, to state that you want to use `stack` then the configuration file
@@ -382,18 +409,21 @@ dependencies:
382
409
- someDep
383
410
```
384
411
385
-
## Editor Integration
412
+
## Configuring your editor
386
413
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).
388
415
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.
390
418
391
419
### Using Haskell Language Server with VS Code
392
420
393
421
Install from
394
422
[the VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=haskell.haskell), or manually from the repository [vscode-haskell](https://github.com/haskell/vscode-haskell).
395
423
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.
396
424
425
+
Configuration is done via the "Haskell" section of "Settings".
426
+
397
427
### Using Haskell Language Server with Sublime Text
398
428
399
429
- 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.
465
495
As an alternative to using [vim-plug](https://github.com/junegunn/vim-plug) shown above, clone [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
466
496
into `~/.vim/pack/XXX/start/`, where `XXX` is just a name for your "plugin suite".
467
497
468
-
##### Sample `~/.vimrc`
498
+
##### Configuration and sample `~/.vimrc` sections
469
499
470
500
```vim
471
501
set rtp+=~/.vim/pack/XXX/start/LanguageClient-neovim
@@ -506,6 +536,9 @@ it may also be helpful to also specify root markers:
506
536
let g:LanguageClient_rootMarkers = ['*.cabal', 'stack.yaml']
507
537
```
508
538
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
+
509
542
### Using Haskell Language Server with Atom
510
543
511
544
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.
532
565
533
566
#### Using haskell-language-server with [doom-emacs](https://github.com/hlissner/doom-emacs/tree/develop/modules/lang/haskell#module-flags)
534
567
535
-
Manual installation of packages is not required.
568
+
Manual installation of packages is not required.
536
569
Enable the lsp module and the haskell lang module with lsp flag in `.doom.d/init.el`:
537
570
538
571
``` emacs-lisp
@@ -553,8 +586,8 @@ Enable the `haskell` layer and the `lsp` layer in your Spacemacs config file:
553
586
```emacs-lisp
554
587
dotspacemacs-configuration-layers
555
588
'(
556
-
haskell
557
-
lsp
589
+
haskell
590
+
lsp
558
591
;; ...
559
592
)
560
593
```
@@ -648,3 +681,12 @@ To do every time you changed code and want to test it:
648
681
- With Stack: `stack build haskell-language-server:exe:haskell-language-server`
649
682
- Restart HLS
650
683
- 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
0 commit comments