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

VS Code's indentation settings aren't overridden #1859

Open
thorn0 opened this issue Mar 18, 2021 · 5 comments
Open

VS Code's indentation settings aren't overridden #1859

thorn0 opened this issue Mar 18, 2021 · 5 comments
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.

Comments

@thorn0
Copy link
Member

thorn0 commented Mar 18, 2021

Summary

This was discussed in #1515 (comment) and turned out to be a separate issue.

Steps To Reproduce:

  1. create an empty directory
  2. create .prettierrc in it, with this content: {"tabWidth": 2}
  3. create an empty index.js

Expected result

When I open the empty file,

  • I should see "Spaces: 2" in the status bar
  • Tab should insert 2 spaces

Actual result

When I opened this directory in VS Code and opened index.js, I saw "Spaces: 4" in the status bar. Pressing the Tab key inserted 4 spaces. After adding some code with indentation to this file, formatting it with Prettier (it got correctly indented with 2 spaces), closing, and opening the file again, VS Code's autodetection worked (as editor.detectIndentation is true by default) and this time correctly showed "Spaces: 2" in the status bar, the Tab key started to work as expected too.

Additional information

For my tests, I disabled other extensions that could affect this. In particular, EditorConfig and ESLint.

The EditorConfig extension doesn't have this problem. It changes the behavior of VS Code even in empty files.

#1327 might be related (the extension seems to fail to override VS Code's behavior in that case too).

VS Code Version:

1.54.3

Prettier Extension Version:

6.3.1

OS and version:

Windows 10 x64 20H2

@ntotten
Copy link
Member

ntotten commented Mar 18, 2021

I'm not sure we can change that. AFAIK there isn't an API to change that in the editor besides writing the setting, but I am not comfortable overwriting settings on behalf of a user.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jun 18, 2021

Considering this is the behaviour out of the box, it could be quite confusing to new users.

The steps to reproduce can be simplified even more:

  1. Create a new directory and open VS Code with default settings and no extensions to simulate a new user: code --user-data-dir data --extensions-dir data-extensions .
  2. Install the Prettier extension
  3. Create a JS file

To fix this I think the Prettier extension would need to override the editor.tabSize setting. I think the user would always want the editor setting to match their formatter.

@phoenixeliot
Copy link

I'm not sure we can change that. AFAIK there isn't an API to change that in the editor besides writing the setting, but I am not comfortable overwriting settings on behalf of a user.

I think this could potentially be solved with a little alert bubble, asking the user if they want to set their workspace tab setting to match their prettier config, if the extension detects that there is a prettier config and that it doesn't match the setting

@ntotten ntotten added the help-wanted Not something we plan on doing, but we will take a pull request. label Aug 20, 2022
@long76
Copy link

long76 commented Apr 7, 2023

up vote

@danielniccoli
Copy link

I just ran into the same problem and it took me a long time to find this issue.

I'm not sure we can change that. AFAIK there isn't an API to change that in the editor besides writing the setting, but I am not comfortable overwriting settings on behalf of a user.

So, do i understand correctly that in VS Code the tabWidth setting in .prettierrc has no effect and the VS Code config takes precedence? And you are saying that you are not comfortable overriding the VS Code setting with the .prettierrc setting?

What confused me was the following:

All prettier options can be configured directly in this extension. These settings are used as a fallback when no configuration file is present in your project, see the [configuration](#configuration) section of this document for more details. For reference on the options see the [prettier documentation](https://prettier.io/docs/en/options.html).

My understanding of that sentence is that the precedence is in the following order:

  1. tabWidth in .prettierrc
  2. prettier.tabWidth in .vscode/settings.json
  3. editor.tabSize in .vscode/settings.json

This is very confusing.

If you set only 1. and neither of 2. and 3. then the behaviour seems completely arbitrary. Files that already have a tabSize of 4 stay like that. Files with a tabsize of 2 also stay like that. And sometimes new files get formatted with either one.

Maybe it would help clarifying the current behaviour? It definitely would help me understand, what I must configure to reliably have a tab size of 4 spaces, that also gets applied with certainty when I paste code with a tabsize of 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.
6 participants