zed icon indicating copy to clipboard operation
zed copied to clipboard

Zed not respecting tab size when saving file

Open OmerFlame opened this issue 1 year ago • 17 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

When saving, Zed just doesn't respect the tab size that was set in the settings. (Settings and demo of the issue provided in the attached screen recording)

Environment

Zed: v0.79.1 (stable) OS: macOS 13.3.0 Memory: 16 GiB Architecture: aarch64

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

https://user-images.githubusercontent.com/17903236/229575342-cce95708-0c86-44a3-87ef-db93bbe93131.mov

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.

log.txt

OmerFlame avatar Apr 03 '23 16:04 OmerFlame

Any ETA on when this will be fixed? This is a pretty serious issue, my whole project is working on a specific tab size...

OmerFlame avatar Apr 09 '23 19:04 OmerFlame

UPDATE: I can confirm that this only seems to happen in C/C++ source and header files. This behavior doesn't seem to happen on Rust/Python/JavaScript. This seems to me like clangd formats the code regardless of the tab size given in Zed's settings.

OmerFlame avatar Apr 10 '23 15:04 OmerFlame

Same issue here. I even tried figuring out how to configure clangd but I think that if it's always using the LSP, it'd be good to have a way to configure clangd in the editor itself.

There does seem to be that possibility, but I'm unsure on how to configure formatting since the docs only cite initialization options.

mateusdeap avatar Aug 21 '23 10:08 mateusdeap

Experiencing the same issue with Lua files here.

My editor config:

{
    "buffer_font_size": 15,
    "tab_size": 4,
    "hard_tabs": true
}

gdevillele avatar Nov 27 '23 08:11 gdevillele

Same in TypeScript/tsx files. My config

{ "base_keymap": "VSCode", "theme": "Rosé Pine", "buffer_font_size": 15, "autosave": "on_focus_change", "tab_size": 4 }

Aaron9812 avatar Nov 29 '23 15:11 Aaron9812

For the time being, consider setting format_on_save to off in your configuration file.

"format_on_save": "off"

jfoscarini avatar Jan 28 '24 18:01 jfoscarini

same in .vue files

fanckush avatar Feb 06 '24 10:02 fanckush

Same in .css files.

Erlendms avatar Feb 06 '24 21:02 Erlendms

same in .vue files

for .vue files I put this configuration in .zed/settings.json (local settings), now it is working as expected

{ "languages": { "Vue.js": { "tab_size": 2 } } }

andisulistyonugroho avatar Feb 07 '24 01:02 andisulistyonugroho

I really like the format on save but doing the same thing for me

"autosave": {
        "after_delay": {
            "milliseconds": 3000
        }
    },
    "format_on_save": "on",
    "hard_tabs": true,
    "tab_size": 4,
    "language_overrides": {
        "TypeScript": {
            "tab_size": 4,
            "hard_tabs": true
        },
        "JSON": {
            "tab_size": 4,
            "hard_tabs": true
        }
    },

doing the language overrides didn't seem to help

invaderb avatar Feb 23 '24 20:02 invaderb

C++ tab size : 4 and hard_tabs : true doesn't seems to be working

slice-amandata avatar Feb 26 '24 09:02 slice-amandata

I'm using this config to fix it:

  "language_overrides": {
    "Vue.js": {
      "tab_size": 2,
      "hard_tabs": true
    },
    "TypeScript": {
      "tab_size": 2,
      "hard_tabs": true
    },
    "JSON": {
      "tab_size": 2,
      "hard_tabs": true
    }
  }

DeVoresyah avatar Feb 27 '24 10:02 DeVoresyah

On 0.123.6 using language overrides does not fix the issue with C++:

    "hard_tabs": true,
    "tab_size": 4,
    "format_on_save": "on",
    "language_overrides": {
        "C++": {
            "hard_tabs": true,
            "tab_size": 4
        }
    }

spnda avatar Feb 27 '24 14:02 spnda

Can confirm that this persists for C++ even if you put language overrides & tab-size related settings. Other languages are fine when you fix your config with override.

