If you're using the CMake Tools extension
You need to configure the Cpptools extension to use the CMake tools extensions as the configuration provider.
If you don't have a need to define multiple Cpptools c_cpp configurations, I'd just go and put the following in your workspace .vscode/settings.json:
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
Otherwise, you can create a c_cpp configuration in your .vscode/c_cpp_configurations.json and set configurationProvider in there. Ex. (put this in the configurations array property)
{ "name": "CMake Tools", "configurationProvider": "ms-vscode.cmake-tools" }
You may or may not need to run configuration and build for IntelliSense to catch up to your changes. I'm not exactly sure about the implementation details or historical nuances on that. From what I've observed, problem detection is build-diagnostic-based, so you'll need to rebuild to "refresh" problem detection for things like error squiggles in the editor.
That's it. If you're the kind of person who likes reading docs (crazy, right? that people like that exist?)...
CMake Tools docs for setting up intellisense can be found here. Quoting from it:
CMake Tools currently supports Microsoft's ms-vscode.cpptools extension. If the ms-vscode.cpptools extension is installed and enabled, then configuring your project will provide this integration automatically.
ms-vscode.cpptools will show a prompt confirming that you wish to use CMake Tools to provide the configuration information for your project. Accept this prompt to activate the integration. Subsequently, CMake Tools will provide and automatically update cpptools configuration information for each source file in your project.
The Cpptools FAQ entry on setting up IntelliSense can be found here. Quoting from it:
Or, if you install a build system extension that interfaces with our extension, you can allow that extension to provide the configurations for you. For example, the CMake Tools extension can configure projects that use the CMake build system. Use the C/C++: Change Configuration Provider... command to enable any such extension to provide the configurations for IntelliSense.
Cpptools docs for the configurationProvider setting can be found here. Quoting from it:
configurationProvider: The ID of a VS Code extension that can provide IntelliSense configuration information for source files. For example, use the VS Code extension ID ms-vscode.cmake-tools to provide configuration information from the CMake Tools extension. If you have specified a configurationProvider, the configurations that provides will take precedence over your other settings in c_cpp_properties.json.
Several other answers written here suggest that you should also set the compileCommands property of your c_cpp configuration. I have not found that to be necessary in my own experience. If I understand correctly, that is just another separate way to get IntelliSense with the Cpptools extension. Again, quoting from the Cpptools FAQ entry on setting up IntelliSense:
A third option for projects without build system extension support is to use a compile_commands.json file if your build system supports generating this file. In the "Advanced" section of the Configuration UI, you can supply the path to your compile_commands.json and the extension will use the compilation information listed in that file to configure IntelliSense.
Emphasis on "A third option". Also, CMake doesn't currently support creating compile command database files for all the generators it supports. See the docs for CMAKE_EXPORT_COMPILE_COMMANDS, which states:
Note: This option is implemented only by Makefile Generators and Ninja Generators. It is ignored on other generators.
So using that is not quite the most portable approach.
If you're using the Clangd extension
I've already written about this elsewhere: How can I make the VS Code clangd extension aware of the include paths defined in my CMake configuration?. TL;DR if you aren't doing in-source builds, you may need to tell clangd where your compile_commands.json file is.