gleam-lang/gleam

Extract record code action

開放

#4,406 建立於 2025年3月29日

 (1 則留言) (2 個反應) (0 位負責人)Rust (960 個分叉)batch import
help wanted

倉庫指標

星標
 (21,417 顆星)
PR 合併指標
 (平均合併 10天 19小時) (30 天內合併 69 個 PR)

描述

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.

貢獻者指南