Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zed not respecting tab size when saving file #4842

Open
1 task done
OmerFlame opened this issue Apr 3, 2023 · 31 comments
Open
1 task done

Zed not respecting tab size when saving file #4842

OmerFlame opened this issue Apr 3, 2023 · 31 comments
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc reproducible Verified steps to reproduce included setting Feedback for preferences, configuration, etc

Comments

@OmerFlame
Copy link

Check for existing issues

  • 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

Screen.Recording.2023-04-03.at.19.48.33.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 OmerFlame added bug [core label] triage labels Apr 3, 2023
@JosephTLyons JosephTLyons added editor Feedback for code editing, formatting, editor iterations, etc setting Feedback for preferences, configuration, etc and removed triage labels Apr 3, 2023
@OmerFlame
Copy link
Author

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
Copy link
Author

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.

@mateusdeap
Copy link

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.

@gdevillele
Copy link

Experiencing the same issue with Lua files here.

My editor config:

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

@Aaron9812
Copy link

Same in TypeScript/tsx files. My config

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

@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@jfoscarini
Copy link

jfoscarini commented Jan 28, 2024

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

"format_on_save": "off"

@fanckush
Copy link

fanckush commented Feb 6, 2024

same in .vue files

@Erlendms
Copy link

Erlendms commented Feb 6, 2024

Same in .css files.

@andisulistyonugroho
Copy link

andisulistyonugroho commented Feb 7, 2024

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 } } }

@invaderb
Copy link

invaderb commented Feb 23, 2024

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

@slice-amandata
Copy link

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

@DeVoresyah
Copy link

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
    }
  }

@spnda
Copy link

spnda commented Feb 27, 2024

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
        }
    }

@otaliptus
Copy link

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.

@gttotev
Copy link

gttotev commented Mar 7, 2024

@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.

@grvm
Copy link

grvm commented Mar 27, 2024

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

tab_spaces = 2

And that fixed it!

@tommydangerous
Copy link

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!

@motherboardMage
Copy link

motherboardMage commented Jul 10, 2024

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

@louisnw01
Copy link

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
Copy link

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

{
    "tabWidth": 4
}

@PeterFalken
Copy link

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.

@louisnw01
Copy link

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?

@PeterFalken
Copy link

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

@louisnw01
Copy link

@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

@PeterFalken
Copy link

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"}

@Ptitet
Copy link

Ptitet commented Sep 10, 2024

I'm working in TypeScript with Zed v0.152.3.
format_on_save seems not to be working, whatever value I put.
The action editor::format does not respect the tab_size defined in my general config nor the on in my TypeScript language override.

@Tem3dy
Copy link

Tem3dy commented Jan 14, 2025

What the hell are the devs doing that this hasn't been fixed yet?

@Tem3dy
Copy link

Tem3dy commented Jan 14, 2025

I also noticed that Zed fails to respect the tab size when coding and making a new line for example in a function.

I've had this situation that I don't know how to reproduce multiple times, where if you enter a new line, the editor doesn't insert the tab at the correct set amount in the settings, for example it only inserts 3 spaces instead of 4, or 2 instead of 4 or whatever the value is in the config, if someone noticed something similar and knows how to reproduce, it would be worth sharing here

@dmitry-kabanov
Copy link

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

{
    "tabWidth": 4
}

Fixed for me as well. This means that the documentation for JavaScript is incorrect:

Formatting on save is enabled by default for JavaScript, using TypeScript's built-in code formatting. But many JavaScript projects use other command-line code-formatting tools, such as Prettier.

I have just installed Zed and did not change any formatting settings. Apparently, Prettier is used for format-on-save instead of the TypeScript server.

@Parth589
Copy link

in c++, zed uses clangd to format the source files. so you can add a .clang-format file to configure the indents. source . i used this method because "tab_size": 4 didnt work for me.

@devzeth
Copy link
Member

devzeth commented Feb 20, 2025

The issue described in the first post is not something I can reproduce, however the one from @motherboardMage I can.

{
    "ui_font_size": 16,
    "buffer_font_size": 16,
    "hard_tabs": true, // true or false doesn't change anything
    "tab_size": 4,
    "indent_size": 4,
    "languages": {
        "C": {
            "format_on_save": "on", // <== culprit
            "indent_size": 4

        }
    }
}
int bruh() {
	int test;
	int test2;

	return 0;
}

I'm not sure but it seems like we don't pass any of the options provided for C or C++ (same code).
Reproducible in Zed Prev 175.1

@devzeth devzeth added the reproducible Verified steps to reproduce included label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc reproducible Verified steps to reproduce included setting Feedback for preferences, configuration, etc
Projects
None yet
Development

No branches or pull requests