Skip to content
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

auto-insert semicolon in let-else statements #18651

Open
roife opened this issue Dec 9, 2024 · 3 comments
Open

auto-insert semicolon in let-else statements #18651

roife opened this issue Dec 9, 2024 · 3 comments
Assignees
Labels
A-ide general IDE features C-feature Category: feature request

Comments

@roife
Copy link
Member

roife commented Dec 9, 2024

It would be very convenient if the ; were automatically added when typing { in let-else statements; I often forget it. :)

let Some(x) = x else {|}

// ==>

let Some(x) = x else {|};
@roife roife added the C-feature Category: feature request label Dec 9, 2024
@roife roife self-assigned this Dec 9, 2024
@roife
Copy link
Member Author

roife commented Dec 9, 2024

I implemented this, and it works well in vscode!

But I found that in some editors (e.g. emacs), it conflicts with the editor's own bracket auto-pairing:

fn main() {
    let x = Some(0);
    let Some(x) = x else {| // insert { here
}

// ==>

fn main() {
    let x = Some(0);
    let Some(x) = x else {|
}; // the semicolon was inserted here :(

The } for fn is parsed to be paired with the preceding {.

@roife roife changed the title feat request: auto-insert semicolon in let-else statements auto-insert semicolon in let-else statements Dec 9, 2024
@roife roife added the A-ide general IDE features label Dec 10, 2024
@roife
Copy link
Member Author

roife commented Dec 10, 2024

Or we can add an assist, for let y| = x;, it can be split into let Enum::Variant(y|) = x else { };

@Veykril
Copy link
Member

Veykril commented Dec 10, 2024

Hmm that does sound tricky relying on bracket completion by the editor here. I don't think having a typing handler for that sounds good (I added a couple of things to the on typing handler recently and they all seemed to worsen the UX experience...).

An assist sounds reasonable, it would be in a similar vein to the other case splitting ideas I think? (just for let else, not if let / match)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants