gleam-lang/gleam

Extract record code action

Open

#4.406 aberto em 29 de mar. de 2025

Ver no GitHub
 (1 comment) (2 reactions) (0 assignees)Rust (960 forks)batch import
help wanted

Métricas do repositório

Stars
 (21.417 stars)
Métricas de merge de PR
 (Mesclagem média 9d 23h) (58 fundiu PRs em 30d)

Description

Given a type definition, if some of the fields of one of the variants are selected then a code action if offered to extract them into a new custom type.

pub type NewsPost {
  NewsPost(
    title: String,
    subtitle: String,
    published: calendar.Date,
// Selection start
    author_name: String,
    author_url: String,
// Selection end
  )
}

Could become

pub type NewsPost {
  NewsPost(
    title: String,
    subtitle: String,
    published: calendar.Date,
    author: Author,
  )
}

pub type Author {
  Author(name: String, url: String)
}

Here I've gone for an idealised version that determines ideal names for the fields, but it would still be useful even if it is not able to do this. The original field labels and a placeholder type + variant name could be used.

Guia do colaborador