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

The source file parent path in compile_commands.json isn't added to the browse.path if it's a relative path #11631

Closed
Shaka0723 opened this issue Nov 7, 2023 · 9 comments
Assignees
Labels
bug Feature: Compile Commands fixed Check the Milestone for the release in which the fix is or will be available. Language Service quick fix verified Bug has been reproduced
Milestone

Comments

@Shaka0723
Copy link

Shaka0723 commented Nov 7, 2023

Environment

  • OS and Version: Both Win and WSL
  • VS Code Version: 1.84
  • C/C++ Extension Version: 1.17.5
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary:
1#. can't switch between src and header
2#. goto definition failed from header/function declaration
3#. find all references failed from header/function declaration

Steps to reproduce:
repro condition:

  1. src and header files are not in same folder, e.g.,
  • %{workspaceFolder}/src/a/b/c/d/module1/module1.c,
  • %{workspaceFolder}/inc/a/b/c/d/module1/module1.h,
  1. using compile_commands.json to config intellisense

  2. a project with deep directory depth, like >5

Expected behavior:
"goto definition"/"find all references"/"switch source/header" ... should work fine via compile_commands.json

Configuration and Logs

c_cpp_properties.json as below:
`{
    "configurations": [
        {
            "name": "WLAN_DEMO",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\cygwin64\\bin\\gcc.exe",
            "intelliSenseMode": "windows-gcc-x86",
            "cStandard": "gnu99",
            "cppStandard": "c++11",
            "compileCommands": "${workspaceFolder}\\project\\demo\\wlan_demo\\gcc\\compile_commands.json"
        }
    ],
    "version": 4
}`





logs:

loggingLevel: Debug
cpptools version (TypeScript): 1.17.5
cpptools version (native): 1.17.5.0
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
LSP: cpptools/didChangeCppProperties (id: 1)
LSP: cpptools/queryCompilerDefaults (id: 2)
Code browsing service initialized
Querying compiler for default C++ language standard using command line: C:\cygwin64\bin\gcc.exe -x c++ -E -dM nul
Querying compiler for default C++ language standard using command line: C:\cygwin64\bin\gcc.exe -x c++ -E -dM /dev/null
Detected language standard version: gnu++17
Querying compiler's default target using command line: "C:\cygwin64\bin\gcc.exe" -dumpmachine
Compiler returned default target value: x86_64-pc-cygwin
Compiler query command line: C:\cygwin64\bin\gcc.exe -std=c++11 -m32 -Wp,-v -E -dM -x c++ nul
Compiler query command line: c:\cygwin64\bin\gcc.exe -std=c++11 -m32 -Wp,-v -E -dM -x c++ /dev/null
LSP: Message ignored due to no registered handler: $/setTrace
LSP: Message ignored due to no registered handler: $/setTrace
LSP: Message ignored due to no registered handler: $/setTrace
Attempting to get defaults from C++ compiler in "compilerPath" property: 'C:\cygwin64\bin\gcc.exe'
Compiler query command line: C:\cygwin64\bin\gcc.exe -std=gnu99 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: c:\cygwin64\bin\gcc.exe -std=gnu99 -m32 -Wp,-v -E -dM -x c /dev/null
Attempting to get defaults from C compiler in "compilerPath" property: 'C:\cygwin64\bin\gcc.exe'
  Folder: C:/CYGWIN64/LIB/GCC/X86_64-PC-CYGWIN/11/INCLUDE/ will be indexed
  Folder: C:/CYGWIN64/USR/INCLUDE/ will be indexed
  Folder: D:/SHAKA/XR872/XRADIO-SKYLARK-SDK-MASTER/PROJECT/ will be indexed
  Folder: D:/SHAKA/XR872/XRADIO-SKYLARK-SDK-MASTER/INCLUDE/ will be indexed
  Folder: C:/CYGWIN64/USR/INCLUDE/W32API/ will be indexed
Discovering files...
Compiler query command line: C:\cygwin64\bin\gcc.exe -std=c17 -m64 -Wp,-v -E -dM -x c nul
  Processing folder (recursive): C:/CYGWIN64/LIB/GCC/X86_64-PC-CYGWIN/11/INCLUDE/
Compiler query command line: c:\cygwin64\bin\gcc.exe -std=c17 -m64 -Wp,-v -E -dM -x c /dev/null
  Processing folder (recursive): C:/CYGWIN64/USR/INCLUDE/
  Processing folder (recursive): D:/SHAKA/XR872/XRADIO-SKYLARK-SDK-MASTER/PROJECT/
  Processing folder (recursive): D:/SHAKA/XR872/XRADIO-SKYLARK-SDK-MASTER/INCLUDE/
Attempting to get defaults from C compiler in "compilerPath" property: 'C:\cygwin64\bin\gcc.exe'
Compiler query command line: C:\cygwin64\bin\gcc.exe -std=gnu++17 -m64 -Wp,-v -E -dM -x c++ nul
  Processing folder (recursive): C:/CYGWIN64/USR/INCLUDE/W32API/
Compiler query command line: c:\cygwin64\bin\gcc.exe -std=gnu++17 -m64 -Wp,-v -E -dM -x c++ /dev/null
  Discovering files: 5458 file(s) processed
Attempting to get defaults from C++ compiler in "compilerPath" property: 'C:\cygwin64\bin\gcc.exe'
LSP: cpptools/didChangeCppProperties (id: 3)
LSP: textDocument/didOpen: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
Checking for syntax errors: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/getInlayHints: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 4)
LSP: cpptools/getSemanticTokens: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 5)
LSP: cpptools/getFoldingRanges: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 6)
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/getDocumentSymbols: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 7)
LSP: cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: cpptools/activeDocumentChange: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/activeDocumentChange: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
  2362 file(s) removed from database
Done discovering files.
Populating include completion cache.
Parsing remaining files...
  Parsing: 0 files(s) processed
Done parsing remaining files.
sending compilation args for D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
 .......
  define: _UNICODE
  other: --gcc
  other: --gnu_version=110300
  other: --ms_extensions
  other: --header_only_fallback
  stdver: c99
  intelliSenseMode: linux-gcc-x86
Checking for syntax errors: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
Shutting down IntelliSense server: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
LSP: textDocument/documentHighlight: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 8)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 9)
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 10)
LSP: cpptools/findAllReferences: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 11)
sending compilation args for D:\Shaka\xr872\xradio-skylark-sdk-master\project\common\apps\player_app.c
  ........
  include: D:\SHAKA\XR872\XRADIO-SKYLARK-SDK-MASTER\PROJECT\COMMON\BOARD\XR872_EVB_AI
  include: C:\CYGWIN64\LIB\GCC\X86_64-PC-CYGWIN\11\INCLUDE
  include: C:\CYGWIN64\USR\INCLUDE
  include: C:\CYGWIN64\USR\INCLUDE\W32API
  ....
  define: __CONFIG_CODEC_HEAP_MODE=0
  preinclude: D:\SHAKA\XR872\XRADIO-SKYLARK-SDK-MASTER\PROJECT\COMMON\PRJ_CONF_OPT.H
  other: --gcc
  other: --gnu_version=110300
  other: --ms_extensions
  stdver: c99
  intelliSenseMode: linux-gcc-x86
Queueing IntelliSense update for files in translation unit of: D:\Shaka\xr872\xradio-skylark-sdk-master\project\common\apps\player_app.c
Error squiggle count: 0
Checking for syntax errors: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
Shutting down IntelliSense server: D:\Shaka\xr872\xradio-skylark-sdk-master\project\common\apps\player_app.c
LSP: textDocument/didClose: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
LSP: Request canceled by server (cpptools/getSemanticTokens, code: -32802, id: 5)
LSP: Request canceled by server (cpptools/getInlayHints, code: -32802, id: 4)
LSP: $/cancelRequest (<unknown/completed>, id: 4)
LSP: $/cancelRequest (<unknown/completed>, id: 5)
LSP: textDocument/didOpen: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 12)
Checking for syntax errors: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
LSP: cpptools/getInlayHints: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 13)
LSP: cpptools/getSemanticTokens: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 14)
LSP: cpptools/activeDocumentChange: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h
LSP: cpptools/textEditorSelectionChange
Database safe to open.
LSP: cpptools/getFoldingRanges: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 15)
LSP: cpptools/getSemanticTokens: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 16)
LSP: Request canceled by server (cpptools/getSemanticTokens, code: -32802, id: 14)
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 17)
sending compilation args for D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
  include: C:\CYGWIN64\LIB\GCC\X86_64-PC-CYGWIN\11\INCLUDE
 ....
  ...
  define: _DEBUG
  define: UNICODE
  define: _UNICODE
  other: --gcc
  other: --gnu_version=110300
  other: --ms_extensions
  other: --header_only_fallback
  stdver: c99
  intelliSenseMode: linux-gcc-x86
Queueing IntelliSense update for files in translation unit of: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
Queueing IntelliSense update for files in translation unit of: D:\Shaka\xr872\xradio-skylark-sdk-master\include\audio\manager\audio_manager.h
Error squiggle count: 0
Update IntelliSense time (sec): 17.744
LSP: cpptools/getFoldingRanges: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 18)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 19)
LSP: cpptools/didSwitchHeaderSource (id: 20)
LSP: textDocument/hover: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 21)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 22)
LSP: textDocument/definition: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 23)
LSP: cpptools/findAllReferences: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 24)
sending compilation args for D:\Shaka\xr872\xradio-skylark-sdk-master\project\demo\audio_demo\audio_player.c
  include: C:\CYGWIN64\LIB\GCC\X86_64-PC-CYGWIN\11\INCLUDE
  include: C:\CYGWIN64\USR\INCLUDE
  include: C:\CYGWIN64\USR\INCLUDE\W32API
  include: D:\SHAKA\XR872\XRADIO-SKYLARK-SDK-MASTER\INCLUDE
  include: D:\SHAKA\XR872\XRADIO-SKYLARK-SDK-MASTER\PROJECT
  include: D:\SHAKA\XR872\XRADIO-SKYLARK-SDK-MASTER\INCLUDE\DRIVER\CMSIS
  .....
  stdver: c99
  intelliSenseMode: linux-gcc-x86
Shutting down IntelliSense server: D:\Shaka\xr872\xradio-skylark-sdk-master\project\demo\audio_demo\audio_player.c
LSP: textDocument/documentHighlight: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 26)
LSP: $/cancelRequest (<unknown/completed>, id: 26)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 27)
LSP: cpptools/getFoldingRanges: file:///d%3A/Shaka/xr872/xradio-skylark-sdk-master/include/audio/manager/audio_manager.h (id: 28)

Other Extensions

No response

Additional context

more infos

  1. clangd extension works fine with same compile_commands.json in same project
  2. if disable "compileCommands" line in "c_cpp_properties.json", then intellisense works better(but you know, it depends on key "includePath"/"defines"...)
  3. switch src and header works fine from src function definition
  4. if open src and same-named header together in vscode editor, then bug 1# /2# can't repro
@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Nov 7, 2023

I'm not reproing the issue. Can you run C/C++: Reset IntelliSense Database to make sure database isn't corrupted? Then can you run C/C++: Log Diagnostics and provide the output or review it to see if there is anything that seems incorrect, i.e. are the folders with the source and headers in the browse path? Also when you open module1.c/h does the Outline view populate with symbols? Also, are you able to project a sample compile_commands.json that repros the issue? If Find All References and Go to Definition don't work, that usually means there's a problem with tag parsing the files or the symbol database.

