zed icon indicating copy to clipboard operation
zed copied to clipboard

format_on_save is ignored when saving a remote YAML file

Open jerinjoy opened this issue 11 months ago • 9 comments

Check for existing issues

  • [x] Completed

Describe the bug / provide steps to reproduce it

When saving a YAML file on a remote server after making edits, Zed will auto indent the file. I've set:

  "format_on_save": "off",

but it still indents the file.

This doesn't appear to occur if I'm editing the same file locally.

Example YAML: https://raw.githubusercontent.com/rivosinc/JumpStart/refs/heads/main/src/public/jumpstart_public_source_attributes.yaml

Zed Version and System Specs

Zed: v0.169.3 (Zed) OS: macOS 15.1.1 Memory: 16 GiB Architecture: aarch64

If applicable, add screenshots or screencasts of the incorrect state / behavior

Before Saving: Image

After Saving: Image

If applicable, attach your Zed.log file to this issue.

Zed.log

Zed.log

jerinjoy avatar Jan 22 '25 20:01 jerinjoy

I encountered the problem where it doesn't really respect the "tab_size" value for remote.

Exactly as shown in the screenshot, on remote it uses 4 spaces instead of 2 while locally it respect that.

canidam avatar Feb 03 '25 18:02 canidam

is there any way to configure a custom command that is getting invoked for formatting? Then I could call dprint for yaml files.

Right now there seems no workaround. :(

sassman avatar Feb 25 '25 08:02 sassman

I think this is a regression? I'm also experience it on 0.175.6 and I thought I had it properly disabled before. I also can't seem to disable format_on_save for toml files (i.e. Cargo.toml).

strtok avatar Feb 28 '25 15:02 strtok

Related: I can't turn off the auto formatter for HTML. My indentation and certain line breaks are removed / reformatted. With this setting I exact the file to save exactly as it is without processing.

Zed 0.176.1: 121bd97cb189d272c746e04b8d15d188ffe346c5

Settings { "format_on_save": "off", "languages": { "HTML": { "tab_size": 4, "format_on_save": "off" } },

wesort avatar Mar 04 '25 16:03 wesort

Here's a video of this in action:

https://github.com/user-attachments/assets/67e7b935-a289-4259-b2c7-5de8976275d0

wesort avatar Mar 04 '25 17:03 wesort

I was experiencing the same problem with YAML files being auto formatted (even with format_on_save: false) with $4$ spaces, even with tab_size: 2 for YAML language specifically.

I've discovered that there is a server settings file, which can be seem bellow:

Image

If I set the proper configs in this file, the formatter respects it. But seems like a bug indeed, if no values are set in this file, the user settings in the host should be used.

Specs: Zed: v0.176.3 (Zed) OS: macOS 14.7.3 Memory: 16 GiB Architecture: aarch64

paulora2405 avatar Mar 10 '25 10:03 paulora2405

Thanks @paulora2405 - Unfortunately for me that isn't resolving it.

BTW, this issue isn't present on every remote server I'm using Zed with.

My workaround currently is to use cmd+k s but it's really hard/annoying to break my cmd+s muscle memory. I tried to remap the key binding for cmd+s to be cmd+k s but that didn't work either.

wesort avatar Mar 10 '25 16:03 wesort

Also altering the behavior of the formatting doesn't work as well.

e.g.

"languages": { 
    "YAML": { 
      "tab_size": 2, 
   }
}

has no effect. Nor does selecting an external formatter such as YQ.

rrichardson avatar May 31 '25 03:05 rrichardson

One other data point:

I change the file type to "Plain Text" in the bottom right corner of the editing window, and it still formats the YAML to 4 spaces. This makes the IDE completely unusable for me for YAML files.

rrichardson avatar Jun 04 '25 16:06 rrichardson

This is happening on JSON and YAML for me but only on a remote. As others have mentioned setting the tab_size for the languages doesn't work.

theelderbeever avatar Jun 09 '25 20:06 theelderbeever

Having the same issue. However the workaround above from paulora2405 worked for me.

Took a while however to figure this out.

LeoLionel avatar Jun 10 '25 23:06 LeoLionel

Anecdotal evidence but this seems to be a problem on remotes where the zed editor is installed too. If you remove the installed editor and just do remote it seems like the issue goes away.

Tested with Remote Ubuntu machine and MacOS client

  1. Was having problem when Ubuntu had the editor installed.
  2. Ran zed --uninstall on remote
  3. Tried remote again WITH the server settings setting the tab_size
  4. Seems fixed?

theelderbeever avatar Jun 12 '25 18:06 theelderbeever

Managed to fix it for myself by creating ~/.config/zed/settings.json on remote, with tab_size: 2. Changing local settings.json file doesn't seem to have any effect.

I suppose this also fixes lots of other similar bugs, such as remote LSP configuration.

glassbeads avatar Jun 26 '25 11:06 glassbeads

I'm getting a similar issue. I have a Mac client and a remote Fedora Linux server. When I save using the remote flow it indents files like .json, .toml, and others incorrectly. When I develop locally on the Mac or locally on the Linux server it indents correctly. It has something to do with the remote flow.

For additional context: I'm on Zed Preview 0.195.1. I deleted settings.json on both machines. Issue still persists.

spencerbart avatar Jul 15 '25 17:07 spencerbart

I'm getting a similar issue. I have a Mac client and a remote Fedora Linux server. When I save using the remote flow it indents files like .json, .toml, and others incorrectly. When I develop locally on the Mac or locally on the Linux server it indents correctly. It has something to do with the remote flow.

For additional context: I'm on Zed Preview 0.195.1. I deleted settings.json on both machines. Issue still persists.

Have you tried making local and remote settings.json files identical?

glassbeads avatar Jul 15 '25 18:07 glassbeads

Have you tried making local and remote settings.json files identical?

Yeah

I deleted settings.json on both machines.

They both bootstrapped to an empty settings.json.

The main thing that tells me this is a bug is that saving locally on my Mac formats correctly, saving locally on my Linux machine formats correctly, but saving while remoted in from the Mac to the Linux machine formats incorrectly.

spencerbart avatar Jul 16 '25 15:07 spencerbart

Managed to fix it for myself by creating ~/.config/zed/settings.json on remote, with tab_size: 2. Changing local settings.json file doesn't seem to have any effect.

I suppose this also fixes lots of other similar bugs, such as remote LSP configuration.

I experienced same issue while editing rust files on remote, local settings did not have any effect, drove me nuts for few hours. Finally managed to fix it by creating settings file on remote.

Interestingly format_on_save setting in the project setting file also did not have any effect, which means server settings override it?!

manV avatar Aug 22 '25 07:08 manV

The real problem is that remote sessions have settings differing from the client.

Have you tried making local and remote settings.json files identical?

It's hard to see for me how that's a sensible default. Nobody expects or wants that?

mstarodub avatar Aug 22 '25 11:08 mstarodub