gleam-lang/gleam

"Split alternative pattern" code action

Open

#4856 opened on Aug 16, 2025

View on GitHub
 (6 comments) (5 reactions) (0 assignees)Rust (21,417 stars) (960 forks)batch import
help wanted

Description

Sometimes code starts out as dealing with 2 patterns in the same way, but then later, something different has to happen for one or all of the cases. It could be nice if the language server provided a code action to split an alternative pattern into individual pattern matches.

Before:

case next() {
  Ok(response) -> response
  Error(MissingAccessToken) | Error(MissingRefreshToken) -> unauthorized()
  //  ^ split alternative patterns
}

After:

case next() {
  Ok(response) -> response
  Error(MissingAccessToken) -> unauthorized()
  Error(MissingRefreshToken) -> unauthorized()
}

To consider:

  • split The pattern on the selected pipe; That would make it more flexible, but would require more clicks to fully split a pattern.
  • Split out only the currently hovered alternative, leaving the rest in place

~ 💜

Contributor guide