microsoft / microsoft/vscode-cmake-tools

Intellisense not working for subdirectories

Open
#1,596 9 comments 0 reactions 0 assignees View on GitHub
bug Feature: configure Feature: cpptools integration
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

Hi there, up until yesterday I was working on a CMake project that included headers from subdirectories within the project. I would call `add_subdirectory()` from a higher level CMakelists.txt and add a `target_include_directories()` within the subdirectory. With this setup intellisense worked perfectly for the headers within this subdirectory and everything compiles properly. In fact, intellisense STILL works JUST in this project folder funnily enough.

However, I've tried multiple times now to start new CMake projects in different folders and intellisense does not to be able to open up headers in subdirectories anymore. It reports red error squiggles beneath `#include` statements for headers contained within these subdirectories. I also get zero configuration errors and everything still compiles perfectly just like the old project mentioned above which still has functioning intellisense.

### Expected:

1. Open new folder in a new window in vscode
2. Use "CMake: Quick Start" and allow CMake tools to configure intellisense
3. Create subdirectory called "src"
4. Add a CMakeLists.txt within it containing `target_include_directories(target PRIVATE ${CMAKE_CURRENT_LIST_DIR}`
5. Add an empty test.hpp within the same subdirectory
6. In the top level CMakeLists.txt, add a call to `add_subdirectory(src)`
7. After configuring, add `#include "test.hpp"` at the top of main.cpp
8. Intellisense should be able to locate test.hpp within the "src" subdirectory

### Apparent Behavior:

Steps 1 to 7 repeat without any difference.
At step 8 however, red error squiggles appear under `#include "test.hpp"` at the top of main.cpp, with the error message "Cannot open source file "test.hpp"" appearing when you hover over it. Everything still configures and compiles without any issue however.

### Platform and Versions

- **Operating System**: macOS
- **CMake Version**: 3.19.1
- **VSCode Version**: 1.52.0
- **CMake Tools Extension Version**: 1.5.3
- **Compiler/Toolchain**: Clang 11.0.3

### Other Notes/Information

I tried following the intellisense tips and fixes found on the CMake tools help site, such as including the header files within a call to `target_sources` in the CMakeLists.txt file located within the subdirectory. It didn't change the outcome however.

Contributor guide

Open the contributing guide

Research direction

Reproduce the seven-step setup with the top-level CMakeLists.txt, src/CMakeLists.txt, main.cpp, and test.hpp, then compare it with the older working project. Trace how CMake Tools supplies IntelliSense configuration after add_subdirectory() and target_include_directories(); done means test.hpp resolves in main.cpp without squiggles while the project still configures and compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, vscode
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.