clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
625 stars 102 forks source link

the .clang-format no effect #463

Open walkthetalk opened 1 year ago

walkthetalk commented 1 year ago

not only for display, e.g.

TabWidth:        8

it still display 4 spaces width for tab.

but also for 'format selection' in context menu.

I[11:22:33.852] ASTWorker building file /home/ll/repos/np100/modules/drivers/qkm/src/qkm_hidden.cpp version 2 with command 
[/home/ll/repos/np100/build]
/usr/lib/llvm-15/bin/clang++ --driver-mode=g++ -DFMT_SHARED -DQKM_LIBRARY -DQT_CORE_LIB -DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_OPENGL_LIB -DQT_QMLINTEGRATION_LIB -DQT_QMLMODELS_LIB -DQT_QML_DEBUG -DQT_QML_LIB -DQT_QUICK_LIB -DQT_SERIALPORT_LIB "-D_NP100_RELEASE_VERSION_=\"0.0.0.0\"" -D_USE_MATH_DEFINES -I/home/ll/repos/np100/build/dep.qkm/qkm_autogen/include -I/home/ll/repos/np100/modules/drivers/qkm/include -I/home/ll/repos/np100/modules/drivers/qkm/SYSTEM -I/home/ll/repos/np100/modules/auxiliary/include -I/home/ll/repos/np100/modules/msgpack/include -isystem /usr/include/eigen3 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtSerialPort -isystem /usr/include/x86_64-linux-gnu/qt6/QtQuick -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtQml -isystem /usr/include/x86_64-linux-gnu/qt6/QtQmlIntegration -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtQmlModels -isystem /usr/include/x86_64-linux-gnu/qt6/QtOpenGL -g -fPIC -Wall -Wextra -pedantic -Werror -fPIC -std=c++17 -o dep.qkm/CMakeFiles/qkm.dir/src/qkm_hidden.cpp.o -c -resource-dir=/usr/lib/llvm-15/lib/clang/15.0.7 -- /home/ll/repos/np100/modules/drivers/qkm/src/qkm_hidden.cpp
I[11:22:33.909] --> textDocument/clangd.fileStatus
I[11:22:34.061] <-- textDocument/codeAction(64)
I[11:22:34.066] <-- textDocument/documentSymbol(65)
I[11:22:34.247] --> reply:textDocument/inlayHint(63) 403 ms
I[11:22:34.248] Skipping rebuild of the AST for /home/ll/repos/np100/modules/drivers/qkm/src/qkm_hidden.cpp, inputs are the same.
I[11:22:34.250] --> textDocument/publishDiagnostics
I[11:22:34.252] --> reply:textDocument/codeAction(64) 190 ms
I[11:22:34.252] --> reply:textDocument/documentSymbol(65) 186 ms
I[11:22:34.252] --> textDocument/clangd.fileStatus
I[11:22:34.525] <-- textDocument/codeAction(66)
I[11:22:34.525] --> reply:textDocument/codeAction(66) 0 ms
I[11:22:34.525] --> textDocument/clangd.fileStatus
I[11:22:34.807] <-- textDocument/documentLink(67)
I[11:22:34.807] --> reply:textDocument/documentLink(67) 0 ms
I[11:22:34.807] --> textDocument/clangd.fileStatus
I[11:22:35.816] <-- textDocument/semanticTokens/full/delta(68)
I[11:22:35.817] --> reply:textDocument/semanticTokens/full/delta(68) 0 ms
I[11:22:35.817] --> textDocument/clangd.fileStatus
I[11:23:33.438] <-- textDocument/hover(69)
I[11:23:33.442] --> reply:textDocument/hover(69) 4 ms
I[11:23:33.442] --> textDocument/clangd.fileStatus
I[11:24:16.057] <-- textDocument/hover(70)
I[11:24:16.062] --> reply:textDocument/hover(70) 4 ms
I[11:24:16.062] --> textDocument/clangd.fileStatus

image

HighCommander4 commented 1 year ago

not only for display, e.g.

TabWidth:        8

it still display 4 spaces width for tab.

This needs to be configured in VSCode's own settings, see https://code.visualstudio.com/docs/editor/codebasics#_indentation

The .clang-format file only controls the formatting actions performed by clangd (or other plugins that may invoke the clang-format tool).

but also for 'format selection' in context menu.

I believe you also need to configure in VSCode settings that clangd should be used as the formatter for C++ source files, something like this:

"[cpp]": {
  "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
}
walkthetalk commented 1 year ago

@HighCommander4 Thanks!