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
48.29k stars 2.87k forks source link

Editor auto-indents curly braces when typed under an if statement in C #13924

Open motherboardMage opened 3 months ago

motherboardMage commented 3 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

The issue:

Whenever I try to type in curly braces under an if statement in C, the Zed editor automatically adds an indent before them. I have turned code formatting off.

Steps to reproduce:

  1. Start typing an if statement
  2. Press enter / return to go to the next line
  3. Type the left curly bracket
  4. The editor should automatically add the right bracket and shift the entire thing one tab towards right

Screen recording of the issue and a screenshot of my config file are attached with this bug report

https://github.com/zed-industries/zed/assets/145113/4156d580-9f53-4d30-9455-0209f093a72f

Screenshot 2024-07-08 at 12 52 19 PM

Environment

Zed: v0.142.6 (Zed) OS: macOS 14.5.0 Memory: 8 GiB Architecture: x86_64

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.

N/A

notpeter commented 3 months ago

I can reproduce this issue. It looks like our tree-sitter indents.scm is pretty bare-bones for C:

https://github.com/zed-industries/zed/blob/275dd3fa819a7767270ca90346535b917e602eee/crates/languages/src/c/indents.scm#L1-L9

Perhaps we can incorporate nvim-treesitter/queries/c/indents.scm from neovim (Apache 2.0 License). Theirs correctly leaves the braces unindented.

motherboardMage commented 3 months ago

Hey, thank you, while I didn't understand most of what you said (because I'm quite new to computer science) but I'm glad I could help making Zed a little better. I have encountered another problem, perhaps in the same vein and I am yet to create an issue about it. Please look into it when I do. Thanks again

Louis-Ladd commented 1 week ago

Still having this issue as well on arch build of zed Has this been resolved?