Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support format request: provideDocumentRangesFormattingEdits #12082

Open
ArnoGW1 opened this issue Mar 8, 2024 · 10 comments
Open

Implement support format request: provideDocumentRangesFormattingEdits #12082

ArnoGW1 opened this issue Mar 8, 2024 · 10 comments
Labels
bug Feature: Code Formatting investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service performance
Projects
Milestone

Comments

@ArnoGW1
Copy link

ArnoGW1 commented Mar 8, 2024

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

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Mar 8, 2024

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).

@sean-mcmanus sean-mcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2024
@ArnoGW1
Copy link
Author

ArnoGW1 commented Mar 11, 2024

...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.

@sean-mcmanus sean-mcmanus reopened this Mar 11, 2024
@sean-mcmanus sean-mcmanus added Language Service Feature: Code Formatting bug more info needed The issue report is not actionable in its current state and removed duplicate labels Mar 11, 2024
@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Mar 11, 2024

@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.

@sean-mcmanus sean-mcmanus self-assigned this Mar 11, 2024
@romanholidaypancakes
Copy link

romanholidaypancakes commented Mar 12, 2024

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.

@ArnoGW1
Copy link
Author

ArnoGW1 commented Mar 12, 2024

@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.

@ArnoGW1
Copy link
Author

ArnoGW1 commented Mar 12, 2024

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)

@ArnoGW1
Copy link
Author

ArnoGW1 commented Mar 12, 2024

I just had a formatting failure when saving a small change, not sure it's related:

LSP: (received) cpptools/formatRange: file:///d%3A/projects/my_project/src/src_1.cpp (id: 1435)
LSP: (invoked) cpptools/formatRange: file:///d%3A/projects/my_project/src/src_1.cpp (id: 1435)
Formatting document: file:///d%3A/projects/my_project/src/src_1.cpp
Formatting Engine: clangFormat
Formatting failed:
c:\Users\user\.vscode-server\extensions\ms-vscode.cpptools-1.19.7-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file -fallback-style=LLVM --Wno-error=unknown -offset=10906 -length=0 -assume-filename=D:\projects\my_project\src\src_1.cpp D:\PROJECTS\MY_PROJECT\SRC\SRC_1.CPP
error: offset 10906 is outside the file

LSP: Sending response (id: 1435)
LSP: (received) cpptools/fileChanged: file:///d%3A/projects/my_project/src/src_1.cpp
LSP: (invoked) cpptools/fileChanged: file:///d%3A/projects/my_project/src/src_1.cpp
LSP: (received) textDocument/didSave: file:///d%3A/projects/my_project/src/src_1.cpp
LSP: (invoked) textDocument/didSave: file:///d%3A/projects/my_project/src/src_1.cpp

@sean-mcmanus sean-mcmanus added investigate: repro This issue's repro steps needs to be investigated/confirmed and removed more info needed The issue report is not actionable in its current state labels Mar 13, 2024
@sean-mcmanus
Copy link
Collaborator

@ArnoGW1 Is the id of the LSP: Sending response (id: 812) when formatting gets permanently stuck the id of the formatting message? We have one known IntelliSense deadlock at #12051 which should be fixed with our pending 1.19.8 release. After the formatting gets stuck, are most other operations stuck?

So is the issue just with formatOnSave or do you see an issue when invoking format document too?? I'm seeing 4 formatRange requests being sent when formatOnSave is invoked.

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

@sean-mcmanus
Copy link
Collaborator

@ArnoGW1 When a file has many edits with "editor.formatOnSaveMode": "modificationsIfAvailable", I've gotten VS Code to send 100+ formatRange requests which can take a very long time -- do you want us to create a separate issue to track that or use this issue? I'm unclear whether the issue you're hitting is due to these multiple formatRange requests or if there's a separate issue you want us to track with this issue that can repro with just a single formatRange being processed.

@sean-mcmanus sean-mcmanus removed their assignment Mar 13, 2024
@ArnoGW1
Copy link
Author

ArnoGW1 commented Mar 14, 2024

@ArnoGW1 When a file has many edits with "editor.formatOnSaveMode": "modificationsIfAvailable", I've gotten VS Code to send 100+ formatRange requests which can take a very long time -- do you want us to create a separate issue to track that or use this issue? I'm unclear whether the issue you're hitting is due to these multiple formatRange requests or if there's a separate issue you want us to track with this issue that can repro with just a single formatRange being processed.

There were very few changes, less than 10 lines in a 160-line file. I will answer your other questions when I have time to investigate.

@Colengms Colengms changed the title Formatting with clang-format takes between 0.1 and 20 seconds Implement support format request: provideDocumentRangesFormattingEdits Apr 18, 2024
@Colengms Colengms added this to the 1.21 milestone Apr 18, 2024
@Colengms Colengms added this to Triage in 1.21 via automation Apr 18, 2024
@bobbrow bobbrow added more info needed The issue report is not actionable in its current state and removed more info needed The issue report is not actionable in its current state labels Jun 17, 2024
@bobbrow bobbrow removed this from the 1.21 milestone Jun 17, 2024
@bobbrow bobbrow added this to the On Deck milestone Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Feature: Code Formatting investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service performance
Projects
Status: Triage
1.21
Triage
Development

No branches or pull requests

5 participants