microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.4k stars 12.41k forks source link

Expand and shrink selection around JavaScript `if-elseif-else` statements #56432

Open thernstig opened 10 months ago

thernstig commented 10 months ago

Acknowledgement

Comment

I am unsure if this is a bug or a feature request.

The expand and shrink selection does not work as expected around if-elseif-else statments.

    const a = 1;
    if (a === 1) {
      // foo
    } else if (a === 2) {
      // fii
    } else {
      // fum
    }

Actual behavior

Place the cursor between else if and try to expand selection. It expands like this.

Start image

Middle (few more expansions needed to get here) image

End (only one more expansion from the one above) image

Expected behavior

I expected it to select it like this, starting from Middle above:

image image image image

Additional context

VS Code version: Code 1.84.1 (2b35e1e6d88f1ce073683991d1eff5284a32690f, 2023-11-06T12:35:59.022Z) OS version: Windows_NT x64 10.0.19045 Modes: Remote OS version: Linux x64 5.4.0-166-generic

System Info |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 2611)| |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.69GB (17.72GB free)| |Process Argv|--crash-reporter-id e332dab4-91ea-49d1-8a1f-d8f6e06fa4e1| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|SSH: vm| |OS|Linux x64 5.4.0-166-generic| |CPUs|Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (8 x 2394)| |Memory (System)|31.32GB (23.28GB free)| |VM|50%|
Extensions (35) Extension|Author (truncated)|Version ---|---|--- jest-snippets|and|1.9.1 remote-containers|ms-|0.321.0 remote-ssh|ms-|0.107.0 remote-ssh-edit|ms-|0.86.0 remote-wsl|ms-|0.81.8 vscode-remote-extensionpack|ms-|0.24.0 remote-explorer|ms-|0.4.1 remote-server|ms-|1.5.0 highlight-matching-tag|vin|0.11.0 browserslist|web|1.1.0 vscode-openapi|42C|4.18.6 lit-html|bie|1.11.1 ruff|cha|2023.44.0 vale-vscode|chr|0.17.5 vscode-markdownlint|Dav|0.52.0 vscode-eslint|dba|2.4.2 gitlens|eam|14.4.1 prettier-vscode|esb|10.1.0 code-runner|for|0.12.1 go|gol|0.39.1 path-autocomplete|ion|1.25.0 vscode-azureresourcegroups|ms-|0.7.5 vscode-cosmosdb|ms-|0.20.0 vscode-docker|ms-|1.27.0 vscode-kubernetes-tools|ms-|1.3.15 python|ms-|2023.20.0 vscode-pylance|ms-|2023.11.10 azure-account|ms-|0.11.6 vscode-yaml|red|1.14.0 vscode-direnv|Rub|0.0.2 code-spell-checker|str|3.0.1 vscode-stylelint|sty|1.3.0 even-better-toml|tam|0.19.2 shellcheck|tim|0.34.0 vscode-proto3|zxh|0.5.5
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593:30376534 pythonvs932:30410667 py29gd2263cf:30880073 vscaat:30438848 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyonecf:30548226 2e4cg342:30602488 f6dab269:30613381 showlangstatbar:30737416 pythonfmttext:30731395 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 pythonnosmt12:30797651 pythonidxpt:30866567 pythonnoceb:30805159 synctok:30869157 dsvsc013:30795093 dsvsc014:30804076 dsvsc015:30845448 pythontestfixt:30871694 pythonregdiag2cf:30871583 pyreplss2:30879913 pythonmypyd1:30879173 pythoncet00cf:30874137 pythontbext0:30879054 dsvsc017cf:30880893 aa_t_chat:30882232 ```
DanielRosenwasser commented 10 months ago

If there was an additional level that highlighted just the else

    const a = 1;
    if (a === 1) {
      // foo
    } else [|if (a === 2) {
      // fii
    } else|] {
      // fum
    }

I think that would be a good way to enable what you're looking for, while not being too disruptive in behavior, right?

thernstig commented 10 months ago

@DanielRosenwasser I am not confident in the best way the expansion should work. Though I find the Actual behavior shown unintuitive, the Expected behavor was my subjective opinion on how I thought it should behave. But that needs to be refined.

I am unsure if your proposal is an addition to the Expected behavior I had, or if it is a complete alternative to it.

In short. The Expected behavior should be refined to what would make most sense for developers top want to move/copy.