haskell / haskell/haskell-language-server

OverloadedRecordDot support - Type Awareness / Completion

Open
#2,732 12 comments 20 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
3d 21h
Merged PRs (30d)
13

Description

Given the following (GHC 9.2+) snippet:
```haskell
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors #-}

data MyRecord = MyRecord
{ a :: String
, b :: Integer
} deriving (Eq, Show)

x :: MyRecord
x = MyRecord { a = "Hello", b = 12 }

y = x.a

z = x.b
```

HLS now understands (without record-dot-preprocessor!) that `y` is a `String` and `z` is an `Integer`, seen in both above-line hints and on hover.

Unfortunately, it has no type information available when hovering over the `a` in `x.a` or the `b` in `x.b`. Additionally, it lacks the ability to suggest- when entering a dot after a record type- the fields accessible on that type.

**Describe the solution you'd like**

The ability to "dot into" types is both a small form of IDE-driven API exploration and a way to easily manage larger applications without needing a Haddock window on the side at all times.

Pressing '.' after a type (or manually opening auto-completion with the cursor directly following a dot following a type) should summon auto-completion with the context narrowed to the prior type's fields.

For a step further, but one worth considering when designing a solution, a useful addition would be allowing automatic import of the type information required if necessary, similar to when accepting a completion of an unimported `trait` function in [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer/). Documentation on the HasField requirements is available [here (HasField constraints)](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/hasfield.html#solving-hasfield-constraints) and [here (OverloadedRecordDot)](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/overloaded_record_dot.html). `NoFieldSelectors` may complicate this functionality.

**Describe alternatives you've considered**

I've built my glue-code in Rust instead, so far, to avoid having to manage large numbers of one-off record types in Haskell, but I'd love to unify my codebase, and Record Dot Syntax has been the selling point that would get me there, assuming the presence of IDE support. It appears that 9.2.1 support is now functioning, but dot-accesses appear opaque to the language server.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue's GHC 9.2+ snippet in HLS and trace the existing type-awareness, hover, and completion entry points involved in OverloadedRecordDot. Read the linked GHC documentation on HasField constraints and OverloadedRecordDot first. Done means field hover information is available and dot completion lists fields for the preceding record type.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.