microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 447 forks source link

Intellisense not working for subdirectories #1596

Open ghost opened 3 years ago

ghost commented 3 years ago

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

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.

andreeis commented 3 years ago

Is step 7 (configure) succeeding? If it would fail for any reason, then the squiggle is expected. Are you sure you're describing the CMakeLists.txt right? With target_include_directories in src\CMakeLists.txt configure fails and I see squiggle, but with it defined in the top folder configure succeeds and the header is found.

ghost commented 3 years ago

I believe I have diagnosed the problem now. I realised all the new CMake projects I've started since the original working project were stored on an APFS Encrypted and Case-Sensitive volume on my SSD. When I copy over the problematic CMake projects onto an unencrypted APFS volume (the same one the original working project is stored on), the intellisense works just fine and everything configures with zero errors.

If it is a case of the intellisense being unable to read encrypted, case-sensitive drives, does that make it an issue belonging to the C/C++ Microsoft extension?

Thanks for the quick reply by the way.

andreeis commented 3 years ago

Oh, interesting. I am thinking of doing the following to know more where the root problem is.

Set loggingLevel to debug for CMake Tools and CppTools. Make sure cmake.configureOnOpen is not defined to false (the default is true, so if it's missing you're good).

Then load each project (each having all the files closed, no editors opened) and save the CMake Tools output channel in both cases. Those will contain logging information about what happens when a project is loaded and then configured.

Then load a c/cpp source code file (main.cpp if you only did a simple quick CMake project) and save the CppTools output channel for both.

Then run the command "C/C++: Log Diagnostics" and save the "C/C++ Diagnostics" output channel for both.

Share these 6 log files with us. You should also inspect the main.cpp paths in these logs and highlight when they don't look correct.

Most probably what happens is that CMake Tools sends the IntelliSense information associated to a file path and CppTools is searching for it by using a different path and that's why is not found. Let's see what extension uses the wrong path.

ghost commented 3 years ago

Hi there, I've tried to source as many of the log files that you requested.

This was the CMake tools output for the unencrypted project.

