Open Warkanlock opened 6 months ago
@Warkanlock I can't reproduce this. I did observe some similar behavior around the time of this report where format_on_save
was losing my file content, but haven't seen it in a few months.
Can you see if you are still experiencing thing scary behavior?
@Warkanlock I can't reproduce this. I did observe some similar behavior around the time of this report where
format_on_save
was losing my file content, but haven't seen it in a few months.Can you see if you are still experiencing thing scary behavior?
Might it be solved on the latest versions of Zed? I've not used Zed anymore for C programming, given this issue, so I cannot confirm nor deny that this keeps happening
@notpeter I think this problem still persists. This is my config:
{
"telemetry": {
"diagnostics": true,
"metrics": false
},
"theme": "Kanagawa Wave",
"vim_mode": true,
"ui_font_size": 16,
"font_family": "Fira Mono",
"buffer_font_family": "Fira Mono",
"buffer_font_size": 16,
"autosave": "on_focus_change",
"relative_line_numbers": true,
"project_panel": {
"dock": "right",
"git_status": true
},
"terminal": {
"font_family": "Fira Mono",
"blinking": "on"
},
"preferred_line_length": 180,
"languages": {
"C++": {
"tab_size": 4,
"formatter": {
"external": {
"command": "clang-format",
"arguments": ["{buffer_path}"]
}
},
"format_on_save": "on"
}
}
}
MacBook M1 - macOS Sonoma 14.5 - Zed 0.143.7
Whenever I delete any line and press escape to :w
, the code just reappears.
https://github.com/user-attachments/assets/637b7aba-39eb-40d1-ac5a-129bd2fb385e
I went back to my configuration file after reading this thread since I opened a long time ago, and something that fixed the issue for me was to disable the format_on_save
...
"C": {
"show_copilot_suggestions": true,
"formatter": {
"external": {
"command": "clang-format",
"arguments": ["{buffer_path}"]
}
},
"format_on_save": "off"
}
...
Using this configuration chunk now essentially I can use Zed as part of the workflow; however, I need to run the format
command every time I wanna use clang-format
(which is not a big deal, honestly)
Thanks for quick response.
Disabling format_on_save
worked for me. I've also added a quick keymap for this one.
I agree it's not a priority, rather a good feature to have. It would be great if you could add a message or a quick note about clang-format
in documentation.
Thank you once again for what you're doing. Switched fully to zed and enjoy it on a daily basis !
This issue might not be related to only clang-format
. It also occurs when using GNU Indent as the external formatter for C.
Here is a snippet of my Zed configuration.
"languages": {
"C": {
"formatter": {
"external": {
"command": "indent",
"arguments": [ "{buffer_path}", "-linux", "-nut", "-i4", "-o", "/dev/stdout" ]
}
}
}
}
A short summary of the arguments:
-linux
: same styling as code in the Linux kernel-nut
and -i4
: indentation with 4 spaces-o /dev/stdout
: output to stdoutZed: 0.143.6 (via DNF, Terra) OS: Fedora 40 with Linux 6.9.8 Memory: 32GB Architecture: x86_64 (AMD)
I've read the Zed documentation again. Using {buffer_path}
is not intended, instead stdin should be used.
"languages": {
"C": {
"formatter": {
"external": {
"command": "indent",
"arguments": [ "-", "-linux", "-nut", "-i4", "-o", "/dev/stdout" ]
}
}
}
}
Replacing {buffer_path}
with -
fixes the issue with format_on_save
.
~Using /dev/stdin
instead of -
doesn't work. (#14716)~ It does.
This works for clang-format:
"languages": {
"C": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "bash",
"arguments": ["-c", "clang-format"]
}
}
}
},
Check for existing issues
Describe the bug / provide steps to reproduce it
After setting a language configuration for C code in
languages
my code, after being saved, is replaced with the latest N-1 step previously done on the editor.For example:
struct
definition.struct,
together with a summary comment.This is the configuration used (utilizing
clang-format
as default):Turning
format_on_save
tooff
solves the issue, but I need to manuallysave > format
workflow.Environment
Zed: v0.123.6 (Zed) OS: macOS 14.3.1 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
With
format_on_save: on
https://github.com/zed-industries/zed/assets/145113/0d044fd9-33ab-4019-8d24-57d2c3e683de
With
format_on_save: off
https://github.com/zed-industries/zed/assets/145113/0c5509e3-6f41-490f-b98d-6c81b30e8608