microsoft / vscode-cpptools

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

"configurationProvider" property disappearing #11574

Open Jyrijoul opened 10 months ago

Jyrijoul commented 10 months ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: While editing _c_cppproperties.json, trying to add the "configurationProvider" property results in the current line and existing comments being deleted. Note that properties other than configurationProvider do not seem to have the same behaviour. It could be that this is the intended behaviour, however, it makes it difficult to browse the available values of the property.

Steps to reproduce:

  1. Install the C/C++ extension
  2. Open an empty folder
  3. Use the Edit Configurations (JSON) command to create and open the _c_cppproperties.json configuration file
  4. Try to add the property "configurationProvider", letting it be autocompleted to "configurationProvider": "". Alternatively, type it in manually.
  5. Notice the property as well as any existing comments disappearing. Note that it seems to happen on saving the configuration file.

Expected behaviour: "configurationProvider": "" and comments not disappearing.

Configuration and Logs

c_cpp_properties.json:
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            // Random comment
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ]
        }
    ],
    "version": 4
}

C/C++ language server debug log:
LSP: cpptools/didChangeCppProperties (id: 46)
LSP: cpptools/didChangeCppProperties (id: 47)
LSP: cpptools/didChangeCppProperties (id: 48)
LSP: cpptools/didChangeCppProperties (id: 49)

C/C++ Configuration Warning:
[10/24/2023, 11:04:39 AM] For C++ source files, the cppStandard was changed from "c++17" to "".
[10/24/2023, 11:04:39 AM] For C source files, the cStandard was changed from "c11" to "".

Other Extensions

All other extensions are disabled, even though disabling them did not change the behaviour.

Additional context

No response

Colengms commented 10 months ago

Hi @Jyrijoul . Thanks for reporting this.

This appears to be related to the following bit of (rather old) code:

https://github.com/microsoft/vscode-cpptools/blob/8fbc56a6884c5a841cb599ea7364d0cd321e439d/Extension/src/LanguageServer/configurations.ts#L1411-L1418

It probably shouldn't be modifying the document if a corrected ID could not be found. Also, it probably shouldn't be touching all configurations, as some of them may not be applicable to the current host (if that file is checked into a repo). And, when rewriting c_cpp_properties.json, it should try to preserve existing comments.

Jyrijoul commented 10 months ago

Hi @Colengms, thanks a lot for the reply! Good to know that it is indeed a bug and that you already found a potential cause. :)