zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
42.09k stars 2.2k forks source link

Ruby auto indentation is inconsistent #4479

Open willcosgrove opened 10 months ago

willcosgrove commented 10 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I run into indentation issues when writing Ruby in Zed on a consistent basis. Most commonly, I encounter it when I'm in an if..end block. But I also notice it when I'm creating a new ruby file and there isn't a full module/class structure defined yet.

From an empty ruby file, define a method and insert a new line. I would expect the cursor to be indented one level, but it is at the top level.

https://github.com/zed-industries/community/assets/77887/5d7fa8cd-7d1b-49c4-a63e-18e3a5323c31

From an empty ruby file, begin an if block and insert a new line. I would again expect the cursor to be indented one level, but it is not. And neither are subsequent lines.

https://github.com/zed-industries/community/assets/77887/1da5c63f-e998-4d1a-a6af-8ba5830c610f

This last example has a more typical file structure, the code is written inside a complete class definition. Define a method, insert new line, it is correctly indented an additional level. Write an if condition and insert a new line and the indentation does not change. I would expect it to be indented an additional level. You can also see that the editors understanding of the file hierarchy breaks as soon as the if is written.

https://github.com/zed-industries/community/assets/77887/e157f707-6c73-4e1d-90a4-fc92a8b32ac8

Thanks, let me know if I can provide any more info!

PS: This seems related to zed-industries/zed#5116 but that issue seemed stale. I could not reproduce the bug in that issue's example so it's possible it was fixed but never closed.

Environment

Zed: v0.103.1 (preview) OS: macOS 13.5.0 Memory: 64 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

No response

richkilmer commented 3 months ago

I am going to comment on in this that this issue is THE worst part of my daily use of Zed which I have not been doing for the last 4-5 months. When you type in: if condition then press enter and type in else it de-indents it. I constantly have to fight this autoformatting issue every time. Its been such a common thing my fingers automatically fix the incorrect formatting but it would be great if this could be addressed. if / else / end should all be at the same indent level. The line after if should be indented and its not.

joeldrapper commented 1 month ago

@richkilmer the issue you mentioned seems to be fixed now, but the other inconsistencies are still present.

https://github.com/zed-industries/zed/assets/246692/07d43e75-a19f-43c5-8f1a-3472d69a3470