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

Last indent level converted to spaces (.clang-format set to UseTab: Always) #3172

Closed
daravi opened this issue Feb 14, 2019 · 6 comments
Closed

Comments

@daravi
Copy link

daravi commented Feb 14, 2019

Type: LanguageService

I am using "C_Cpp.Clang_format_style": "file" to specify my custom formatting. Here is my .clang-format file content:

BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4

However, when formatting, vs-code converts the last indentation level to spaces. For example if I have 4 indentation levels the fourth one is converted to spaces. I have set detectIndentation and insertSpaces to false.

Describe the bug

  • OS and Version: MacOS 10.13.6
  • VS Code Version: 1.31.1
  • C/C++ Extension Version: 0.21.0
  • Description of what the bug is: Last indent level is converted to spaces on formatting (.clang-format file defines UseTab: Always)

To Reproduce

1- Set "C_Cpp.Clang_format_style" to "file"
2- Create a .clang-format file in project root:

BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4

3- Attempt to format a file

Expected behavior
All indentation levels must be tabs.

Additional context
Please note that when I select Tab Size > Convert Indentation to Tabs all levels are converted to tabs as expected. But after reformatting the file the last level is turned back to spaces.

Resources
https://clang.llvm.org/docs/ClangFormatStyleOptions.html

@daravi
Copy link
Author

daravi commented Feb 14, 2019

I think this might be a convenience feature of vscode and not an actual case of space-indentation.

@daravi daravi closed this as completed Feb 14, 2019
@Tronic
Copy link

Tronic commented Apr 5, 2020

Could you elaborate on how is this a convenience feature? I have VSCode and clang-format both set to use tabs, and yet every time I paste, the last level of surrounding code gets indented by spaces.

It would be convenient if clang-format followed VSCode indent setting without even requiring separate
indentation settings there.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 6, 2020

@Tronic I'm not able to repro this issue, although I used

BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4

If someone can provide a specific code example that might help.

@Tronic
Copy link

Tronic commented Apr 8, 2020

@sean-mcmanus Missing TabWidth seemed to be causing this. It would make sense for UseTab, IndentWidth and TabWidth all to follow the indentation choice made in VS Code, but at least manually configuring avoids the paste misformat issue. Thanks!

@sean-mcmanus
Copy link
Contributor

@Tronic When the default "Visual Studio" style is used, we do inherit the VS Code tab/indent-related settings, but when a .clang-format file is used, we don't do anything to change that, because clang-format itself reads the .clang-format directly. Theoretically we could read/parse/modify the .clang-format ourselves and stop sending "file" to clang-format.

This issue #657 is related (although it morphed into a different issue).

@daravi
Copy link
Author

daravi commented Apr 11, 2020

Could you elaborate on how is this a convenience feature?

@Tronic Sorry I missed your question. I don't remember tbh since this was a while back. But I think at least at that time I had come to the conclusion that the editor was showing the last indent level as spaces but it was only for ease of navigation and not actual tab characters.
I might be remembering incorrectly or have been wrong about what vscode was doing, but it seems that your issue is resolved so cheers!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants