Inject match arms sorted by "truthy" value first when running add missing patterns
code action
#3903
JosephTLyons
started this conversation in
Ideas & suggestions
Replies: 3 comments
-
What about adding them in the same order as they are defined? |
Beta Was this translation helpful? Give feedback.
0 replies
-
That would be nice! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hello! I'm not sure what the goal is with this item of work. What problems would you say this solves? For the given examples I think you could just as easily argue in the other direction. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, when running
add missing patterns
, forResult
andBool
, "falsy" values are always injected first.It seems like there are two groups of people here. The first group dynamically adjusts the order here based on what follows in the bodies of each arm (shorter path first), the second group always uses the same order. For the first group, no default ordering is going to work all the time, if they are always changing it depending on context, but for the second group, and for people coming from other languages, I believe many are used to the "truthy" values being first. For instance, coming from Rust, their default ordering when running the language server action is:
I think for built-in Gleam types that have a finite number of options, the language server could sort these to be "truthy" first - "hardcoded." For custom types, it could fallback to the current behavior, as the language server wouldn't have any context on how to sort those.
I find myself reordering these patterns frequently after using the actions. While preferences vary, I think a good chunk of Gleam users might come from Rust. Using Rust's output as an example sort of highlights the fact that these newer Gleam users might also be surprised by the current behavior here.
Note that there might be other built-in types that this would make sense for too,
Bool
andResult
are just the ones I hit frequently.Beta Was this translation helpful? Give feedback.
All reactions