microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.47k stars 28.1k forks source link

Sort Lines Ascending command messes up trailing commas #201316

Open droddy opened 6 months ago

droddy commented 6 months ago

Type: Bug

When using the 'Sort Lines Ascending' command on a list of strings with trailing commas, the commas are sorted along with the strings. This can lead to incorrect formatting for languages like TypeScript. The expected behavior is that the commas should be corrected after the list is sorted. Co-Pilot is able to sort lines AND correct any messed up/missing trailing commas.

VS Code version: Code 1.85.1 (0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2, 2023-12-13T09:49:37.021Z) OS version: Windows_NT x64 10.0.22621 Modes: Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2 Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz (4 x 2112)| |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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.81GB (11.88GB free)| |Process Argv|--file-uri vscode-remote://wsl%2Bdebian_moved/home/droddy/prweb-front-end.code-workspace --crash-reporter-id 24ba618d-f344-4214-929f-c23edc77ca0a| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|WSL: Debian_moved| |OS|Linux x64 5.15.133.1-microsoft-standard-WSL2| |CPUs|Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz (4 x 2111)| |Memory (System)|15.53GB (9.14GB free)| |VM|0%| |Item|Value| |---|---| |Remote|WSL: Debian_moved| |OS|Linux x64 5.15.133.1-microsoft-standard-WSL2| |CPUs|Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz (4 x 2111)| |Memory (System)|15.53GB (9.14GB free)| |VM|0%|
Extensions (39) Extension|Author (truncated)|Version ---|---|--- html-snippets|abu|0.2.1 asp-net-core-snippet-pack|adr|1.51.0 firebase-snippets|has|0.0.1 mysql-syntax|jak|1.3.1 remote-containers|ms-|0.327.0 remote-ssh|ms-|0.107.1 remote-ssh-edit|ms-|0.86.0 remote-wsl|ms-|0.81.8 vscode-remote-extensionpack|ms-|0.25.0 remote-explorer|ms-|0.4.1 remote-server|ms-|1.5.0 twind-intellisense|sas|0.2.1 vscode-sql-formatter|adp|1.4.4 aws-toolkit-vscode|ama|2.4.0 npm-intellisense|chr|1.4.5 regex|chr|0.4.0 vscode-eslint|dba|2.4.2 xml|Dot|2.5.1 gitlens|eam|14.6.1 prettier-vscode|esb|10.1.0 vscode-yarn|gam|2.1.0 copilot|Git|1.143.0 copilot-chat|Git|0.11.1 polacode-2019|jef|0.6.1 vscode-docker|ms-|1.28.0 vscode-kubernetes-tools|ms-|1.3.15 cmake-tools|ms-|1.16.32 cpptools|ms-|1.18.5 cpptools-extension-pack|ms-|1.3.0 live-server|ms-|0.4.13 vsliveshare|ms-|1.0.5900 advanced-new-file|pat|1.2.2 vscode-yaml|red|1.14.0 vs-code-prettier-eslint|rve|5.1.0 twind-intellisense|sas|0.2.1 vscode-fileutils|sle|3.10.3 vsfire|tob|1.4.1 cmake|twx|0.0.17 vscode-aws-console|vsc|0.0.5 (2 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 py29gd2263:30899288 vsclangdf:30486550 c4g48928:30535728 dsvsc012:30540252 azure-dev_surveyone:30548225 282f8724:30602487 f6dab269:30613381 a9j8j154:30646983 showlangstatbar:30737416 962ge761:30917236 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 welcomedialog:30910333 pythonnosmt12:30797651 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 dsvsc013:30795093 dsvsc014:30804076 dsvsc015:30845448 pythontestfixt:30902429 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 aa_t_chat:30882232 dsvsc019:30917259 ```
IllusionMH commented 6 months ago

This command is not language aware, so this is unfortunate but expected. Not sure if there are plans to change that.

However, if you have trailing commas enabled in external formatters, e.g. Prettier then it doesn't matter - all lines have it. And TS should report syntax errors in most or all cases otherwise.