Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add docs on how to choose a formatter #432

Merged
merged 4 commits into from
Oct 2, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This is *very* early stage software.
- [Building](#building)
- [Install via cabal](#install-via-cabal)
- [Install specific GHC Version](#install-specific-ghc-version)
- [HLS LSP Configuration](#hls-lsp-configuration)
- [Project Configuration](#project-configuration)
- [Editor Integration](#editor-integration)
- [VS Code](#using-haskell-language-server-with-vs-code)
Expand Down Expand Up @@ -207,7 +208,7 @@ The script will install the executables `haskell-language-server-wrapper` and `h
It will copy the latter appending the used ghc version, needed by the wrapper to choose the suitable version
for the project at hand.

So installing the executables directly with `stack install` or `cabal v2-install` may not be enough
So installing the executables directly with `stack install` or `cabal v2-install` may not be enough
for it to work properly.

Install haskell-language-server for the latest available and supported GHC version (and hoogle docs):
Expand Down Expand Up @@ -253,6 +254,40 @@ If your desired ghc has been found, you use it to install haskell-language-serve
./cabal-hls-install data
```

## HLS LSP Configuration

haskell-language-server supports some forms of configuration.
Copy link
Collaborator

@fendor fendor Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what editor? For all? Is that a HLS configuration I was not aware of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


This configuration is done via the LSP settings you provide with your editor and/or LSP client.
Some examples include:
* in VSCode/VSCodium this is done via the `Settings` tab
* with `LanguageClient-neovim` you can point the [`g:LanguageClient_settingsPath`](https://github.com/autozimu/LanguageClient-neovim/blob/0e5c9546bfddbaa2b01e5056389c25aefc8bf989/doc/LanguageClient.txt#L221)
variable to the file in which you want to keep your LSP settings

### Formatting providers
By default, haskell-language-server is compiled with support for several different formatters.

These include
* `floskell`
* `fourmolu`
* `ormolu`
* `stylish-haskell`
* `brittany` (if compiled with AGPL)

To choose one of them, you need to include the name of the one you want to use
as the value for the `formattingProvider` key in your LSP configuration like so:
```json
{
...
"haskell": {
...
"formattingProvider": "fourmolu"
...
}
...
}
Copy link
Collaborator

@fendor fendor Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this lsp configuration? I have never seen that one. What should be the name of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming it is a .json file that you point your lsp client to (e.g. in LanguageClient-neovim that seems to be g:LanguageClient_settingsPath)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is specific to LanguageClient-neovim? At least I have never seen such a configuration file for HLS itself. Others will have to clarify.

Copy link
Contributor Author

@googleson78 googleson78 Sep 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it is generic, because I couldn't find another way of choosing a formatter. How do you do so in your editor+client?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode / VSCodium has a settings Tab where you can choose the formatter out of a dropbox menu

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense, so this configuration's location is still editor dependent. We should make this clear and maybe refer to the documentation of the respective lsp-client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some "clarification", is it ok?

I'm also not sure how good an idea being this specific as I was is, because while it's helpful for someone who has never used their respective LSP client before, it might get outdated and is in a way "redundant" information.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite client-specific. For example, in lsp-haskell (the emacs mode), you configure these things with emacs defcustom variables. I think it's reasonable for the client to explain how configuration is done, since we can't specify it in a general way on the server side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there should still be some mention that you can put such a field into your client's configuration, whatever that may be. If it didn't exist in the changelog you would have to read through source code to learn about this.

Besides, there is already precedent for descriptions on how to configure different clients for use with HLS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'm the only one who found it took effort to find this out either:
https://twitter.com/seagreen__/status/1309967145221214209?s=20

```

## Project Configuration

**For a full explanation of possible configurations, refer to [hie-bios/README](https://github.com/mpickering/hie-bios/blob/master/README.md).**
Expand Down Expand Up @@ -575,7 +610,7 @@ This returns an error in HLS if 'tasty-discover' is not in the path: `could not
### Style guidelines

The project includes a [`.editorconfig`](https://editorconfig.org) [file](https://github.com/haskell/haskell-language-server/blob/master/.editorconfig) with the editor basic settings used by the project.
However, most editors will need some action to honour those settings automatically.
However, most editors will need some action to honour those settings automatically.
For example vscode needs to have installed a specific [extension](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig).
Please, try to follow those basic settings to keep the codebase as uniform as possible.

Expand Down Expand Up @@ -616,7 +651,7 @@ If you want to test HLS while hacking on it, follow the steps below.
To do once:
- Open some codebase on which you want to test your hacked HLS in your favorite editor
- Configure this editor to use your custom HLS executable
- With Cabal:
- With Cabal:
- On Unix systems: `cabal exec which haskell-language-server`
- On Windows: `cabal exec where haskell-language-server`
- With Stack: `$(stack path --dist-dir)/build/haskell-language-server/haskell-language-server`
Expand Down