@sean-mcmanus sean-mcmanus added more info needed The issue report is not actionable in its current state not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one). labels Nov 7, 2023
@Shaka0723
Copy link
Author

Shaka0723 commented Nov 8, 2023

1.Can you run C/C++: Reset IntelliSense Database to make sure database isn't corrupted?
-- I did it but still failed

2.Then can you run C/C++: Log Diagnostics and provide the output or review it to see if there is anything that seems incorrect
--I did but can't find something that helps

3., i.e. are the folders with the source and headers in the browse path?
-- I change c_cpp_properties.json (add below lines ) but still failed

            "browse": {
                "path": [
                    "${workspaceFolder}"
                ],
            }

4.Also when you open module1.c/h does the Outline view populate with symbols?
-- Yes, outline works fine

5.Also, are you able to project a sample compile_commands.json that repros the issue? If Find All References and Go to Definition don't work, that usually means there's a problem with tag parsing the files or the symbol database.

-- Yes please see below comments

@Shaka0723
Copy link
Author

Shaka0723 commented Nov 8, 2023

please see
Additional context above in my first comment
more infos

  1. clangd extension works fine with same compile_commands.json in same project
  2. if disable "compileCommands" line in "c_cpp_properties.json", then goto definition / find all reference ....works better(but you know, it depends on key "includePath"/"defines"...)
  3. switch src and header works fine from src file
  4. if open src and same-named header together in vscode editor, then bug 1# /2# can't repro

So it may be a bug of cpptools, if my project configuration isn't incorrect.

@Shaka0723
Copy link
Author

@sean-mcmanus
sorry, I ignore a most important reproducing condition: project with very deep directory (>=5?)
please see below pic:
image

reproducing steps:

  1. download attached project CPPTools_compile_commands_TestProject.zip and unzip to you c:/
  2. make sure you have a gcc in c:/cygwin64/bin/gcc.exe, or just replace compilerPathdefined in .vscode/c_cpp_properties.json with your gcc path
  3. open the unzip project code with vscode, and just open bsp_f.h (don't open bsp_f.c bsp_g.c)
  4. right click to find definition of any api declared in bsp_f.h, then nothing happened, no jump
  5. right click to find reference for api bf_i()
    image
    CPPTools_compile_commands_TestProject.zip

@sean-mcmanus sean-mcmanus added bug verified Bug has been reproduced and removed more info needed The issue report is not actionable in its current state not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one). labels Nov 9, 2023
@sean-mcmanus sean-mcmanus added this to the 1.19.0 milestone Nov 9, 2023
@sean-mcmanus
Copy link
Collaborator

@Shaka0723 Thanks, I repro the issue with that project and compile_commands.json -- it looks like the folder with the source path is not getting added to the browse.path for some reason.

@sean-mcmanus
Copy link
Collaborator

@Shaka0723 This is a "duplicate" of #11036, but that is closed so we can keep this issue open and/or fix it.

@sean-mcmanus
Copy link
Collaborator

@Shaka0723 I think we can fix it by just adding the source file directories -- my prior concern was about using that directory instead of the "directory". Also, I previously was thinking that the "directory" would always contain the source file directory, but in your example that uses a lot of ".." it does not.

@Shaka0723
Copy link
Author

@Shaka0723 I think we can fix it by just adding the source file directories -- my prior concern was about using that directory instead of the "directory". Also, I previously was thinking that the "directory" would always contain the source file directory, but in your example that uses a lot of ".." it does not.

Thanks and you are right, I replace ../../.... with absolute path then cpptools works fine now.
Hope it fixxed soon.

@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Nov 17, 2023
@sean-mcmanus
Copy link
Collaborator

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.19.0 (pre-release)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Feature: Compile Commands fixed Check the Milestone for the release in which the fix is or will be available. Language Service quick fix verified Bug has been reproduced
Projects
None yet
Development

No branches or pull requests

3 participants