"Format Selection" formats code outside the selected range on Visual Studio Code
Type: Bug
Steps to Reproduce:
- Open a JavaScript file with code that needs formatting.
- Select a portion of the code by dragging the cursor over the desired section.
- Use the "Format Selection" feature, which should format only the selected code.
- Observe the result: instead of formatting only the selected code, the entire function (or the code outside the selection) is also formatted.
- Additionally, if the cursor is placed in the file without any selected range, the "Format Selection" feature behaves as "Format Document," formatting the entire file instead of the selected line or section.
- Expected behavior: Only the selected code range should be formatted.
Thank you.
Extension version: 11.0.0 VS Code version: Code 1.95.1 (65edc4939843c90c34d61f4ce11704f09d3e5cb6, 2024-10-31T05:14:54.222Z) OS version: Windows_NT x64 10.0.19045 Modes: Remote OS version: Linux x64 5.4.0-200-generic
System Info
| Item | Value |
|---|---|
| CPUs | 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz (16 x 2496) |
| 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 webnn: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 63.80GB (33.12GB free) |
| Process Argv | --crash-reporter-id 7ecb8206-fb83-42b0-bcf0-55a8f65214d4 |
| Screen Reader | no |
| VM | 0% |
| Item | Value |
|---|---|
| Remote | SSH: 192.168.56.120 |
| OS | Linux x64 5.4.0-200-generic |
| CPUs | 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz (4 x 0) |
| Memory (System) | 15.62GB (7.16GB free) |
| VM | 100% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
bdiig495:31013172
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
nativerepl1:31139838
refactort:31108082
pythonrstrctxt:31112756
wkspc-onlycs-t:31132770
wkspc-ranged-t:31151552
cf971741:31144450
iacca1:31156133
notype1:31157159
5fd0e150:31155592
dwcopilot:31170013
This issue has been labeled as stale due to inactivity. Reply to keep this issue open.
I saw this issue being reported in the past and it got closed by stale inactivity. It is still happening.
Yeah, facing the same issue. I invoke the "format selection" command explicitly using the command palette and code is formatted outside the selection. Looks like it formats everything to me.
- Extension: 11.0.0
- VSCode: 1.97.2
- Typescript file
- Prettier version: (if the node_modules version is actually used) 3.5.3
No suspicious logs. The rangeStart/End looks about right.
Probably due to https://github.com/prettier/prettier/issues/16140 ?
Will this ever get fixed?
i have the same issue here