-
-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Pattern match on argument" code action #4153
Conversation
kind: TodoKind::EmptyFunction, | ||
location: SrcSpan { start, end }, | ||
kind: TodoKind::EmptyFunction { | ||
function_location: SrcSpan { start, end } | ||
}, | ||
location: SrcSpan { | ||
start: left_brace_start + 1, | ||
end: right_brace_end | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously when the compiler inserted an implicit todo
in an empty function body it marked its position as starting at the start of the function declaration. This would mess up code actions that rely on a function's body's statement to always come inside the curly braces.
I found this out implementing the "Destructure argument" code action and changed it here so that an implicit todo now has the following span:
pub fn main() { }
// ^^ This span inside the function's body
// ^^^^^^^^^^^^^ Instead of this span outside the function's body
It still carries around the entire function span to produce nice error messages for incomplete code in the TodoKind::EmptyFunction
variant
.../snapshots/gleam_core__language_server__tests__action__destructure_argument_empty_tuple.snap
Outdated
Show resolved
Hide resolved
And add documentation to the relevant function explaining this behaviour
Instead of being called `value_0` it just uses `value` which looks way better when there's just a single unlabelled field: let Wibble(value) = arg // instead of let Wibble(value_0) = arg
21de198
to
3196ea3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic!
Does it work with anonymous functions? I could see it being useful there too.
Heck, are there other places it would be useful? Like let x =
?
previously if a type were internal the "pattern match on argument" code action would never trigger. However, one would want to do that if they're working in the same module where the type is defined
...m_core__language_server__tests__action__pattern_match_on_argument_works_on_fn_arguments.snap
Show resolved
Hide resolved
...m_core__language_server__tests__action__pattern_match_on_argument_works_on_fn_arguments.snap
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!
This PR closes #4139.
The tests cover loads of different cases but here's a small example of what it looks like in practice: