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

extension opens system header instead of project header #4411

Closed
flip111 opened this issue Oct 9, 2019 · 9 comments
Closed

extension opens system header instead of project header #4411

flip111 opened this issue Oct 9, 2019 · 9 comments
Labels
Feature: Go to Definition An issue related to Go to Definition/Declaration. Language Service
Milestone

Comments

@flip111
Copy link

flip111 commented Oct 9, 2019

Type: LanguageService

Describe the bug

  • OS and Version: Ubuntu 19.04
  • VS Code Version: 1.33.1
  • C/C++ Extension Version: 0.25.1
  • Other extensions you installed (and if the issue persists after disabling them): antlr4

I opened this folder in vscode /home/flip111/spksrc/distrib/gcc-9.2.0. I saw that this folder was created /home/flip111/spksrc/distrib/gcc-9.2.0/.vscode.

When i look at the file /home/flip111/spksrc/distrib/gcc-9.2.0/libiberty/obstack.c i go to a symbol press F12 and it opens the file /usr/include/obstack.h.

I expect it to open /home/flip111/spksrc/distrib/gcc-9.2.0/include/obstack.h.

In the configuration GUI the includePath is set to ${workspaceFolder}/**, compiler configured to /usr/bin/clang

It's my first time using vscode, i don't understand why it prefers to open my system header instead of the project header.

@sean-mcmanus
Copy link
Contributor

Are you using Go to Def on the #include <obstack.h>? If so, then it's bug #2564 .

Otherwise, can you run C/C++: Log Diagnostics and look what the includePath is being used and see if the paths are correct?

@sean-mcmanus sean-mcmanus added Feature: Go to Definition An issue related to Go to Definition/Declaration. Language Service more info needed The issue report is not actionable in its current state labels Oct 10, 2019
@flip111
Copy link
Author

flip111 commented Oct 10, 2019

I use it on chunkfun in

https://github.com/gcc-mirror/gcc/blob/gcc-9_2_0-release/libiberty/obstack.c#L92

-------- Diagnostics - 10/10/2019, 2:36:45 AM
Version: 0.25.1
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c11",
    "cppStandard": "c++17",
    "intelliSenseMode": "clang-x64"
}
Translation Unit Mappings:
[ /home/flip111/spksrc/distrib/gcc-9.2.0/include/obstack.h ]:
    /home/flip111/spksrc/distrib/gcc-9.2.0/include/obstack.h
[ /home/flip111/spksrc/distrib/gcc-9.2.0/libiberty/obstack.c ]:
    /home/flip111/spksrc/distrib/gcc-9.2.0/libiberty/obstack.c
Translation Unit Configurations:
[ /home/flip111/spksrc/distrib/gcc-9.2.0/include/obstack.h ]:
    Process ID: 11540
    Memory Usage: 13 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/include/c++/8
        /usr/include/x86_64-linux-gnu/c++/8
        /usr/include/c++/8/backward
        /usr/lib/llvm-8/lib/clang/8.0.0/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++17
    IntelliSense Mode: clang-x64
    Other Flags:
        --clang
        --clang_version=80000
        --header_only_fallback
[ /home/flip111/spksrc/distrib/gcc-9.2.0/libiberty/obstack.c ]:
    Process ID: 11744
    Memory Usage: 21 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /usr/lib/llvm-8/lib/clang/8.0.0/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c11
    IntelliSense Mode: clang-x64
    Other Flags:
        --clang
        --clang_version=80000
Total Memory Usage: 34 MB

@sean-mcmanus
Copy link
Contributor

Your includePath doesn't include any workspace folder path. What is your workspace folder? The "${workspaceFolder}/**" will only recursively find headers that are under that path -- is the header in a parent path of the workspace folder?

@flip111
Copy link
Author

flip111 commented Oct 10, 2019

Hi @sean-mcmanus i don't really understand what you are saying. You say my includePath doesn't include a workspace folder path. But i see in the logs:

    "includePath": [
        "${workspaceFolder}/**"
    ],

${workspaceFolder}/** looks like a workspace folder path to me. Do you mean a path additionally to this path?

I was assuming that ${workspaceFolder} would be the directory which the .vscode directory is located which in my case is /home/flip111/spksrc/distrib/gcc-9.2.0 (here the .vscode directory is in).

The header file is located here /home/flip111/spksrc/distrib/gcc-9.2.0/include/obstack.h. Which is UNDER the workspace path. But it's NOT a in a PARENT directory like /home/flip111/spksrc/distrib or /home/flip111/spksrc or /home/flip111 or /home.

@bobbrow
Copy link
Member

bobbrow commented Oct 10, 2019

Does your compiler exist in the /home/flip111/spksrc/distrib/gcc-9.2.0 folder?
(for example: /home/flip111/spksrc/distrib/gcc-9.2.0/bin/g++)

If it does, you should change the "compilerPath" to point to it instead of using /usr/bin/clang.

@flip111
Copy link
Author

flip111 commented Oct 10, 2019

There are no binaries distributed along with the source code of gcc. See https://github.com/gcc-mirror/gcc/tree/gcc-9_2_0-release

@bobbrow
Copy link
Member

bobbrow commented Oct 10, 2019

Thanks for the update. This is one of the tricky corner cases we face when we find includes with duplicate names. You should be able to set priority on your local copy of the includes by adding "/home/flip111/spksrc/distrib/gcc-9.2.0/include" to the "includePath" array like this:

    "includePath": [
        "${workspaceFolder}/include",
        "${workspaceFolder}/**"
    ],

@flip111
Copy link
Author

flip111 commented Oct 10, 2019

Thanks @bobbrow that fixed it. May i note that this is not very intuitive, imo project files should get priority. The issue can be closed if wontfix. Or leave open to change priority of include files and/or add help information about this.

@bobbrow bobbrow removed the more info needed The issue report is not actionable in its current state label Oct 10, 2019
@bobbrow bobbrow added this to the Backlog milestone Oct 10, 2019
@Colengms
Copy link
Contributor

Closing this as the user's issue is addressed, and the behavior is currently by design. We improved the logging when multiple headers with the same name are encountered.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Go to Definition An issue related to Go to Definition/Declaration. Language Service
Projects
None yet
Development

No branches or pull requests

4 participants