Skip to content

Commit bd48d61

Browse files
committed
Share project between hls and hdb
1 parent a821a7d commit bd48d61

6 files changed

Lines changed: 74 additions & 35 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ For these test executables, `-p` which applies a regex filter to the test
167167
names. When running `cabal-install` test suites, one need only use `cabal test` or
168168
`cabal run <test-target>` in order to test locally.
169169

170+
## Using Haskell Language Server
171+
172+
[Haskell Language Server][hls] (HLS) works on this repository through the
173+
[`hie.yaml`](./hie.yaml) cradle in the root, which points it at the
174+
[`cabal.hie.project`](./cabal.hie.project) project rather than the default
175+
`cabal.project`. With that in place, there is nothing to set up beyond having
176+
an HLS that matches the `ghc` on your `PATH`.
177+
178+
> [!WARNING]
179+
> Without `hie.yaml`, HLS tries to load the default project and fails with
180+
> `Failed to parse result of calling cabal` when the `cabal` on your `PATH` is
181+
> cabal-install 3.18 or later, including a build of this repository. HLS uses
182+
> [hie-bios][hie-bios], which asks `cabal repl --with-repl` for the flags to
183+
> load the project, and that fails to resolve dependencies because
184+
> `cabal-testsuite` has a custom setup depending on an older and incompatible
185+
> version of `Cabal`. hie-bios then falls back to an older method that
186+
> cabal-install 3.18 broke. The `cabal.hie.project` project leaves out
187+
> `cabal-testsuite`, so its own code is the one part of the repository that HLS
188+
> doesn't cover.
189+
190+
To check the setup from the command line, run HLS on a file. It loads the file
191+
the same way as it would in an editor and reports what it found:
192+
193+
```
194+
$ haskell-language-server-9.14.1 cabal-install/main/Main.hs
195+
...
196+
Completed (1 file worked, 0 files failed)
197+
```
198+
199+
HLS and the Haskell debugger share a build directory under `~/.cache/hie-bios`,
200+
which is why they share a project. Starting the debugger while HLS is still
201+
loading, or the other way around, can make them trip over each other in there.
202+
203+
[hls]: https://haskell-language-server.readthedocs.io/
204+
170205
## Using the Haskell Debugger
171206

172207
We can debug `cabal` with the [Haskell debugger][hdb] to set breakpoints, step
@@ -191,14 +226,15 @@ To get set up:
191226

192227
We have a project and cradle for debugging:
193228

194-
* [`cabal.hdb.project`](./cabal.hdb.project) with a subset of packages, leaving
195-
out `cabal-testsuite`.
229+
* [`cabal.hie.project`](./cabal.hie.project) with a subset of packages, leaving
230+
out `cabal-testsuite`. This is the same project that Haskell Language Server
231+
uses.
196232

197233
* [`hie-hdb.yaml`](./hie-hdb.yaml) uses this project and lists which components
198234
to load. Breakpoints can only be set in those components. Everything else is
199-
a compiled dependency. The cradle is not named `hie.yaml` so that the Haskell
200-
Language Server won't pick it up. This means it has to be given explicitly to
201-
`hdb`.
235+
a compiled dependency. This is a separate cradle from the `hie.yaml` that
236+
Haskell Language Server uses, as it loads many components at once, so it has
237+
to be given explicitly to `hdb`.
202238

203239
> [!WARNING]
204240
> Do not use `cabal.project`, the default project, for debugging. `hdb` tries to

‎cabal.hdb.project‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎cabal.hie.project‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- A project for the tools that load this repository through hie-bios: Haskell
2+
-- Language Server (via hie.yaml) and the Haskell debugger (via hie-hdb.yaml).
3+
-- See the "Using Haskell Language Server" and "Using the Haskell Debugger"
4+
-- sections of CONTRIBUTING.md.
5+
--
6+
-- This leaves out cabal-testsuite because `cabal repl --with-repl`, that
7+
-- hie-bios relies on, needs Cabal >= 3.16 for the setup of every package in the
8+
-- project and the custom setup of cabal-testsuite depends on an older Cabal.
9+
import: project-cabal/ghc-options.config
10+
import: project-cabal/ghc-latest.config
11+
import: project-cabal/pkgs/cabal.config
12+
import: project-cabal/pkgs/install.config
13+
import: project-cabal/pkgs/tests.config
14+
import: project-cabal/constraints.config
15+
16+
tests: True
17+
18+
-- The tools load packages as bytecode, ignoring optimization flags and warning
19+
-- that they do so.
20+
optimization: False

‎hie-hdb.yaml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# A hie-bios cradle for debugging cabal with the Haskell debugger (hdb), see
22
# the "Using the Haskell debugger" section of CONTRIBUTING.md.
33
#
4-
# This file is deliberately not named hie.yaml so that HLS does not pick it up.
5-
# Pass it to hdb explicitly, with --cradle-file or "cradleFile".
4+
# This is not the hie.yaml that Haskell Language Server uses, because it loads
5+
# many components at once. Pass it to hdb explicitly, with --cradle-file or
6+
# "cradleFile".
67
cradle:
78
cabal:
8-
cabalProject: cabal.hdb.project
9+
cabalProject: cabal.hie.project
910
# Breakpoints can only be set in the components loaded here. To debug a
1011
# test suite, add its component, e.g. cabal-install:test:unit-tests.
1112
componentsToLoad:

‎hie.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The hie-bios cradle for Haskell Language Server, see the "Using Haskell
2+
# Language Server" section of CONTRIBUTING.md.
3+
cradle:
4+
cabal:
5+
cabalProject: cabal.hie.project

‎project-cabal/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ We have these projects, all in the root:
66
$ tree -P '*.project' --prune -L 1
77
.
88
├── cabal.bootstrap.project
9-
├── cabal.hdb.project
9+
├── cabal.hie.project
1010
├── cabal.meta.project
1111
├── cabal.project
1212
├── cabal.release.project
@@ -78,13 +78,13 @@ package group.
7878
| Project | pkgs | cabal | tests | install |
7979
|------------------|:---: |:---: |:---: |:---: |
8080
| default | ✓ | | | |
81-
| hdb | | ✓ | ✓ | ✓ |
81+
| hie | | ✓ | ✓ | ✓ |
8282
| libonly | | ✓ | ✓ | |
8383
| release | | ✓ | ✓ | ✓ |
8484
| validate | ✓ | | | |
8585
| validate.libonly | | ✓ | ✓ | |
8686

87-
The `hdb` project is for use with the Haskell debugger, see
87+
The `hie` project is for use with Haskell Language Server and the Haskell debugger, see
8888
[CONTRIBUTING.md](../CONTRIBUTING.md#using-the-haskell-debugger). It imports the
8989
same package groups as the `release` project, leaving out `cabal-testsuite` and
9090
the benchmarks.
@@ -103,7 +103,7 @@ Additional configuration is imported:
103103
| Project | ghc-options | ghc-latest | constraints |
104104
|------------------|:---: |:---: |:---: |
105105
| default | ✓ | ✓ | ✓ |
106-
| hdb | ✓ | ✓ | ✓ |
106+
| hie | ✓ | ✓ | ✓ |
107107
| libonly | ✓ | | |
108108
| release | | | |
109109
| validate | ✓ | ✓ | ✓ |

0 commit comments

Comments
 (0)