Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile_commands.json file not found if created after the initial editor load and its path contains variables #7241

Closed
aleksa2808 opened this issue Mar 27, 2021 · 0 comments · Fixed by #7242
Labels
bug Feature: Compile Commands Feature: Configuration An issue related to configuring the extension or IntelliSense fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Milestone

Comments

@aleksa2808
Copy link
Contributor

aleksa2808 commented Mar 27, 2021

Type: LanguageService

Describe the bug

  • OS and Version: Ubuntu 20.04
  • VS Code Version: 1.54.3
  • C/C++ Extension Version: 1.3.0-insiders2
  • Other extensions you installed (and if the issue persists after disabling them): persists without other extensions
  • Does this issue involve using SSH remote to run the extension on a remote machine?: no

When the compile_commands.json file path includes variables like ${workspaceFolder} the file is found if it exists only during the initial editor load, but not if it was created after the editor was started.

Steps to reproduce

Make a simple program that includes a header from an external library, and set the compileCommands item in the c_cpp_properties.json file (or in more general settings) to something like ${workspaceFolder}/build/compile_commands.json. Make sure the build folder is clean and then compile the program to generate the compile_commands.json file. The include directives should still be marked with red lines indicating that the extension couldn't locate the compile_commands.json file.

Example (lib can be any available library):

main.cpp

#include "lib.hpp"

int main()
{
    lib();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(app)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(lib REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} lib::lib)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

Expected behavior

I expect the include paths to get resolved shortly after the compile_commands.json file is created.

Logs
-------- Diagnostics - 3/27/2021, 7:55:19 AM
Version: 1.3.0-insiders2
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "cStandard": "gnu17",
    "cppStandard": "gnu++14",
    "intelliSenseMode": "linux-gcc-x64",
    "compileCommands": "${workspaceFolder}/build/compile_commands.json",
    "compilerArgs": [],
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "compilerPathIsExplicit": true,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/user/source/test/app/src/main.cpp ]:
    /home/user/source/test/app/src/main.cpp
Translation Unit Configurations:
[ /home/user/source/test/app/src/main.cpp ]:
    Process ID: 12164
    Memory Usage: 10 MB
    Compiler Path: /usr/bin/gcc
    Includes:
        /usr/include/c++/9
        /usr/include/x86_64-linux-gnu/c++/9
        /usr/include/c++/9/backward
        /usr/lib/gcc/x86_64-linux-gnu/9/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++14
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=90300
Total Memory Usage: 10 MB

------- Workspace parsing diagnostics -------
Number of folders and files enumerated: 3635
Number of files discovered (not excluded): 3081
@sean-mcmanus sean-mcmanus added this to the 1.3.0 milestone Mar 29, 2021
@sean-mcmanus sean-mcmanus added Feature: Compile Commands Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service bug labels Mar 29, 2021
@Colengms Colengms modified the milestones: 1.3.0, 1.4.0 Mar 30, 2021
@sean-mcmanus sean-mcmanus modified the milestones: 1.4.0, 1.3.0 Mar 31, 2021
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 31, 2021
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Feature: Compile Commands Feature: Configuration An issue related to configuring the extension or IntelliSense fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants