microsoft / microsoft/vscode-cmake-tools

C_Cpp.ResetDatabase does not recover IntelliSense for newly created files when CMake Tools is the configurationProvider

Open
#4,953 14 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

## Summary

When a new `.cpp`/`.h` file is created inside VS Code in a CMake project (where CMake Tools is the IntelliSense `configurationProvider`), IntelliSense permanently fails for that file until `Developer: Restart Extension Host` or a full VS Code restart is performed. Running `cmake.configure` followed by `C_Cpp.ResetDatabase` does NOT fix the issue.

## Environment
- cpptools: 1.32.2
- cmake-tools: 1.23.52
- OS: Linux (Ubuntu)
- Multi-root workspace (10 folders)
- CMake project uses `file(GLOB_RECURSE ... CONFIGURE_DEPENDS ...)` for sources

## Steps to Reproduce

1. Open a CMake project with CMake Tools as the IntelliSense provider (no `c_cpp_properties.json`, no `C_Cpp.default.compileCommands`)
2. Create a new `.cpp` file inside VS Code — it opens immediately, IntelliSense starts failing (expected, cmake has not re-configured yet)
3. Run **CMake: Configure** — the code model is updated, the new file appears in `.cmake/api/v1/reply/target-*.json` with the correct include paths, and `compile_commands.json` also contains the correct entry with `-isystem` paths
4. Run **C/C++: Reset IntelliSense Database**
5. Re-open the new file

**Expected:** IntelliSense works — include paths are found, no errors
**Actual:** IntelliSense still shows include errors:
```
#include errors detected based on information provided by the configurationProvider.
Squiggles are disabled for this translation unit.
```
System includes (from `-isystem` / `isSystem=true` in the CMake code model) are not found.

## Key Observation

- **Existing files** (present before the current VS Code session) work correctly with identical CMake code model include paths — no IntelliSense errors.
- **Only newly created files** in the current session fail, even after `cmake.configure` + `C_Cpp.ResetDatabase`.
- **`Developer: Restart Extension Host`** fixes the issue immediately.

## Root Cause Hypothesis

When a new file is first opened, cpptools requests its configuration from CMake Tools. If cmake has not re-configured yet, CMake Tools returns no configuration for that URI. Cpptools caches this "no configuration" state.

After `cmake.configure`, CMake Tools fires a `configurationChanged` event. However, files previously in "no configuration" state appear to not be re-queried. `C_Cpp.ResetDatabase` clears the symbol index and restarts the language server, but the stale provider-relationship state for the "no config" file persists.

Only a full extension host restart (which also re-initializes CMake Tools, clearing all provider state) resolves the issue.

## Expected Behavior of `C_Cpp.ResetDatabase`

`C_Cpp.ResetDatabase` should perform a full reset equivalent to restarting the extension host, including re-requesting IntelliSense configurations from all registered `configurationProvider`s for all currently open files — including files that were previously in a "no configuration" state.

## Workaround

Use **`Developer: Restart Extension Host`** instead of `C_Cpp.ResetDatabase`.

Alternatively, create new files from outside VS Code (e.g. terminal `touch`), run `cmake.configure`, then open the files — IntelliSense works on first open.

## Related Issue

See also: https://github.com/microsoft/vscode-cmake-tools/issues/1479 ("Provide configuration information for nearby files", marked stale)

Contributor guide

Open the contributing guide

Research direction

Reproduce the workflow using CMake: Configure and C/C++: Reset IntelliSense Database, then inspect the generated .cmake/api/v1/reply/target-*.json and compile_commands.json entries for the new file. Compare the behavior of a newly created file with an existing file, and verify that the fix makes IntelliSense recover without Developer: Restart Extension Host.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, typescript, vscode
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.