microsoft / microsoft/vscode-cpptools

Wrong configuration info is used for a C/C++ file that is included by another

Open
#6,250 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: Compile Commands Feature: Configuration Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

I was/I am trying to make "Go To Definition" work in a big project but it did not work. I managed to produce a minimal example of this bug:

Type: LanguageService

Describe the bug

  • OS and Version: Arch Linux
  • VS Code Version:
    1.49.1
    58bb7b2331731bf72587010e943852e13e6fd3cf
    x64
  • C/C++ Extension Version: 1.0.0
  • Other extensions you installed (and if the issue persists after disabling them): None
  • Does this issue involve using SSH remote to run the extension on a remote machine?: No
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc):

File Structure (You can download it here: bugexample.zip):
.
├── child.C : #include "child.H"
├── child.H : #include "hiddenFile.H"
├── compile_commands.json
├── hiddenlib
│ └── hiddenFile.H : empty
├── main.C : #include "child.H" \n int main(){}
└── .vscode
│ └── c_cpp_properties.json

c_cpp_properties.json:

{
    "configurations": [
      {
        "compileCommands": "${workspaceFolder}/compile_commands.json",
      }
    ],
    "version": 4
}

compile_commands.json was generated using bear -- g++ -I./hiddenlib -c main.C:

[
  {
    "arguments": [
      "/usr/bin/g++",
      "-I./hiddenlib",
      "-c",
      "main.C"
    ],
    "directory": "/home/volker/Documents/bugexample",
    "file": "/home/volker/Documents/bugexample/main.C",
    "output": "/home/volker/Documents/bugexample/main.o"
  }
]

Expected behavior and observed behaviour

If I open the folder, open child.H, set my cursor on "hiddenFile.H" and sellect "Go To Definition" it should jump to hiddenlib/hiddenFile.H. Instead it says "No definition for hiddenFile". Also there is a message on startup that says
"child.C" not found in "${workspaceFolder}/compile_commands.json". 'includePath' from c_cpp_properties.json in folder 'bugexample' will be used for this file instead.

Note: You can only reproduce this bug if you don't open main.C and you need to wait a few seconds after startup before trying to "Go To Definition" (around 7 seconds on my machine).

Logs
-------- Diagnostics - 10/4/2020, 12:46:46 AM
Version: 1.0.0
Current Configuration:
{
    "compileCommands": "${workspaceFolder}/compile_commands.json",
    "compilerArgs": [],
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/volker/Documents/bugexample/child.C ]:
    /home/volker/Documents/bugexample/child.H
Translation Unit Configurations:
[ /home/volker/Documents/bugexample/child.C ]:
    Process ID: 66481
    Memory Usage: 9 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/include/c++/10.2.0
        /usr/include/c++/10.2.0/x86_64-pc-linux-gnu
        /usr/include/c++/10.2.0/backward
        /usr/local/include
        /usr/lib/clang/10.0.1/include
        /usr/include
        /home/volker/Documents/bugexample
    Standard Version: c++14
    IntelliSense Mode: clang-x64
    Other Flags:
        --clang
        --clang_version=100001
Total Memory Usage: 9 MB

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

Slightly OT: If you know a better tool than vscode-cpptools for finding the definitions in big projects, please tell me.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the attached bugexample.zip, using compile_commands.json and .vscode/c_cpp_properties.json as shown. Start by checking how child.H receives configuration when child.C is absent from compile_commands.json; done means Go To Definition from hiddenFile.H resolves to hiddenlib/hiddenFile.H without the fallback-configuration warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools, tooling
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.