Skip to content

Commit ab517d3

Browse files
author
Julien Debon
committed
Rework "Configuration" and "Manually testing HLS" documentations
1 parent e0d82e7 commit ab517d3

File tree

2 files changed

+87
-73
lines changed

2 files changed

+87
-73
lines changed

docs/configuration.md

+42-22
Original file line numberDiff line numberDiff line change
@@ -90,83 +90,97 @@ Settings like this are typically be provided by the language-specific LSP client
9090
## Configuring your project build
9191

9292
`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.
93-
This is handled by the [hie-bios](https://github.com/mpickering/hie-bios) project.
93+
This is handled under the hood by the [hie-bios](https://github.com/mpickering/hie-bios) application.
94+
In turn, `hie-bios` needs some configuration to identify all files, GHC options, etc., needed to compile a project.
9495

95-
**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).**
96+
There are several ways to provide this configuration to `hie-bios`, detailed below.
9697

97-
At the moment, `haskell-language-server` has support to automatically detect your project build configuration to handle most use cases.
98+
### Implicit configuration
99+
If no `hie.yaml` file is present, `haskell-language-server` automatically detects your `hie-bios` configuration.
100+
**For most cases, this works just fine, and is the recommended way.**
98101

99-
*So using a explicit `hie.yaml` file will not likely fix your ide setup*. It will do it almost only if you see an error like `Multi Cradle: No prefixes matched`
102+
See [the hie-bios documentation](https://github.com/haskell/hie-bios#implicit-configuration) for more information on implicit configuration.
103+
104+
### Explicit, generated configuration
105+
Maybe using the implicit configuration does not suit you.
106+
E.g., it does not work, or you prefer to have explicit configuration in your project.
107+
In that case, you can automatically generate a `hie.yaml` file, using [implicit-hie](https://github.com/Avi-D-coder/implicit-hie):
108+
109+
```shell
110+
gen-hie > hie.yaml # In the root directory of your project
111+
```
112+
113+
### Explicit, manual configuration
114+
Maybe using the generated `hie.yaml` file does not suit you.
115+
E.g., it still does not work, or you want to fine-tune the configuration.
116+
We recommend to start from the `hie.yaml` file generated by `implicit-hie` (see previous section) and modify it to suit your needs.
100117

101-
If the automatic detection fails with that error you can configure `hie-bios` using a `hie.yaml` file in the root of the workspace.
102-
A `hie.yaml` file **explicitly** describes how to setup the environment to compile the various parts of your project.
103118
For that you need to know what *components* your project has, and the path associated with each one.
104119
So you will need some knowledge about
105120
[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.
106121

107-
You also can use [implicit-hie](https://github.com/Avi-D-coder/implicit-hie) to automatically generate `hie.yaml` files for
108-
the most common stack and cabal configurations
122+
**For a full explanation of how to configure it manually, refer to the [hie-bios documentation](https://github.com/mpickering/hie-bios/blob/master/README.md).**
123+
124+
#### Examples of explicit `hie-yaml` configurations
109125

110-
For example, to state that you want to use `stack` then the configuration file
111-
would look like:
126+
##### Single Stack component
112127

113128
```yaml
114129
cradle:
115130
stack:
116131
component: "haskell-language-server:lib"
117132
```
118133
119-
If you use `cabal` then you probably need to specify which component you want
120-
to use.
134+
##### Single Cabal component
121135
122136
```yaml
123137
cradle:
124138
cabal:
125139
component: "lib:haskell-language-server"
126140
```
127141
128-
If you have a project with multiple components, you can use a cabal-multi
129-
cradle:
142+
##### Multiple Stack components
130143
131144
```yaml
132145
cradle:
133-
cabal:
146+
stack:
134147
- path: "./test/functional/"
135148
component: "haskell-language-server:func-test"
136-
- path: "./test/utils/"
137-
component: "haskell-language-server:hls-test-utils"
138149
- path: "./exe/Main.hs"
139150
component: "haskell-language-server:exe:haskell-language-server"
140151
- path: "./exe/Wrapper.hs"
141152
component: "haskell-language-server:exe:haskell-language-server-wrapper"
142153
- path: "./src"
143-
component: "lib:haskell-language-server"
154+
component: "haskell-language-server:lib"
144155
- path: "./ghcide/src"
145156
component: "ghcide:lib:ghcide"
146157
- path: "./ghcide/exe"
147158
component: "ghcide:exe:ghcide"
148159
```
149160
150-
Equivalently, you can use stack:
161+
##### Multiple Cabal components
151162
152163
```yaml
153164
cradle:
154-
stack:
165+
cabal:
155166
- path: "./test/functional/"
156167
component: "haskell-language-server:func-test"
168+
- path: "./test/utils/"
169+
component: "haskell-language-server:hls-test-utils"
157170
- path: "./exe/Main.hs"
158171
component: "haskell-language-server:exe:haskell-language-server"
159172
- path: "./exe/Wrapper.hs"
160173
component: "haskell-language-server:exe:haskell-language-server-wrapper"
161174
- path: "./src"
162-
component: "haskell-language-server:lib"
175+
component: "lib:haskell-language-server"
163176
- path: "./ghcide/src"
164177
component: "ghcide:lib:ghcide"
165178
- path: "./ghcide/exe"
166179
component: "ghcide:exe:ghcide"
167180
```
168181
169-
Or you can explicitly state the program which should be used to collect
182+
##### Custom program
183+
You can explicitly state the program which should be used to collect
170184
the options by supplying the path to the program. It is interpreted
171185
relative to the current working directory if it is not an absolute path.
172186
@@ -196,6 +210,12 @@ dependencies:
196210
- someDep
197211
```
198212
213+
### Common problems
214+
215+
#### Multi Cradle: No prefixes matched
216+
The error message `Multi Cradle: No prefixes matched` usually means that implicit configuration failed.
217+
In that case, you must use explicit configuration.
218+
199219
### How to show local documentation on hover
200220

