microsoft / vscode-cpptools

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

Autoformatting with `modificationsIfAvailable` changes too many lines #12119

Open ArnoGW1 opened 7 months ago

ArnoGW1 commented 7 months ago

Type: Bug

When auto-formatting on save with these settings:

    "[cpp]": {
        "editor.formatOnType": true,
        "editor.formatOnSave": true,
        "editor.formatOnSaveMode": "modificationsIfAvailable"
    },

my changes and the line after them are formatted. Because of that, every save formats one more line (the extra formatted line from the first save counts as a change for the second save, which formats one more extra line, etc.)

This leads to way too many changes when saving a file multiple times.

Some more details: I'm using clang-format configured for space-indentation while changing a tab-indented file.

Extension version: 1.19.8 VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:20:17.278Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 5900X 12-Core Processor (24 x 3700)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|63.93GB (37.62GB free)| |Process Argv|--crash-reporter-id 0ac330db-34c3-4766-8c92-8e2a96e97825| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfcontrol:30979541 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 dsvsc020:30976470 7ghi1836:30988842 ```
sean-mcmanus commented 7 months ago

Yeah, the fix is for us to implement provideDocumentRangesFormattingEdits . The previous issue was https://github.com/microsoft/vscode-cpptools/issues/12082 and https://github.com/microsoft/vscode/issues/207655 .

sean-mcmanus commented 7 months ago

Oops, this is a little different from those previous issues, but it might still would probably be fixed by implementing provideDocumentRangesFormattingEdits .