Adding Record-Dot-Syntax support to Haskell Language Server
This page serves as a record of the work I did for Google Summer of Code 2022. I want to thank the community at #ghc
and #haskell-language-server
for being so welcoming and helpful this summer. And a special super thanks to Michael Peyton Jones for mentoring me!
Over the summer I added record-dot-syntax support to the haskell language server.
Record-dot-syntax was a highly-requested feature that GHC introduced in version 9.2.0 with the OverloadedRecordDot
language extension. For years users had been frustrated by Haskell’s conspicuous lack of support for namespacing features common in other languages. Haskell provided a limited form of namespacing with qualified imports, but using it to namespace field selectors tended to require hacky file structures. Record-dot-syntax aimed to fix that with ergonomic field selectors that use the syntax myrecord.somefield
.
To unlock the true potential of this language feature, users should be able to “dot into” records as they edit, seeing the fields available to select. This was the main contribution of this project. Additionally, users expect the editor correctly report type information when they hover over records, so this was another important contribution.
I decided to split my work into two phases: adding support for hover information first, then adding support for completions. The reason was that it would be easier to add completion information once the type information is properly exposed.
Phase 1: Exposing type information on hover
Relevant issues and commits:
- The issue that explains what type information needs to be included in the AST: ghc#21797
- The patch that adds the type information to the AST: ghc!8589
- A backport of the patch for GHC 9.2.x, added to a compatibility library included in HLS: haskell-language-server#3016
Phase 2: Adding completions
Relevant issues and commits:
- The main issue where I tackled completions: haskell-language-server#3080 Note: Due to some recent issues with the repo’s CI affecting all PRs, this hasn’t been merged yet, although it’s functionality is complete.
- An issue where some discussions took place about completions and record-dot-syntax overall: haskell-language-server#2732