201221
Haskell Language Server can display Haddock documentation on hover and completions if the project and

docs/contributing/contributing.md

+45-51
Original file line numberDiff line numberDiff line change
@@ -108,79 +108,73 @@ $ cabal run haskell-language-server:func-test -- -p "hlint enables"
108108

109109
## Using HLS on HLS code
110110

111-
Project source code should load without `hie.yaml` setup.
111+
Refer to the [HLS project configuration guidelines](../configuration.md#configuring-your-project-build) as they also apply to the HLS project itself.
112112

113-
In other cases:
114-
115-
1. Check if `hie.yaml` (& `hie.yml`) files left from previous configurations.
116-
117-
2. If the main project needs special configuration, note that other internal subprojects probably also would need configuration.
118-
119-
To create an explicit configuration for all projects - use [implicit-hie](https://github.com/Avi-D-coder/implicit-hie) generator directly:
120-
121-
```shell
122-
gen-hie > hie.yaml # into the main HLS directory
123-
```
124-
125-
that configuration should help.
126-
127-
3. Inspect & tune configuration explicitly.
128-
129-
[Configuring project build](../configuration.md#configuring-your-project-build) applies to HLS project source code loading just as to any other.
130-
131-
Note: HLS may implicitly detect codebase as a Stack project (see [hie-bios implicit configuration documentation](https://github.com/haskell/hie-bios/blob/master/README.md#implicit-configuration)). To use Cabal, try creating an `hie.yaml` file:
113+
Note: HLS implicitly detects the HLS codebase as a Stack project (since there is a `stack.yaml` file).
114+
If you want HLS to use Cabal, create this `hie.yaml` file at the root of the project:
132115

133116
```yaml
134117
cradle:
135118
cabal:
136119
```
137120
138-
### Manually testing your hacked HLS
139-
If you want to test HLS while hacking on it, follow the steps below.
140-
141-
#### Using Cabal
121+
## Manually testing your hacked HLS
122+
If you want to test HLS while hacking on it (you can even test it on HLS codebase itself, see previous section), you need to:
142123
143-
- Whenever you want to build HLS, call `cabal install exe:haskell-language-server --overwrite-policy=always`.
144-
At the end of the output you will find the path the HLS executable was installed to, i.e.:
124+
1. (Once) Find the path to the hacked HLS you build
125+
2. (Once) Configure your editor to use it
126+
3. (Every time you change the HLS code) Rebuild HLS
127+
4. (Every time you change the HLS code) Restart the LSP workspace
145128
146-
```
147-
...
148-
Resolving dependencies...
149-
Symlinking 'haskell-language-server' to
150-
'/home/user/.cabal/bin/haskell-language-server'
151-
Symlinking 'haskell-language-server-wrapper' to
152-
'/home/user/.cabal/bin/haskell-language-server-wrapper'
153-
```
129+
### Find the path to the hacked HLS you build
130+
Note that unless you change the GHC version or the HLS version between builds, the path should remain the same, this is why you need to set it only once.
154131
155-
In this example output, the path would be `/home/user/.cabal/bin/haskell-language-server`.
132+
#### Using Cabal
133+
Run:
134+
```shell
135+
$ cabal build exe:haskell-language-server && cabal list-bin exe:haskell-language-server
136+
[..]
137+
<some long path>/haskell-language-server
138+
```
156139

157-
- Open some codebase on which you want to test your local HLS in your favorite editor (it can also be the HLS codebase itself: see previous section for configuration)
158-
- Configure this editor to use your custom HLS executable by using the path you obtained previously.
159-
- Restart HLS in your project:
160-
- With VS Code: Press `CTRL + Shift + P` and type `Haskell: Restart Haskell LSP Server`
161-
- With Emacs: `lsp-workspace-restart`
140+
#### Using Stack
141+
Run:
142+
```shell
143+
$ echo $(pwd)/$(stack path --dist-dir)/build/haskell-language-server/haskell-language-server
144+
[..]
145+
<some long path>/haskell-language-server
146+
```
162147

163-
##### VS Code
148+
### Configure your editor to use it
164149

165-
When using VS Code you can set up a test project to use a specific HLS executable:
150+
#### VS Code
151+
When using VS Code you can set up each project to use a specific HLS executable:
166152

167153
- If it doesn't already exist in your project directory, create a directory called `.vscode`.
168-
- In the `.vscode` directory create a file called `settings.json` with the below contents. The path used here is the one obtained by using the `cabal` install command.
169-
154+
- In the `.vscode` directory create a file called `settings.json` with the below contents.
170155
```json
171156
{
172-
"haskell.serverExecutablePath": "/home/user/.cabal/bin/haskell-language-server"
157+
"haskell.serverExecutablePath": "/path/to/your/hacked/haskell-language-server"
173158
}
174159
```
175160

176-
#### Using Stack
161+
#### Emacs
162+
There are several ways to configure the HLS server path:
163+
- `M-x customize-group<RET>lsp-haskell<RET>Lsp Haskell Server Path`
164+
- Evaluate `(setq lsp-haskell-server-path "/path/to/your/hacked/haskell-language-server")`
165+
- Create a file `.dir-locals.el` with the following content:
166+
```lisp
167+
((haskell-mode . ((lsp-haskell-server-path . "/path/to/your/hacked/haskell-language-server"))))
168+
```
169+
170+
### Rebuild HLS
171+
- With Stack: `stack build haskell-language-server:exe:haskell-language-server`
172+
- With Cabal: `cabal build exe:haskell-language-server`
177173

178-
- Open some codebase on which you want to test your local HLS in your favorite editor (it can also be the HLS codebase itself: see previous section for configuration)
179-
- Configure this editor to use your custom HLS executable
180-
- To obtain the path to your local HLS executable: `$(stack path --dist-dir)/build/haskell-language-server/haskell-language-server`
174+
### Restart the LSP workspace
181175

182-
- Build HLS
183-
- `stack build haskell-language-server:exe:haskell-language-server`
176+
- With VS Code: Press `Ctrl + Shift + p` and type `Haskell: Restart Haskell LSP Server`
177+
- With Emacs: `M-x lsp-workspace-restart`
184178

185179
## Style guidelines
186180

0 commit comments

Comments
 (0)