otaliptus avatar Mar 01 '24 07:03 otaliptus

@OmerFlame It seems formatting is handled by the clangd language server. You can instruct it to use 4 spaces by creating a .clang-format file in the same directory containing:

IndentWidth: 4

(see https://clang.llvm.org/docs/ClangFormatStyleOptions.html)

This is a workaround however; it would be nice to see support for configuring the language server formatter integrated into Zed itself.

gttotev avatar Mar 07 '24 00:03 gttotev

For Rust, it was definitely rustfmt overriding the editor settings. Created $HOME/.rustfmt.toml, added a line

tab_spaces = 2

And that fixed it!

grvm avatar Mar 27 '24 17:03 grvm

I really like the format on save but doing the same thing for me

"autosave": {
        "after_delay": {
            "milliseconds": 3000
        }
    },
    "format_on_save": "on",
    "hard_tabs": true,
    "tab_size": 4,
    "language_overrides": {
        "TypeScript": {
            "tab_size": 4,
            "hard_tabs": true
        },
        "JSON": {
            "tab_size": 4,
            "hard_tabs": true
        }
    },

doing the language overrides didn't seem to help

OMG this is super useful, thank you!

tommydangerous avatar May 06 '24 23:05 tommydangerous

The issue still has not been fixed. I have turned off format on save and am currently using artistic style to format my C files after I'm done coding.

Here's a screen recording of the issue on my machine:

https://github.com/zed-industries/zed/assets/170600677/8e29866b-22bb-4722-a850-9bd006786471

VSCode's auto formatter looks very similar to artistic style. Would it be possible to somehow integrate astyle into the editor itself?

Edit: I have also tried setting the indent_size property to 40 as the default setting was 20 on my installation but it did not affect the outcome at all.

My environment:

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

motherboardMage avatar Jul 10 '24 05:07 motherboardMage

The issue still has not been fixed. I have turned off format on save and am currently using artistic style to format my C files after I'm done coding.

Here's a screen recording of the issue on my machine:

Screen.Recording.2024-07-10.at.9.46.08.AM.mov

VSCode's auto formatter looks very similar to artistic style. Would it be possible to somehow integrate astyle into the editor itself?

Edit: I have also tried setting the indent_size property to 40 as the default setting was 20 on my installation but it did not affect the outcome at all.

My environment:

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

I'm getting the exact same behavior with TSX and TypeScript files. Any solution to this?

louisnw01 avatar Jul 26 '24 11:07 louisnw01

I was able to fix this by adding a .prettierrc file to the root of my project containing:

{
    "tabWidth": 4
}

louisnw01 avatar Jul 26 '24 22:07 louisnw01

I was able to fix this by adding a .prettierrc file to the root of my project containing:

{
    "tabWidth": 4
}

I tried this with a YAML file but with a "tabWidth": 2 value and it didn't work.

PeterFalken avatar Jul 27 '24 01:07 PeterFalken

I was able to fix this by adding a .prettierrc file to the root of my project containing:

{

"tabWidth": 4

}

I tried this with a YAML file but with a "tabWidth": 2 value and it didn't work.

What does it say the language server logs for prettier?

louisnw01 avatar Jul 27 '24 08:07 louisnw01

@louisnw01 , how do I check the server logs for prettier?

PeterFalken avatar Jul 27 '24 14:07 PeterFalken

@louisnw01 , how do I check the server logs for prettier?

cmd+shift+p, open language server logs, click the xxx () - Server Logs in the top left, then click on the one which says prettier, you should be able to see them then

louisnw01 avatar Jul 27 '24 14:07 louisnw01

This is what I got on the logs after saving. It is still using 4 spaces instead of 2. stderr: Resolved config: {"tabWidth":2}, will format file '~/HomePage/bookmarks.yaml' with options: {"useTabs":false,"tabWidth":2,"printWidth":80,"plugins":[],"parser":null,"filepath":"~/HomePage/bookmarks.yaml"}

PeterFalken avatar Jul 27 '24 16:07 PeterFalken