"Code completion" (or "IntelliSense" as Microsoft calls it in their products) is a feature of most IDEs. It provides suggestions as you type, and shows most errors immediately without having to compile.
You don't have to use code completion, and writing a few simple programs without code completion is a good learning experience. But for more complex projects it's invaluable.
Out of the box VSC doesn't have code completion for most languages. You must install an extension for it.
The two most popular extensions for C/C++ code completion are:
-
Microsoft's C/C++ extension, seemingly using the same code completion engine as Visual Studio.
-
Clangd. Not to be confused with Clang. Clangd is a code completion engine based on Clang the compiler, hence its name.
We will be installing Clangd, since in my experience it works faster, [doesn't choke on advanced C++ features](TODO show example), and can be used in most popular IDEs (not only in VSC).
Clangd needs two parts to work:
- A extension for your IDE (for VSC in this case).
- A program called
clangdthat the extension interacts with.
Install the latter in MSYS2 using pacman -S mingw-w64-ucrt-x86_64-clang-tools-extra. (Why not the official Clang installer?)
In VSC, open the extension marketplace by pressing the 'boxes' button on the left:
![]()
Search for clangd and install it:
![]()
NOTE: You don't need the C/C++ extension to be installed, since Clangd (and others I'll suggest next) replaces it. If you want to keep it installed, you need to disable its intellisense to avoid conflicts:
NOTE: If Clangd suggests downloading a "language server", refuse. It's not useful since we already installed the same thing from MSYS2. (Why not the official Clang installer? applies to this as well.)
If you see this message, you didn't configure PATH correctly as was explained here. (Alternatively, you can go to File->Preferences->Settings, search for clangd path, and put C:\msys64\ucrt64\bin\clangd.exe in there.)
If you change PATH, you'll need to start VSC for it to take effect. And when changing Clangd settings, you can either restart VSC or press CtrlShiftP->clangd: Restart language server.
Create a new file and save it with the .cpp extension (e.g. name it prog.cpp). You should see clangd: idle appear at the bottom-left corner.
When you start typing, you should see red squiggles for invalid code, and code completion suggestions.
-
CtrlSpace - Open code completion suggestions. Normally this happens automatically as you type, but you can open it manually too. Hit Escape to hide it.
-
CtrlShiftSpace - Open function parameters help. This also usually opens automatically. Hit Escape to hide it.
-
Ctrl. - Quick actions. If you see a lightbulb icon, pressing this will suggest to fix the current error, or do something else.
-
F8 - Show next problem. This explains what a red squiggle means (or you can move your mouse over it).
-
Holding Ctrl and clicking on something in the code will open its declaration or show where it's used.
Try to use Clangd for a bit! See what features you like or don't like.
Then come back here and see if you want to change any of the settings below.
If you type e.g. std::cout << std::sin(42) << '\n';, Clangd will show a little gray x: before 42, telling you the function parameter name:
This is not a part of the actual source code, just something it displays to make your life easier.
If you find this is annoying, go to File->Preferences->Settings, search for inlay hints, and set it to offUnlessPressed. You can then hold CtrlAlt to temporarily unhide them.
You will see a little dot before some of the Clangd code completions:
Accepting such completion by pressing Enter will automatically add an include for this name, e.g. #include <iostream> in this case.
If you don't like this behavior (and arguably it's not good for learning purposes), go to the settings, search clangd arguments, press Add item, type --header-insertion=never and press OK. Hit CtrlShiftP->clangd: Restart language server to apply changes.
Even after this, you can still use Ctrl. (see above) to automatically insert missing headers.
Sometimes accepting a function name completion will insert placeholders for its arguments. E.g. typing std::find_ and acceping std::find_if will result in this:
If you don't like this and would prefer to get just std::find_if(), go to the settings, search clangd arguments, press Add item, type --function-arg-placeholders=false and press OK. Hit CtrlShiftP->clangd: Restart language server to apply changes.
If you use File->Open Folder... and look at the Explorer tab, you'll see that Clangd has created a .cache directory to store its internal data next to your source code.
You can hide this directory from Explorer by going to the settings, searching for files exclude, pressing Add Pattern and adding .cache/ to the list.






