microsoft / vscode-cpptools

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

Wrong syntax highlighting when casting to pointer types #12982

Open oncipriani opened 1 week ago

oncipriani commented 1 week ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: The closing parenthesis for a type cast to any pointer type gets the wrong color.

Steps to reproduce:

  1. Open the provided sample C source in VS Code;
  2. Notice the wrong parenthesis colors in lines 7 and 8.

Expected behavior: The color of a closing parenthesis should be the same as the color of its matching opening parenthesis.

Configuration and Logs

c_cpp_properties.json:

{
    "env": {
        "commonIncludePath": [
            "${workspaceFolder}/src/**",
            "${env:VULKAN_SDK}/include/**"
        ],
        "commonDefines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ]
    },
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${commonIncludePath}"
            ],
            "defines": [
                "${commonDefines}",
                "WIN32",
                "WIN32_LEAN_AND_MEAN",
                "STRICT",
                "VK_USE_PLATFORM_WIN32_KHR"
            ],
            "windowsSdkVersion": "10.0.26100.0",
            "compilerPath": "cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

Log Disgnostics:

-------- Diagnostics - 11/20/2024, 10:30:39 AM
Version: 1.22.11
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "e:/Git/redesigned-octo-engine/src/**",
        "C:/VulkanSDK/1.3.296.0/include/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE",
        "WIN32",
        "WIN32_LEAN_AND_MEAN",
        "STRICT",
        "VK_USE_PLATFORM_WIN32_KHR"
    ],
    "windowsSdkVersion": "10.0.26100.0",
    "compilerPath": "cl.exe",
    "cStandard": "c17",
    "cppStandard": "c++20",
    "intelliSenseMode": "windows-msvc-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "cl.exe",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "e:/Git/redesigned-octo-engine/src/**",
            "C:/VulkanSDK/1.3.296.0/include/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.intelliSenseUpdateDelay": 3000,
    "C_Cpp.clang_format_style": "Visual Studio",
    "C_Cpp.loggingLevel": "Debug",
    "C_Cpp.autoAddFileAssociations": false
}
Additional Tracked Settings:
{
    "editorTabSize": 4,
    "editorInsertSpaces": true,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {},
    "filesExclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true
    },
    "filesAutoSaveAfterDelay": false,
    "editorInlayHintsEnabled": true,
    "editorParameterHintsEnabled": true,
    "searchExclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.code-search": true
    },
    "workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.22.11.0
Current database path: C:\USERS\ONCIP\APPDATA\LOCAL\MICROSOFT\VSCODE-CPPTOOLS\EDE6E95EC1D6FE7B9DB825C1AAE3684D\.BROWSE.VC.DB
Translation Unit Mappings:
[ E:\Git\redesigned-octo-engine\src\containers\queue.c - source TU]:
    C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_malloc.h
    E:\Git\redesigned-octo-engine\src\containers\queue.h
[ E:\Git\redesigned-octo-engine\src\test.c - source TU]:
Translation Unit Configurations:
[ E:\Git\redesigned-octo-engine\src\containers\queue.c ]
    Process ID: 14936
    Memory Usage: 65 MB
    Includes:
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include
        E:\Git\redesigned-octo-engine\src
    System Includes:
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
        WIN32
        WIN32_LEAN_AND_MEAN
        STRICT
        VK_USE_PLATFORM_WIN32_KHR
    Standard Version: ms_c17
    IntelliSense Mode: windows-msvc-x64
    Other Flags:
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x64
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x86\store\references
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\References\10.0.26100.0
        --using_directory
        C:\Windows\Microsoft.NET\Framework64\v4.0.30319
[ E:\Git\redesigned-octo-engine\src\test.c ]
    Process ID: 8952
    Memory Usage: 58 MB
    Includes:
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include
    System Includes:
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
        WIN32
        WIN32_LEAN_AND_MEAN
        STRICT
        VK_USE_PLATFORM_WIN32_KHR
    Standard Version: ms_c17
    IntelliSense Mode: windows-msvc-x64
    Other Flags:
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x64
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x86\store\references
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\References\10.0.26100.0
        --using_directory
        C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Total Memory Usage: 124 MB

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

Language server logs:

loggingLevel: Debug
loggingLevel has changed to: Debug
LSP: (invoked) cpptools/didChangeCppProperties (id: 328)
LSP: Sending response (id: 328)
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
Intellisense update pending for: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (received) cpptools/didChangeActiveEditor: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (received) cpptools/getCodeActions: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 329)
LSP: (invoked) cpptools/didChangeActiveEditor: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/getCodeActions: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 329)
LSP: Sending response (id: 329)
LSP: (invoked) cpptools/didChangeTextEditorSelection
IntelliSense update scheduled and TU acquisition started for: file:///e%3A/Git/redesigned-octo-engine/src/test.c
Update IntelliSense time (sec): 0.003
LSP: (received) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 330)
LSP: (invoked) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 330)
LSP: Sending response (id: 330)
LSP: (received) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 331)
LSP: (invoked) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 331)
LSP: Sending response (id: 331)
LSP: (received) cpptools/restartIntelliSenseForFile: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (invoked) cpptools/restartIntelliSenseForFile: file:///e%3A/Git/redesigned-octo-engine/src/test.c
Shutting down IntelliSense server: E:\Git\redesigned-octo-engine\src\test.c
Intellisense update pending for: file:///e%3A/Git/redesigned-octo-engine/src/test.c
IntelliSense update scheduled and TU acquisition started for: file:///e%3A/Git/redesigned-octo-engine/src/test.c
Resolving recursive includes...
Done resolving recursive includes.
sending compilation args for E:\Git\redesigned-octo-engine\src\test.c
  include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\TOOLS\MSVC\14.42.34433\INCLUDE
  include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\AUXILIARY\VS\INCLUDE
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.26100.0\UM
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.26100.0\UCRT
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.26100.0\SHARED
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.26100.0\WINRT
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.26100.0\CPPWINRT
  define: _DEBUG
  define: UNICODE
  define: _UNICODE
  define: WIN32
  define: WIN32_LEAN_AND_MEAN
  define: STRICT
  define: VK_USE_PLATFORM_WIN32_KHR
  other: --using_directory
  other: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x64
  other: --using_directory
  other: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x86\store\references
  other: --using_directory
  other: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0
  other: --using_directory
  other: C:\Program Files (x86)\Windows Kits\10\References\10.0.26100.0
  other: --using_directory
  other: C:\Windows\Microsoft.NET\Framework64\v4.0.30319
  stdver: ms_c17
  intelliSenseMode: windows-msvc-x64
Update IntelliSense time (sec): 0.044
LSP: (received) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 332)
LSP: (invoked) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 332)
LSP: Sending response (id: 332)
LSP: (received) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 333)
LSP: (invoked) cpptools/getFoldingRanges: file:///e%3A/Git/redesigned-octo-engine/src/test.c (id: 333)
LSP: Sending response (id: 333)
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) cpptools/didChangeActiveEditor: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (invoked) cpptools/didChangeActiveEditor: file:///e%3A/Git/redesigned-octo-engine/src/test.c
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors

Other Extensions

No response

Additional context

Sample C source:

int main(void) {
    char a = 42;
    int b, c, *p1, *p2;

    // The color of the first closing parenthesis in the following 2 lines
    // differs from the color of their matching opening parenthesis (wrong).
    p1 = (int *)(&a);
    p2 = (int *)&a;

    // The color of the first closing parenthesis in the following 2 lines
    // matches the color of their matching opening parenthesis (correct).
    b = (int)(a);
    c = (int)a;

    return 0;
}
sean-mcmanus commented 1 week ago

@oncipriani Can you provide a screenshot? Can you check if the issue still repros with our C/C++ extension disabled? I am not reproing the issue for some reason.

Image

oncipriani commented 1 week ago

Helo, @sean-mcmanus.

I tested with the C++ extension disabled and the issue still occurs. I guess it is not a problem with the extension, then. 😅

Here is a screenshot of the sample C source code in VS Code with the C++ extension enabled: Screenshot of the sample C source code in VS Code with the C++ extension enabled

And here it is with the C++ extension disabled: Screenshot of the sample C source code in VS Code with the C++ extension disabled

While I was taking the screenshots I found out what was causing the problem: font ligatures. Disabling font ligatures fixes the problem.

For reference, here is my entire settings.json:

{
    "editor.acceptSuggestionOnEnter": "off",
    "editor.fontFamily": "'Cascadia Code', Consolas, 'Courier New', monospace",
    "editor.fontLigatures": true,
    "editor.renderWhitespace": "boundary",
    "editor.rulers": [
        {
            "color": "#00ff8050",
            "column": 80
        },
        {
            "color": "#ff800050",
            "column": 120
        },
        {
            "color": "#ff000050",
            "column": 160
        }
    ],
    "extensions.ignoreRecommendations": true,
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "workbench.startupEditor": "none",
    "workbench.sideBar.location": "right",
    "C_Cpp.autoAddFileAssociations": false,
    "C_Cpp.intelliSenseUpdateDelay": 3000
}