tweag / tweag/rules_haskell

Improve Bazel experience in Dante upstream

Open
#464 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P2 type: feature request
Dominant language
Starlark
Stars
279
Forks
93
Avg merge
13d 11h
Merged PRs (30d)
3

Description

This is really a ticket for Dante, but filing here for this team to prioritize. Several IDE integration options today are unfortunately tied pretty tightly to the existence of Stack (unnecessarily so!). This includes intero, and hence also haskero and haskelly for VSCode (since both depend on intero). Dante shows that in the case of Emacs and likely others too, you can get pretty much all of the same features working uniformly for many build tools with very little tool-specific code (typically just a few lines in dante.el). ghcid shows something else: that no IDE integration can be workable too.

It's possible to make Dante work with Bazel today in simple cases where all source files can be provided to GHCi as-is (no system dependencies etc). You have to tell Dante that you want it to spawn a naked GHCi prompt for this to work and set dante-project-root manually. To improve on this, we need to:

  1. Teach Dante to recognize the project root automatically by looking for a WORKSPACE file.
  2. Teach Dante what <target-name> to use when calling bazel run @replto spawn the REPL, given the name ofWORKSPACE`-relative source file path.
  3. (optional) make it so that Dante only uses one REPL session per *-@repl target, to save on memory. Since we have one *-@repl target per haskell_library or haskell_binary, not one per source file. I don't know how hard this would be. Maybe trivial or very hard depending on the internals of Dante.

For (2), Dante internally has a buffer-local variable called dante-target, which is the name of the target to supply to the REPL. Given the filename /path/to/Foo.hs associated with the current buffer, we can compute <target-name> as follows:

fullname=$(bazel query //path/to/file/bar.java)
bazel query "attr('srcs', $fullname, ${fullname//:*/}:*)"

cc @jyp.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

This ticket is for Dante upstream; start by reading dante.el and the described dante-target behavior, then inspect how WORKSPACE-relative source paths map to Bazel targets. Done would include automatic project-root detection and target selection for Bazel REPLs; shared REPL sessions are listed as optional and may require understanding Dante internals.

Written by the indexing model from the issue text.

Assessment

Tech stack
emacs, haskell
Domain
build-system, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.