microsoft / microsoft/vscode-cpptools

#ifdef and #if defined not parsed correctly

Offen
#12,867 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Language Service Visual Studio Code
Vorherrschende Sprache
TypeScript
Sterne
6.2k
Forks
1.7k
Ø Merge
14 Std. 46 Min.
Gemergte PRs (30 T.)
61

Beschreibung

Environment
  • OS and Version: Windows 11
  • VS Code Version: 1.94.2
  • C/C++ Extension Version: 1.22.9
  • If using SSH remote, specify OS of remote machine: N/A
Bug Summary and Steps to Reproduce

Bug Summary:
The below screenshots show the issue. The #ifdef section is properly being greyed out, but the parenthesis and curly brackets are not being paired properly. I've reproduced this on Windows 11 with the MSVC compiler, as well as on WSL with gcc. It appears to be OS/compiler agnostic. This seems similar to #12326, but not an exact match. Note that the behavion is the same whether #ifdef or #if defined is used.

Image

Image

Steps to reproduce:

Open the following code in VSCode with the default c_cpp_properties.json:

void foo( void ) {
if( 1
#ifdef NOT_DEFINED_SYMBOL
    )
    {
#else
    )
    {
#endif
    }
}

Expected behavior:

Configuration and Logs

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

C/C++: Log Diagnostics

-------- Diagnostics - 10/21/2024, 11:28:00 AM
Version: 1.22.9
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "c:/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.18362.0",
    "compilerPath": "cl.exe",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "windows-msvc-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "cl.exe",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "c:/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.errorSquiggles": "enabled",
    "C_Cpp.vcFormat.indent.braces": true,
    "C_Cpp.vcFormat.indent.multiLineRelativeTo": "outermostParenthesis",
    "C_Cpp.vcFormat.indent.preserveWithinParentheses": true,
    "C_Cpp.vcFormat.indent.caseLabels": true,
    "C_Cpp.vcFormat.indent.caseContentsWhenBlock": true,
    "C_Cpp.vcFormat.indent.gotoLabels": "leftmostColumn",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.type": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "newLine",
    "C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true,
    "C_Cpp.vcFormat.space.withinParameterListParentheses": true,
    "C_Cpp.vcFormat.space.afterKeywordsInControlFlowStatements": false,
    "C_Cpp.vcFormat.space.withinControlFlowStatementParentheses": true,
    "C_Cpp.vcFormat.space.withinExpressionParentheses": true,
    "C_Cpp.vcFormat.space.beforeBlockOpenBrace": false,
    "C_Cpp.vcFormat.space.withinSquareBrackets": true,
    "C_Cpp.vcFormat.space.withinLambdaBrackets": true,
    "C_Cpp.vcFormat.space.pointerReferenceAlignment": "center",
    "C_Cpp.vcFormat.wrap.preserveBlocks": "never",
    "C_Cpp.clang_format_style": "Visual Studio",
    "C_Cpp.formatting": "vcFormat",
    "C_Cpp.commentContinuationPatterns": [
        {
            "begin": "/*",
            "continue": "*"
        }
    ],
    "C_Cpp.codeAnalysis.runAutomatically": false,
    "C_Cpp.vcpkg.enabled": false,
    "C_Cpp.loggingLevel": "Debug",
    "C_Cpp.experimentalFeatures": "enabled"
}
Additional Tracked Settings:
{
    "editorTabSize": 4,
    "editorInsertSpaces": true,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {
        "*.h": "c",
        "*.inc": "asm-collection",
        "*.sct": "linkerscript",
        "*.men": "cmm",
        "*.S": "arm",
        "*.s": "asm-collection"
    },
    "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.8.0
Current database path: C:\USERS\MAMMEN\APPDATA\LOCAL\MICROSOFT\VSCODE-CPPTOOLS\4E74F6FAD2317DE57C3390195BD9E427\.BROWSE.VC.DB
Translation Unit Mappings:
[ C:\Users\mammen\Documents\Code\c_cpp_vscode_bug_repro\test.c - source TU]:
Translation Unit Configurations:
[ C:\Users\mammen\Documents\Code\c_cpp_vscode_bug_repro\test.c ]
    Process ID: 40028
    Memory Usage: 50 MB
    Compiler Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe
    Includes:
    System Includes:
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: ms_c17
    IntelliSense Mode: windows-msvc-x64
Total Memory Usage: 50 MB

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

Language server logging:

loggingLevel: Debug
LSP: (received) cpptools/initialize (id: 1)
LSP: (invoked) cpptools/initialize (id: 1)
cpptools version (TypeScript): 1.22.9
cpptools version (native): 1.22.8.0
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
LSP: Sending response (id: 1)
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
LSP: (received) cpptools/queryCompilerDefaults (id: 2)
LSP: (invoked) cpptools/queryCompilerDefaults (id: 2)
Compiler info database not connected - skipping load.
Compiler info database not connected - skipping load.
LSP: Sending response (id: 2)
LSP: (received) cpptools/queryCompilerDefaults (id: 3)
LSP: (invoked) cpptools/queryCompilerDefaults (id: 3)
LSP: (received) cpptools/didChangeCppProperties (id: 4)
LSP: (received - deferred) textDocument/didOpen: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c
LSP: (received - deferred) cpptools/didChangeVisibleTextEditors
LSP: (received - deferred) cpptools/didChangeVisibleTextEditors
LSP: (received - deferred) cpptools/didChangeVisibleTextEditors
Compiler info database not connected - skipping load.
Compiler info database not connected - skipping load.
LSP: Sending response (id: 3)
LSP: (invoked) cpptools/didChangeCppProperties (id: 4)
Code browsing service initialized
Populating file name cache...
Attempting to get defaults from C compiler in "compilerPath" property: 'cl.exe'
Attempting to get defaults from C++ compiler in "compilerPath" property: 'cl.exe'
  Folder: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\ATLMFC\INCLUDE\* will be indexed
  Folder: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\INCLUDE\* will be indexed
  Folder: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\CPPWINRT\ will be indexed
  Folder: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\SHARED\ will be indexed
  Folder: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\ will be indexed
  Folder: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UM\ will be indexed
  Folder: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\WINRT\ will be indexed
  Folder: C:\USERS\MAMMEN\DOCUMENTS\CODE\C_CPP_VSCODE_BUG_REPRO\ will be indexed
LSP: (queued) textDocument/didOpen: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c
LSP: (queued) cpptools/didChangeVisibleTextEditors
LSP: (queued) cpptools/didChangeVisibleTextEditors
LSP: (queued) cpptools/didChangeVisibleTextEditors
LSP: Sending response (id: 4)
LSP: (invoked) textDocument/didOpen: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c
Discovering files...
LSP: (invoked) cpptools/didChangeVisibleTextEditors
Intellisense update pending for: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c
  Processing folder (non-recursive): C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\INCLUDE
  Processing folder (recursive): C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\CPPWINRT\
  Processing folder (non-recursive): C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\ATLMFC\INCLUDE
  Processing folder (recursive): C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\SHARED\
  Processing folder (recursive): C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\
  Processing folder (recursive): C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UM\
  Processing folder (recursive): C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\WINRT\
  Processing folder (recursive): C:\USERS\MAMMEN\DOCUMENTS\CODE\C_CPP_VSCODE_BUG_REPRO\
LSP: (received) cpptools/didChangeSettings
LSP: (invoked) cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
Done populating filename cache. Elapsed time: 147 ms
  Discovering files: 5106 file(s) processed
  0 file(s) removed from database
Done discovering files.
Populating include completion cache.
Parsing remaining files...
  Parsing: 0 files(s) processed
Done parsing remaining files.
LSP: (received) cpptools/didChangeSettings
LSP: (invoked) cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: (received) cpptools/didChangeSettings
LSP: (invoked) cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: (received) cpptools/getCodeActions: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 5)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 5)
LSP: Sending response (id: 5)
LSP: Message ignored due to no registered handler: $/setTrace
LSP: (received) cpptools/didChangeSettings
LSP: (invoked) cpptools/didChangeSettings
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 6)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 6)
LSP: $/cancelRequest (<unknown/completed>, id: 5)
LSP: Sending response (id: 6)
LSP: (received) cpptools/getCodeActions: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 7)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 7)
LSP: Sending response (id: 7)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 8)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 8)
LSP: Sending response (id: 8)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 9)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 9)
LSP: Sending response (id: 9)
IntelliSense update scheduled and TU acquisition started for: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c
Resolving recursive includes...
Done resolving recursive includes.
sending compilation args for C:\Users\mammen\Documents\Code\c_cpp_vscode_bug_repro\test.c
  system include: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\INCLUDE
  system include: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\VC\TOOLS\MSVC\14.29.30133\ATLMFC\INCLUDE
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UM
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\SHARED
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\WINRT
  system include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\CPPWINRT
  define: _DEBUG
  define: UNICODE
  define: _UNICODE
  stdver: ms_c17
  intelliSenseMode: windows-msvc-x64
Update IntelliSense time (sec): 0.847
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 10)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 10)
LSP: Sending response (id: 10)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 11)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 11)
LSP: Sending response (id: 11)
LSP: $/cancelRequest (<unknown/completed>, id: 10)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 12)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/Users/mammen/Documents/Code/c_cpp_vscode_bug_repro/test.c (id: 12)
LSP: Sending response (id: 12)
Other Extensions

No response

Additional context

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Öffne zunächst den reproduzierten Fall in test.c mit der bereitgestellten c_cpp_properties.json und überprüfe das Verhalten der Klammerpaarbildung sowohl für #ifdef als auch für #if defined. Verfolge den Einstiegspunkt der C/C++-Erweiterung für die Vorverarbeitung oder das Parsen, der diese Direktiven verarbeitet; abgeschlossen ist die Aufgabe, wenn Klammern und geschweifte Klammern im gezeigten bedingten Code korrekt gepaart werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, typescript
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.