Skip to content

Vertically align record and discriminated union type annotations #500

Open
@reinux

Description

@reinux

Description

It would be nice if record and DU fields could be vertically aligned, or at least kept vertically aligned if they already are, both in the type definition as well as in instantiation, if that's possible.

Currently,

type Person = {
    id          : ID
    name        : string
    age         : int
    nationality : Nation option
    likesPho    : bool
}

let rei = {
    id          = newID()
    name        = "rei"
    age         = 33
    nationality = Some (Nations.Japan)
    likesPho    = true
}

Becomes

type Person =
    { id : ID
      name : string
      age : int
      nationality : Nation option
      likesPho : bool }

let rei =
    { id = newID()
      name = "rei"
      age = 33
      nationality = Some(Nations.Japan)
      likesPho = true }

But it would be nice if it would retain the spacing, maybe keeping the = and : (and of for DUs) aligned with a space or tab after the longest name.

Something similar with DUs and pattern matching would be nice too, so that this spacing is maintained:

type WindowState<'model> =
  | Closed
  | Hidden  of 'model
  | Visible of 'model

let map (f: 'a -> 'b) (state: WindowState<'a>) =
  match state with
  | Closed    -> Closed
  | Hidden m  -> Hidden (f m)
  | Visible m -> Visible (f m)

I find this really improves readability, even though it can be a bit of a pain to do manually.

I suspect this could also apply to any situation where each line in, say, a list comprehension, contains a single expression with a repeating pattern of operators, but that's certainly not trivial to implement. Even just handling the cases where the operator is prescribed by the syntactical context would be awesome.

Repro code

Link

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions