microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

editor action 'FormatDocument' not use .clang-format file #2254

Closed yaochx closed 6 years ago

yaochx commented 6 years ago

Type: LanguageService

Describe the bug

I add a clang format file at root directory of source code. When pressing ctrl + a, then ctrl + k, ctrl + f, using edictor.action.formatselectoin to format file, the format style is correctly the same with using clang-format in command line. However, when pressing ctrl + shift + I, using edictor.action.formatdocument to format file, it differs strangely. It does not use the .clang-format file.

How to fix this odd behavior?

vscode User Setting

"editor.tabSize": 2,
"editor.tabCompletion": false,
"editor.insertSpaces": true,
"editor.formatOnType": true,
"clang.executable": "/usr/bin/clang-5.0",
"C_Cpp.clang_format_fallbackStyle": "Google",
"C_Cpp.clang_format_path": "/usr/bin/clang-format-5.0",
"C_Cpp.clang_format_style": "file",
"C_Cpp.clang_format_sortIncludes": false

.clang-format


BasedOnStyle: Google


Language: Cpp
PointerAlignment: Right
BreakBeforeBraces: Attach
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
Cpp11BracedListStyle: true
Standard: Cpp11
ColumnLimit: 120
CommentPragmas: '^ NOLINT'


sean-mcmanus commented 6 years ago

Do you have the clang-format extension installed? It's possible another extension is executing the format document. If you set our C_Cpp.loggingLevel to "Debug" do you see messages about formatting input/output in the C/C++ section of the Output window?

yaochx commented 6 years ago

thanks to your reply, @sean-mcmanus

  1. Extensions relative to C/C++ are 'C/C++', 'C/C++ Clang Command Adapter', 'C++ Intellisense', 'C++ Snippets'
  2. the output message only shows " Checking for syntax errors: file:///home/collin/***/predictor_manager.cpp "
yaochx commented 6 years ago

When I open another project like apollo, the formatting functions work well. So there's no problem with current vscode and its user setting. Although I try to find out the differences betwen their workspace settings, but till now I do not succeed to fix it.