[variant] Loaded new set of variants [kit] Successfully loaded 3 kits from /Users/benjaminwright/.local/share/CMakeTools/cmake-tools-kits.json [main] Configuring folder: test3 [proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -H/Volumes/GIGABYTE/Source/CMake/test3 -B/Volumes/GIGABYTE/Source/CMake/test3/build -G "Unix Makefiles" [cmake] Not searching for unused variables given on the command line. [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: /Volumes/GIGABYTE/Source/CMake/test3/build

This was the CMake tools output for the unencrypted project.

[variant] Loaded new set of variants [kit] Successfully loaded 3 kits from /Users/benjaminwright/.local/share/CMakeTools/cmake-tools-kits.json [main] Configuring folder: test4 [proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -H/Volumes/ENCRYPTED/Source/test4 -B/Volumes/ENCRYPTED/Source/test4/build -G "Unix Makefiles" [cmake] Not searching for unused variables given on the command line. [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: /Volumes/ENCRYPTED/Source/test4/build

They both compile correctly.

This was the CppTools output for the main.cpp file of the encrypted project (There was no output for the unencrypted project's main.cpp file). I'm not sure if I found the right output channel for CppTools, since this just represents the intellisense errors found in the file.

{ "resource": "/Volumes/ENCRYPTED/Source/test4/main.cpp", "owner": "C/C++", "code": "1696", "severity": 8, "message": "#include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit (/Volumes/ENCRYPTED/Source/test4/main.cpp).", "source": "C/C++", "startLineNumber": 3, "startColumn": 1, "endLineNumber": 3, "endColumn": 21 } { "resource": "/Volumes/ENCRYPTED/Source/test4/main.cpp", "owner": "C/C++", "code": "1696", "severity": 8, "message": "cannot open source file \"test1.hpp\"", "source": "C/C++", "startLineNumber": 3, "startColumn": 1, "endLineNumber": 3, "endColumn": 21 } { "resource": "/Volumes/ENCRYPTED/Source/test4/main.cpp", "owner": "C/C++", "code": "1696", "severity": 8, "message": "cannot open source file \"test2.hpp\"", "source": "C/C++", "startLineNumber": 4, "startColumn": 1, "endLineNumber": 4, "endColumn": 21 }

This is the CppTools diagnostics log for the unencrypted project.

-------- Diagnostics - 12/17/2020, 8:52:18 AM Version: 1.1.3 Current Configuration: { "name": "Mac", "includePath": [ "${workspaceFolder}/" ], "defines": [], "macFrameworkPath": [], "compilerPath": "/usr/local/bin/gcc-10", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "gcc-x64", "compilerArgs": [], "intelliSenseModeIsExplicit": true, "cStandardIsExplicit": true, "cppStandardIsExplicit": true, "compilerPathIsExplicit": true, "configurationProvider": "ms-vscode.cmake-tools", "browse": { "path": [ "${workspaceFolder}/" ], "limitSymbolsToIncludedHeaders": true } } Custom browse configuration: { "browsePath": [ "/volumes/gigabyte/source/cmake/test3/build/cmakefiles", "/volumes/gigabyte/source/cmake/test3/src", "/volumes/gigabyte/source/cmake/test3/src/io", "/volumes/gigabyte/source/cmake/test3" ], "standard": "c++17", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk" ] } Custom configurations: [ /Volumes/GIGABYTE/Source/CMake/test3/main.cpp ] { "defines": [], "standard": "c++17", "includePath": [ "/volumes/gigabyte/source/cmake/test3/src", "/volumes/gigabyte/source/cmake/test3/src/io", "/volumes/gigabyte/source/cmake/test3" ], "intelliSenseMode": "clang-x64", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk" ] } Translation Unit Mappings: [ /Volumes/GIGABYTE/Source/CMake/test3/main.cpp ]: /Volumes/GIGABYTE/Source/CMake/test3/main.cpp Translation Unit Configurations: [ /Volumes/GIGABYTE/Source/CMake/test3/main.cpp ]: Process ID: 15549 Memory Usage: 13 MB Compiler Path: /usr/bin/clang++ Includes: /Volumes/GIGABYTE/Source/CMake/test3/src /Volumes/GIGABYTE/Source/CMake/test3/src/io /Volumes/GIGABYTE/Source/CMake/test3 /Library/Developer/CommandLineTools/usr/include/c++/v1 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include /Library/Developer/CommandLineTools/usr/include Frameworks: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks Standard Version: c++17 IntelliSense Mode: clang-x64 Other Flags: --clang --clang_version=110003 Total Memory Usage: 13 MB

------- Workspace parsing diagnostics ------- Number of folders and files enumerated: 2626 Number of files discovered (not excluded): 2438

This is the CppTools diagnostics log for the encrypted project.

-------- Diagnostics - 12/17/2020, 8:50:34 AM Version: 1.1.3 Current Configuration: { "name": "Mac", "includePath": [ "${workspaceFolder}/" ], "defines": [], "macFrameworkPath": [], "compilerPath": "/usr/local/bin/gcc-10", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "gcc-x64", "compilerArgs": [], "intelliSenseModeIsExplicit": true, "cStandardIsExplicit": true, "cppStandardIsExplicit": true, "compilerPathIsExplicit": true, "configurationProvider": "ms-vscode.cmake-tools", "browse": { "path": [ "${workspaceFolder}/" ], "limitSymbolsToIncludedHeaders": true } } Custom browse configuration: { "browsePath": [ "/volumes/encrypted/source/test4/build/cmakefiles", "/volumes/encrypted/source/test4/src", "/volumes/encrypted/source/test4/src/io", "/volumes/encrypted/source/test4" ], "standard": "c++17", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk" ] } Custom configurations: [ /Volumes/ENCRYPTED/Source/test4/main.cpp ] { "defines": [], "standard": "c++17", "includePath": [ "/volumes/encrypted/source/test4/src", "/volumes/encrypted/source/test4/src/io", "/volumes/encrypted/source/test4" ], "intelliSenseMode": "clang-x64", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk" ] } Translation Unit Mappings: [ /Volumes/ENCRYPTED/Source/test4/main.cpp ]: /Volumes/ENCRYPTED/Source/test4/main.cpp Translation Unit Configurations: [ /Volumes/ENCRYPTED/Source/test4/main.cpp ]: Process ID: 15527 Memory Usage: 113 MB Compiler Path: /usr/bin/clang++ Includes: /Library/Developer/CommandLineTools/usr/include/c++/v1 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include /Library/Developer/CommandLineTools/usr/include Frameworks: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks Standard Version: c++17 IntelliSense Mode: clang-x64 Other Flags: --clang --clang_version=110003 Total Memory Usage: 113 MB

------- Workspace parsing diagnostics ------- Number of folders and files enumerated: 2374 Number of files discovered (not excluded): 2239

These are the relevant log files I could accrue to the best of my limited knowledge. I did notice something however when I inspected and compared both of the diagnostics files. Under the parameter "Custom Browse Configuration" in both files, there is a list of directories written all in lowercase letters. The thing is both my volumes on my computer have uppercase names (GIGABYTE and ENCRYPTED). When I formatted ENCRYPTED initially, I made it to be case-sensitive. I suspect the intellisense error is derived from CppTools trying to look for the directory /volumes/encrypted/source/... which it can't find because of case-sensitivity. That /source directory in particular is actually name /Source. GIGABYTE however is case-unsensitive, so that could explain how CppTools is able to browse that with no problems.

Hopefully that sheds some light.

andreeis commented 3 years ago

Thank you very much. This is enough for now. We will investigate and let you know what we find.

elahehrashedi commented 3 years ago

need to investigate if this is related to this issue: https://github.com/microsoft/vscode-cpptools/issues/1994

vipcxj commented 8 months ago

same issue, any news?

gcampbell-msft commented 2 months ago

@Colengms @sean-mcmanus Do you all have any initial inclination as to whether this belongs on the cmake tools extension or the cpp tools extension? Thanks!

Colengms commented 1 month ago

Hi @gcampbell-msft . This appears to be an old issue. On macOS, the C/C++ extension actually assumes the file system is case-sensitive. My reading of the log diagnostics output above suggests that the custom configuration provided by CMake Tools may contain the wrong case for include paths. if we could get a log containing the contents of the C/C++ output channel with "C_Cpp.loggingLevel": "Debug" set, and containing the message relating to receiving that custom configuration from CMake Tools, that should reflect exactly what was delivered, and rule out any processing cpptools might have done.