Skip to content

Builtin Zed prettier does not respect zed "tab_width" options #20235

Closed as not planned
@ikelos

Description

@ikelos

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

The tab_size option is set to 4 by default (both globally and for javascript in particular) and the autoformatting on save is on by default. Open a Javascript file, ensure the indents are 4 spaces, save the file. The indents are changed to a tab size of 2. This is because the in-built prettier (allowed by default) has its own tab_width defaults, which are set to 2. This can be overridden in the zed config with:

{
    "languages": {
        "JavaScript": {
            "prettier": {
                "tab_width": 4
            }
        }
    }
}

However, this is extremely confusing and most users would expect tab_size at the top level, or at the language level to override the built-in prettier configuration.

This may be related to #12154 and #20009.

Environment

Zed: v0.159.7 (Zed)
OS: Linux Wayland gentoo 2.15
Memory: 15.3 GiB
Architecture: x86_64
GPU: Intel(R) UHD Graphics (TGL GT1) || Intel open-source Mesa driver || Mesa 24.2.6

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

In my view, javascript files, when saved by default, should adhere to the tab_width defaults of zed.

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

Not applicable, although when saving a broken JSON settings file, I discovered the following line:

2024-11-05T11:11:12.87589183Z [ERROR] default prettier instance failed to format buffer

Caused by:
    error during message '{"jsonrpc":"2.0","id":2,"method":"prettier/format","params":{"text":"..snip..","options":{"plugins":[],"parser":null,"filepath":"/home/mike/.config/zed/settings.json","prettierOptions":{"useTabs":false,"tabWidth":2,"printWidth":80}}}}' handling: SyntaxError: Unexpected token, expected "," (13:3)
      11 |   "buffer_font_size": 16,
      12 |   "tab_size": 4, "hard_tabs": false
    > 13 |   "theme": {
         |   ^
      14 |     "mode": "system",
      15 |     "light": "One Light",
      16 |     "dark": "One Dark"

Which caused me to investigate prettierOptions and eventually find that prettier has its own tab_width setting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug[core label]discoverabilityFeedback for discoverability of features, settings, etceditorFeedback for code editing, formatting, editor iterations, etcprettierPrettier tooling support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions