Implement support format request: provideDocumentRangesFormattingEdits · Issue #12082 · microsoft/vscode-cpptools · GitHub
Skip to content

Implement support format request: provideDocumentRangesFormattingEdits #12082

Description

@ArnoGW1

Type: Bug

Formatting any simple 60-line C++ file is sometimes instant, sometimes so long that I give up and try again. I've seen it take 20 seconds or more.

This doesn't depend on contents; formatting randomly takes a long or short time when doing minor changes in the same small .cpp file.

Extension version: 1.19.6
VS Code version: Code 1.87.0 (Universal) (019f4d1419fbc8219a181fab7892ebccf7ee29a2, 2024-02-27T23:42:56.944Z)
OS version: Darwin arm64 23.2.0
Modes:
Remote OS version: Windows_NT x64 10.0.22631

System Info
Item Value
CPUs Apple M1 (8 x 24)
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
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 3
Memory (System) 16.00GB (0.08GB free)
Process Argv --crash-reporter-id 177e6a93-bd0d-4e86-b1ce-b463c9692a68
Screen Reader no
VM 0%
Item Value
Remote pc1
OS Windows_NT x64 10.0.22631
CPUs AMD Ryzen 9 5900X 12-Core Processor (24 x 3700)
Memory (System) 63.93GB (36.37GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
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
pydisww1:30981707
cppperfcontrol:30979541
d34g3935:30971562
fegfb526:30981948
bg6jg535:30979843
ccp1r3:30958155
dsvsc020:30976470

Activity

  1. sean-mcmanus commented on Mar 8, 2024

    @sean-mcmanus
    Contributor

    This is caused by the formatting task getting stuck behind a long IntelliSense parsing operation. It's being tracked by #6156 already, although that issue mentions format on type and vcFormat, the same issue would repro with clang-format and not on type.

    ...unless you don't see the C/C++ task bar progress indicator showing "IntelliSense: Updating" (and/or cpptools-srv isn't using CPU).

  2. ArnoGW1 commented on Mar 11, 2024

    @ArnoGW1
    Author

    ...unless you don't see the C/C++ task bar progress indicator showing "IntelliSense: Updating" (and/or cpptools-srv isn't using CPU).

    I don't see this indicator. The problem happens no matter which IntelliSense operations are underway. If I wait for the open file to be fully parsed and for VSCode to do nothing, then save, the save operation can still hang for a long time.

  3. sean-mcmanus commented on Mar 11, 2024

    @sean-mcmanus
    Contributor

    Arno Gobbin (@ArnoGW1) Can you set C_Cpp.loggingLevel to "Debug" and look in the C/C++ logging to see what it shows when your format and the bug repros?

    e.g. normally, you should see something like

    LSP: (received) cpptools/formatDocument: file:///
    LSP: (invoked) cpptools/formatDocument: file:///
    Formatting document: file:///
    Formatting Engine: clangFormat
    LSP: Sending response (id: 47)
    

    but if there are other messages then those could be contributing to the issue.

  4. romanholidaypancakes commented on Mar 12, 2024

    @romanholidaypancakes

    I also encountered this problem. I have been worried about the performance issues of vs (api components and the like), because as far as I know, we only need to call the clang-format executable file to format the source code. If this is the case The technical solution should be optimized very soon!
    Formatting using visual studio only takes a moment (also clang-format), and if there are syntax errors in the code, it will take a long time and fail.

  5. ArnoGW1 commented on Mar 12, 2024

    @ArnoGW1
    Author

    Arno Gobbin (@ArnoGW1) Can you set C_Cpp.loggingLevel to "Debug" and look in the C/C++ logging to see what it shows when your format and the bug repros?

    Copying a bit more than what you asked; this was with formatOnSave and saving took around 4 seconds in a 116-line file:

    LSP: (invoked) cpptools/getCodeActions: file:///d%3A/projects/my_project/include/header_1.h (id: 278)
    LSP: (invoked) textDocument/didChange: file:///d%3A/projects/my_project/include/header_1.h
    LSP: (invoked) cpptools/didChangeTextEditorSelection
    LSP: (invoked) cpptools/getCodeActions: file:///d%3A/projects/my_project/include/header_1.h (id: 279)
    LSP: Sending response (id: 279)
    LSP: (invoked) cpptools/getFoldingRanges: file:///d%3A/projects/my_project/include/header_1.h (id: 280)
    LSP: (invoked) cpptools/formatRange: file:///d%3A/projects/my_project/include/header_1.h (id: 283)
    Formatting document: file:///d%3A/projects/my_project/include/header_1.h
    Formatting Engine: clangFormat
    LSP: Sending response (id: 280)
    c:\Users\user\.vscode-server\extensions\ms-vscode.cpptools-1.19.6-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file -fallback-style=LLVM --Wno-error=unknown -offset=4956 -length=84 -assume-filename=D:\projects\my_project\header_1.h
    LSP: Sending response (id: 283)
    LSP: (received) cpptools/formatRange: file:///d%3A/projects/my_project/include/header_1.h (id: 284)
    LSP: (invoked) cpptools/formatRange: file:///d%3A/projects/my_project/include/header_1.h (id: 284)
    Formatting document: file:///d%3A/projects/my_project/include/header_1.h
    Formatting Engine: clangFormat
    c:\Users\user\.vscode-server\extensions\ms-vscode.cpptools-1.19.6-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file -fallback-style=LLVM --Wno-error=unknown -offset=5301 -length=148 -assume-filename=D:\projects\my_project\header_1.h
    LSP: Sending response (id: 284)
    LSP: (received) textDocument/willSaveWaitUntil: file:///d%3A/projects/my_project/include/header_1.h (id: 285)
    LSP: (invoked) textDocument/willSaveWaitUntil: file:///d%3A/projects/my_project/include/header_1.h (id: 285)
    LSP: Sending response (id: 285)
    willSaveWaitUntil: 0ms
    

    Note that my settings contain:

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

    But I remember having that issue before adding formatOnSaveMode.

  6. ArnoGW1 commented on Mar 12, 2024

    @ArnoGW1
    Author

    Note that it sometimes doesn't finish at all. It's been happening a lot lately, which is blocking. Here's the log:

    Formatting document: file:///d%3A/projects/my_project/include/header_1.h
    Formatting Engine: clangFormat
    c:\Users\user\.vscode-server\extensions\ms-vscode.cpptools-1.19.6-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file -fallback-style=LLVM --Wno-error=unknown -offset=5443 -length=96 -assume-filename=D:\projects\my_project\header_1.h
    LSP: Sending response (id: 812)
    
  7. 10 remaining items

  8. added
    more info neededThe issue report is not actionable in its current state
    and removed
    more info neededThe issue report is not actionable in its current state
    on Jun 17, 2024
  9. daniellivingston commented on Apr 8, 2025

    @daniellivingston

    Do you have any more repro details for the "error' offset is outside the file"?

    This is something I'm running into as well. Curiously this is the only discussion I could find online referencing it. The Clang-Format extension outputs error: offset 2530 is outside the file.

    Setting C_Cpp.loggingLevel to "Debug" shows:

    LSP: (received) textDocument/willSaveWaitUntil: </path1/fileA.h> (id: 1135)
    LSP: (invoked) textDocument/willSaveWaitUntil: </path1/fileA.h> (id: 1135)
    LSP: Sending response (id: 1135)
    willSaveWaitUntil: 0ms
    LSP: (received) cpptools/didChangeVisibleTextEditors
    LSP: (invoked) cpptools/didChangeVisibleTextEditors
    LSP: (received) cpptools/didChangeActiveEditor: </path1/fileA.h>
    LSP: (invoked) cpptools/didChangeActiveEditor: </path1/fileA.h>
    LSP: (received) cpptools/didChangeVisibleTextEditors
    LSP: (invoked) cpptools/didChangeVisibleTextEditors
    LSP: (received) textDocument/didSave: </path1/fileA.h>
    LSP: (invoked) textDocument/didSave: </path1/fileA.h>
    Intellisense update pending for: </path1/fileA.h>
    LSP: (received) cpptools/fileChanged: </path1/fileA.h>
    LSP: (invoked) cpptools/fileChanged: </path1/fileA.h>
    tag parsing file: </path1/fileA.h>
    IntelliSense update scheduled and TU acquisition started for: </path1/fileA.h>
    LSP: (received) cpptools/getCodeActions: </path1/fileA.h> (id: 1136)
    LSP: (invoked) cpptools/getCodeActions: </path1/fileA.h> (id: 1136)
    LSP: Sending response (id: 1136)
    Update IntelliSense time (sec): 1.336
    LSP: (received) cpptools/getFoldingRanges: </path1/fileA.h> (id: 1137)
    LSP: (invoked) cpptools/getFoldingRanges: </path1/fileA.h> (id: 1137)
    LSP: Sending response (id: 1137)
    LSP: (received) cpptools/getFoldingRanges: </path1/fileA.h> (id: 1138)
    LSP: (invoked) cpptools/getFoldingRanges: </path1/fileA.h> (id: 1138)
    LSP: Sending response (id: 1138)
    LSP: (received) cpptools/getCodeActions: </path1/fileA.h> (id: 1139)
    LSP: (invoked) cpptools/getCodeActions: </path1/fileA.h> (id: 1139)
    LSP: Sending response (id: 1139)
    LSP: (received) cpptools/didChangeVisibleTextEditors
    LSP: (invoked) cpptools/didChangeVisibleTextEditors
    LSP: (received) cpptools/didChangeActiveEditor: </path1/fileA.h>
    LSP: (invoked) cpptools/didChangeActiveEditor: </path1/fileA.h>
    LSP: (received) cpptools/didChangeVisibleTextEditors
    LSP: (invoked) cpptools/didChangeVisibleTextEditors
    LSP: (received) cpptools/getCodeActions: </path1/fileA.h> (id: 1140)
    LSP: (invoked) cpptools/getCodeActions: </path1/fileA.h> (id: 1140)
    LSP: Sending response (id: 1140)
    Database safe to open.
    
  10. Colengms commented on Sep 18, 2026

    @Colengms
    Contributor

    We've been using this issue to track handling of multi-range format requests. It's unclear to me whether all related issues mentioned here have been addressed. It's possible there was a VS Code bug at some point that was generating excessive individual format requests, which may have since been resolved. If anyone is still repro'ing behavior they had reported here, please open a new issue with repro steps.

  11. sean-mcmanus commented on Sep 22, 2026

    @sean-mcmanus
    Contributor
  12. ArnoGW1 commented on Sep 23, 2026

    @ArnoGW1
    Author

    Arno Gobbin (@ArnoGW1) Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.35.2

    Thank you! I will check this when I work on C++ stuff again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions