jinxdash / prettier-plugin-rust

Prettier Rust is an opinionated code formatter that autocorrects bad syntax.
MIT License
178 stars 7 forks source link

Insert extra symbol, error occurs. #11

Closed Chanyon closed 2 years ago

Chanyon commented 2 years ago

Input code

KeyEvent {
                code: code @ (KeyCode::Up | KeyCode::Down | KeyCode::Left | KeyCode::Right | KeyCode::End | KeyCode::Home),
                modifiers: event::KeyModifiers::NONE,
            } => {
                self.output.move_cursor(code);
            }

Output code

KeyEvent {
                code: code @ (
                    | KeyCode::Up
                    | KeyCode::Down
                    | KeyCode::Left
                    | KeyCode::Right
                    | KeyCode::End
                    | KeyCode::Home
                ),
                modifiers: event::KeyModifiers::NONE,
            } => {
                self.output.move_cursor(code);
            }

Additional context

Insert extra symbols after format.

bug .

jinxdash commented 2 years ago

It looks like rust-analyzer's custom parser does not support leading | in patterns. I filed an issue here. In the meantime I recommend removing the leading | and ignoring that code by placing // prettier-ignore above it.

jinxdash commented 2 years ago

This issue has been fixed in rust-analyzer. From what I understand the fix should be part of next week's release, or tomorrow if you use rust-analyzer nightly.