Type: LanguageService
To Reproduce
Steps to reproduce the behavior:
Provide a code sample including configuration files such as c_cpp_properties.json
Expected behavior
A clear and concise description of what you expected to happen.
I expect the formatter to read my .clang-format and use that to format.
Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Call Stacks: For bugs like crashes, deadlocks, infinite loops, etc. that we are not able to repro and for which the call stack may be useful, please attach a debugger and/or create a dmp and provide the call stacks. Starting with 0.17.3, Windows binaries have symbols available in VS Code by setting your "symbolSearchPath" to "http://msdl.microsoft.com/download/symbols".
Error:
Formatting input: #ifndef GAME_H
#define GAME_H
class Game {
private:
int n;
};
#endif
Formatting document: file:///c%3A/Users/ivisc/Desktop/RPG/src/headers/Game.h
Formatting failed:
"c:\Users\ivisc\.vscode\extensions\ms-vscode.cpptools-0.17.4/bin/../LLVM/bin/clang-format.exe" -style="file" -fallback-style="LLVM" -assume-filename="c:\Users\ivisc\Desktop\RPG\src\headers\Game.h"
YAML:1:4: error: Got empty plain scalar
锟斤拷L
.clang-format:
Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
User Settings:
"window.zoomLevel": 0,
"team.showWelcomeMessage": false,
"workbench.colorTheme": "Eclipse",
"editor.insertSpaces": false,
"editor.formatOnType": false,
"C_Cpp.clang_format_style": "file",
"C_Cpp.loggingLevel": "Debug",
"editor.formatOnSave": true,
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false
That's odd. I set up a folder to look like yours, pasted your .clang-format in, and it works for me. The error message seems to imply that there are non-ASCII characters at the start of your .clang-format file. Can you try re-encoding that file as plain text or UTF-8 with no BOM? There might be byte order marks that clang-format doesn't understand in there.
Must be something with IncludeCategories. Crashes when is defined.
@TheAifam5, if you are having issues with IncludeCategories, can you post a new issue? I do not see any problem with it in this case.
@iViscosity, do you have a hex viewer extension installed? The "hexdump for VSCode" extension works well if you don't. Please open your .clang-format in the hex viewer and check the first few bytes to see if they are ASCII characters or byte markers. Clang-Format appears to work ok with the UTF-8 markers EF BB BF, but if you have something else in there, it could be the source of your problem. Please reopen the issue if the byte order markers is not the problem.
I just hit exactly this issue with clang-check, and in my case it was that the file was encoded (according to VIM) with utf-16le. Saving with encoding utf-8 caused it to parse correctly. The error is coming from the YAML parser in Clang's libTooling, so not really a bug in vscode-cpptools, unless there is a way for vscode-cpptools to control the character encodings that clang-format etc. recognise.
Most helpful comment
I just hit exactly this issue with clang-check, and in my case it was that the file was encoded (according to VIM) with
utf-16le. Saving with encodingutf-8caused it to parse correctly. The error is coming from the YAML parser in Clang's libTooling, so not really a bug in vscode-cpptools, unless there is a way for vscode-cpptools to control the character encodings that clang-format etc. recognise.