microsoft / microsoft/vscode-cpptools

rename of typedef'd struct doesn't work properly with unnamed structs

Aperta
#14,162 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Feature: Find All References Feature: Rename Language Service Works in VS
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Environment
  • OS and Version: W10 22H2
  • VS Code Version: 1.108.2
  • C/C++ Extension Version: 1.30.3
  • If using SSH remote, specify OS of remote machine: no
Bug Summary and Steps to Reproduce

Bug Summary:

If you don't name the struct in a typedef, i.e.

typedef struct {
    int a;
} type_t;

renaming the type (here: type_t) does list all references * as NOT A REFERENCE and with the checkbox not ticked.

* EDIT: If you define multiple variables and you rename the type there, it does detect the other variables as references, but not the typedef itself. If renaming at the typedef, none of the variables are references.

Image

When giving it a name, i.e.

typedef struct foo_s {
    int a;
} type_t;

the rename goes through immediately.

Image

EDIT2: This also affects renaming the fields of the struct.

Steps to reproduce:

  1. Make file main.c with:
typedef struct {
    int a;
} type_t;

type_t x;

int main() {
  return 0;
}
  1. Rename Symbol type_t
  2. Depending on where you trigger the rename (typedef or variable definition) the other one is NOT A REFERENCE
  3. Give the type any name
  4. Rename Symbol
  5. Now it magically is a reference ...

Expected behavior:
Rename works the same in both cases without saying it's NOT A REFERENCE when unnamed.


I mean, it isn't a huge problem, but having to tick the boxes each time because it doesn't detect that it's in fact a reference gets annoying.

But I'm happy that renaming macros finally works 😁

Configuration and Logs
This is basically the default configuration for gcc, but there you go:

[c_cpp_properties.json]
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.26100.0",
            "compilerPath": "C:/Program Files/mingw64/bin/gcc.exe",
            "cppStandard": "c++03",
            "intelliSenseMode": "windows-gcc-x64",
            "cStandard": "c99"
        }
    ],
    "version": 4
}



[C/C++: Log Diagnostics]
-------- Diagnostics - 2/3/2026, 11:00:26 AM
Version: 1.30.3
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "d:/Syncbox/test/c-test/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.26100.0",
    "compilerPath": "C:/Program Files/mingw64/bin/gcc.exe",
    "cppStandard": "c++03",
    "intelliSenseMode": "windows-gcc-x64",
    "cStandard": "c99",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "recursiveIncludesReduceIsExplicit": false,
    "recursiveIncludesPriorityIsExplicit": false,
    "recursiveIncludesOrderIsExplicit": false,
    "compilerPathInCppPropertiesJson": "C:/Program Files/mingw64/bin/gcc.exe",
    "mergeConfigurations": false,
    "recursiveIncludes": {},
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.inlayHints.parameterNames.enabled": true,
    "C_Cpp.inlayHints.parameterNames.suppressWhenArgumentContainsName": false,
    "C_Cpp.inlayHints.referenceOperator.enabled": true,
    "C_Cpp.errorSquiggles": "enabled",
    "C_Cpp.default.cStandard": "c99",
    "C_Cpp.vcFormat.indent.caseLabels": true,
    "C_Cpp.vcFormat.newLine.beforeCatch": false,
    "C_Cpp.vcFormat.newLine.beforeElse": false,
    "C_Cpp.commentContinuationPatterns": [
        {
            "begin": "/**",
            "continue": "*"
        }
    ],
    "C_Cpp.experimentalFeatures": "enabled"
}
Additional Tracked Settings:
{
    "editorTabSize": 4,
    "editorInsertSpaces": true,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {
        "*.njs": "javascript",
        "*.cps": "javascript",
        "*.scr": "freebasic",
        "*.FCMacro": "python"
    },
    "filesExclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": 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.30.2.0
Current database path: C:\USERS\ANDREAS\APPDATA\LOCAL\MICROSOFT\VSCODE-CPPTOOLS\4D947C8EF103797001BE961BE2B4AFE0\.BROWSE.VC.DB
Translation Unit Mappings:
[ D:\Syncbox\test\c-test\main.c - source TU]:
Translation Unit Configurations:
[ D:\Syncbox\test\c-test\main.c ]
    Process ID: 11472
    Memory Usage: 52 MB
    Compiler Path: C:\Program Files\mingw64\bin\gcc.exe
    Include paths:
        system include: C:\Program Files\mingw64\lib\gcc\x86_64-w64-mingw32\15.1.0\include
        system include: C:\Program Files\mingw64\include
        system include: C:\Program Files\mingw64\lib\gcc\x86_64-w64-mingw32\15.1.0\include-fixed
        system include: C:\Program Files\mingw64\x86_64-w64-mingw32\include
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: c99
    IntelliSense Mode: windows-gcc-x64
    Other Flags:
        --gcc
        --gnu_version=150100
Total Memory Usage: 52 MB

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



[the language server logging]
LSP: (received) cpptools/rename: file:///d%3A/Syncbox/test/c-test/main.c (id: 503)
LSP: (invoked) cpptools/rename: file:///d%3A/Syncbox/test/c-test/main.c (id: 503)
LSP: (received) textDocument/documentHighlight: file:///d%3A/Syncbox/test/c-test/main.c (id: 504)
LSP: (invoked) textDocument/documentHighlight: file:///d%3A/Syncbox/test/c-test/main.c (id: 504)
LSP: Sending response (id: 504)
LSP: Sending response (id: 503)
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) textDocument/didChange: file:///d%3A/Syncbox/test/c-test/main.c
LSP: (invoked) textDocument/didChange: file:///d%3A/Syncbox/test/c-test/main.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) cpptools/getFoldingRanges: file:///d%3A/Syncbox/test/c-test/main.c (id: 505)
LSP: (invoked) cpptools/getFoldingRanges: file:///d%3A/Syncbox/test/c-test/main.c (id: 505)
LSP: Sending response (id: 505)
LSP: (received) cpptools/getCodeActions: file:///d%3A/Syncbox/test/c-test/main.c (id: 506)
LSP: (invoked) cpptools/getCodeActions: file:///d%3A/Syncbox/test/c-test/main.c (id: 506)
LSP: Sending response (id: 506)
LSP: (received) cpptools/getDocumentSymbols: file:///d%3A/Syncbox/test/c-test/main.c (id: 507)
LSP: (invoked) cpptools/getDocumentSymbols: file:///d%3A/Syncbox/test/c-test/main.c (id: 507)
tag parsing file: D:\Syncbox\test\c-test\main.c
LSP: Sending response (id: 507)
Intellisense update pending for: file:///d%3A/Syncbox/test/c-test/main.c
IntelliSense update scheduled and TU acquisition started for: file:///d%3A/Syncbox/test/c-test/main.c
Update IntelliSense time (sec): 0.012
LSP: (received) cpptools/getFoldingRanges: file:///d%3A/Syncbox/test/c-test/main.c (id: 508)
LSP: (invoked) cpptools/getFoldingRanges: file:///d%3A/Syncbox/test/c-test/main.c (id: 508)
LSP: Sending response (id: 508)
Other Extensions

No response

Additional context

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione di main.c e analizza la voce cpptools/rename mostrata nel log di language-server. Confronta i risultati della ridenominazione per le struct typedef con nome e senza nome, inclusi i campi delle struct; il lavoro è completato quando tutti i riferimenti rilevanti a typedef, variabili e campi vengono rilevati in modo coerente senza selezionare manualmente le caselle.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.