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

Formatting breaks after certain nesting level for tab indentation #630

Closed
alexdima opened this issue Apr 11, 2017 · 10 comments
Closed

Formatting breaks after certain nesting level for tab indentation #630

alexdima opened this issue Apr 11, 2017 · 10 comments

Comments

@alexdima
Copy link
Member

Moved from microsoft/vscode#24485
From @slaiyer


  • VSCode Version: 1.11.1
  • OS Version: Windows 10 64-bit

Steps to reproduce:

  1. Convert to/use tab indentation
  2. Save or perform auto-format with "editor.formatOnSave": true and/or "C_Cpp.clang_format_formatOnSave": true

Tab indentation example (indentation is forcibly replaced with spaces when Step 2 is performed):
image

Space indentation example (missing indentation guides reappear when zoom level is brought back up):
image

It appears as though indentation levels reset (in a way) after 4 nesting levels, but only for tab indentation.

I have tried without success:

  • Changing the line endings
  • Disabling any extensions not installed by default
@sean-mcmanus
Copy link
Contributor

@slaiyer The blank rendering with editor.renderIndentGuides seems like a bug with VS Code that is fixed with 1.12.0-Insiders (although with 1.11.0 I was only able to repro a dimmer Indent Guide).

The issue with clang-format is "by design". You need to add a .clang-format file and change the settings appropriately, such as the TabWith, IndentWidth, and UseTab settings.

If you're still having problems, let us know.

@slaiyer
Copy link

slaiyer commented Apr 13, 2017

@sean-mcmanus The issue persists even with only the native option "editor.formatOnSave": true. I have removed all non-native plugins and settings include clang formatting.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 13, 2017

@slaiyer What issue exactly? Do you have the C/C++ (cpptools) 0.10.5 installed? What version of VS Code are you using? Our extension doesn't have any effect on the renderIndentGuides, and it renders fine on 1.12-Insiders. Our extension calls clang-format to implement formatting for C++ files, but the settings have to be setup correctly in the .clang-format file to match the tab/spacing you want.

@slaiyer
Copy link

slaiyer commented Apr 13, 2017

@sean-mcmanus VS Code updated to 1.11.2 x64 on Windows 10. ms-vscode.cpptools0.10.5 installed and enabled by default.

The original post in this thread has screenshots showing the tab-based indentation issue (of resetting visual indentation levels after 4 code nesting levels) that occurs with C/C++ sources. I have narrowed it down to 2 mutually exclusive triggers:

  • "editor.formatOnSave": true in settings.json
  • Use of auto-format (Alt-Shift-F)

"editor.formatOnType": true and "editor.formatOnPaste": true do not trigger this issue by themselves.

No other formatting/code beautifying extensions installed nor settings enabled to get this minimal example.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 13, 2017

@slaiyer What are the contents of the .clang-format file you are using? If your tabsSize isn't 4, you'll need to change the .clang-format settings to match VS Code's settings. Maybe our default "Visual Studio" style should take into account the Visual Studio Code tab settings. I'll re-open this issue to consider that, so we work better out of the box without a .clang-format file.

@sean-mcmanus sean-mcmanus reopened this Apr 13, 2017
@slaiyer
Copy link

slaiyer commented Apr 13, 2017

@sean-mcmanus I apologize for the continued misunderstanding. I have stopped using clang-format in its entirety and the issue depicted in the screenshots still persists.

Steps to reproduce:

  1. Convert to/use tab indentation
  2. Save with "editor.formatOnSave": true or perform auto-format (Alt-Shift-F)

Since the original post here is by @alexandrudima and I cannot edit it, I have updated the original issue post as well.

EDIT:

Without "editor.formatOnSave": true or performing auto-format (Alt-Shift-F):
0

With either "editor.formatOnSave": true or auto-format (Alt-Shift-F) performed (auto-format with "editor.formatOnSave": false produces same issue as well):
1

@sean-mcmanus
Copy link
Contributor

@slaiyer Our cpptools extension uses the clang-format.exe 3.8 under the covers (there's another clang-format extension that does something similar). VS Code and the cpptools extension do not provide any other means of formatting C++ code.

@slaiyer
Copy link

slaiyer commented Apr 13, 2017

@sean-mcmanus I was not aware of that. In that case, seeing as "C_Cpp.clang_format_fallbackStyle": "Visual Studio" by default, this minimal case should be reproducible at your end.

I hope you have seen the screenshots I have added to my previous post in this thread as an afterthought. Please let me know if I can do more troubleshooting at my end. Thanks a lot for your patience.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 13, 2017

@slaiyer Yes, I can repro the issue. You can work around this via using the setting: "C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, UseTab: Always, IndentWidth: 2, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, TabWidth: 2 }"
modifying the IndentWidth, TabWidth, and other settings as desired. Our code uses that for the Visual Studio style under the cover (also with sort_includes set to false), except we weren't setting the TabWidth, which is what leads to this bug. I thought we had a reason for not setting the TabWidth, but I don't remember what it was. A fix should be in the next update.

@bobbrow
Copy link
Member

bobbrow commented Apr 25, 2017

This issue should be fixed with v0.11.0. Please let us know if it is not.

@bobbrow bobbrow closed this as completed Apr 25, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants