Disclaimer: I am totally knew to VS Code, so, please, be gentle with me. :-)
I am trying to set up VS Code for C++.
However, I explicitly want to set it up so that it uses the Language Server Protocol to communicate with clangd
when handling C++-files.
I already installed clangd
on my (Ubuntu Linux) system and the official "vscode-clangd" extension from the VS Code market, and I also adjusted its settings so that clangd
should be found by it.
However, now I am lost.
When I open a *.cpp
or *.hpp
file VS Code recommends some other extensions to me (e.g. the official Microsoft "C/C++" extension with IntelliSense support) but I do not see where and how clangd
does help me at all.
Using Microsoft's "C/C++" extension seems to work out of the box but how can I use clangd
?
Thanks for any help.
clangd helps developers write, understand and improve C/C++ code by providing: code completion. compile errors and warnings.
We need to click on the extension button that displays a sidebar for downloading and installing the C/C++ extension in the visual studio code. In the sidebar, type C Extension. In this image, click on the Install button to install the C/C++ extension.
Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration. Find and check the box Run in Terminal.
I can share some of my configures.
Microsoft "C/C++" extension is great for debugging, I think you should install it.
Meanwhile, Clangd provides a more accurate result in finding references. So, My suggestion is to keep the official C/C++ extension for debugging but disable its IntelliSense. Put below lines to your settings.json
"C_Cpp.intelliSenseEngine": "Disabled",
"clangd.path": "/path/to/your/clangd",
"clangd.arguments": ["-log=verbose",
"-pretty",
"--background-index",
//"--query-driver=/bin/arm-buildroot-linux-gnueabihf-g++", //for cross compile usage
"--compile-commands-dir=/path/to/your/compile_commands_dir/"]
Always refer to the official website, there are more settings like filtering out compile param etc. When correctly configured, you will see the output of clangd from OUTPUT windows next to Problems and Terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With