microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.4k stars 1.51k forks source link

Parsing of code containing nlohmann/json reports errors #9842

Closed fcharlie closed 1 year ago

fcharlie commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

Recently, when I used VSCode to develop my open source project baulk, I found that the c++ extension incorrectly reported the error of json.hpp, I believe that this cannot be the error of json.hpp, because my project can be compiled normally Yes, the operation is normal. So I speculate that the C++ language service of vscode-cpptools may not be able to parse this version of json.hpp correctly.

json.hpp release: https://github.com/nlohmann/json/releases/tag/v3.11.2

Steps to reproduce:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

No response

Code sample and Logs

-------- Diagnostics - 2022/9/3 18:48:05
Version: 1.12.4
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "${workspaceFolder}/vendor/bela/include",
        "${workspaceFolder}/include",
        "${workspaceFolder}/lib/archive/zlib",
        "${workspaceFolder}/lib/archive/zstd",
        "${workspaceFolder}/lib/archive/liblzma/api",
        "${workspaceFolder}/lib/archive/brotli/include",
        "${workspaceFolder}/lib/archive/ced",
        "${workspaceFolder}/lib/archive/bzip2"
    ],
    "windowsSdkVersion": "10.0.22621.0",
    "intelliSenseMode": "windows-msvc-x64",
    "compilerPathIsExplicit": false,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": false,
    "macFrameworkPath": [],
    "compilerArgs": [
        "-DUNICODE",
        "-D_UNICODE=1",
        "-Zc:__cplusplus"
    ],
    "cStandard": "c17",
    "cppStandard": "c++23",
    "mergeConfigurations": false,
    "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe",
    "browse": {
        "path": [
            "${workspaceFolder}/vendor/bela/include",
            "${workspaceFolder}/include",
            "${workspaceFolder}/lib/archive/zlib",
            "${workspaceFolder}/lib/archive/zstd",
            "${workspaceFolder}/lib/archive/liblzma/api",
            "${workspaceFolder}/lib/archive/brotli/include",
            "${workspaceFolder}/lib/archive/ced",
            "${workspaceFolder}/lib/archive/bzip2",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ C:\Users\charlie\Desktop\Dev\Code\baulk\tools\baulk-lnk\baulk-lnk.cc ]:
    C:\Users\charlie\Desktop\Dev\Code\baulk\tools\baulk-lnk\baulk-lnk.hpp *
    C:\Users\charlie\Desktop\Dev\Code\baulk\include\baulk\json_utils.hpp *
Translation Unit Configurations:
[ C:\Users\charlie\Desktop\Dev\Code\baulk\tools\baulk-lnk\baulk-lnk.cc ]:
    Process ID: 23404
    Memory Usage: 434 MB
    Compiler Path: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe
    Includes:
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\VENDOR\BELA\INCLUDE
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\INCLUDE
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\ZLIB
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\ZSTD
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\LIBLZMA\API
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\BROTLI\INCLUDE
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\CED
        C:\USERS\CHARLIE\DESKTOP\DEV\CODE\BAULK\LIB\ARCHIVE\BZIP2
        C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\TOOLS\MSVC\14.33.31629\INCLUDE
        C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\TOOLS\MSVC\14.33.31629\ATLMFC\INCLUDE
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.22621.0\UM
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.22621.0\UCRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.22621.0\SHARED
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.22621.0\WINRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.22621.0\CPPWINRT
    Defines:
        UNICODE
        _UNICODE=1
    Standard Version: ms_c++latest
    IntelliSense Mode: windows-msvc-x64
    Other Flags:
        --ms_cplusplus_std_value
Total Memory Usage: 434 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 45181

Syntax errors are no longer reported after deleting c_cpp_properties.json under the workspace.

Screenshots

Error screenshot

image

Additional context

Open this project with visual studio + cmake, there is no error in syntax parsing

image
sean-mcmanus commented 1 year ago

@fcharlie Are you able to install the CMake Tools extension, configure it, and set the configurationProvider ? Does that fix the issue? We can try it ourselves too later. It's possible adding "${workspaceFolder}/**" to the start of your includePath could also fix the issue, but using CMake Tools is the preferred method of configuration (it's more accurate).

fcharlie commented 1 year ago

@fcharlie Are you able to install the CMake Tools extension, configure it, and set the configurationProvider ? Does that fix the issue? We can try it ourselves too later. It's possible adding "${workspaceFolder}/**" to the start of your includePath could also fix the issue, but using CMake Tools is the preferred method of configuration (it's more accurate).

I'll try it when I have time

fcharlie commented 1 year ago

@sean-mcmanus No issues have been reported so far with cmake tools enabled.