microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

Refactor: Extract Method missing when selection starts with a comment #6144

Open xbito opened 3 months ago

xbito commented 3 months ago

Type: Bug

Behaviour

If a selection some python code and hit Ctrl+Shift+r to trigger the Refactor inline menu, the option for Extract Method is not included when the code I selected starts with a comment.

no_extract

If I select the same code, but avoiding the comment then the option for Extract Method appears.

yes_extract

Originally reported at: https://github.com/microsoft/vscode/issues/221217

Steps to reproduce:

  1. Select a section of code starting with a comment
  2. Hit Ctrl + Shift + r to trigger the Refactor inline menu
  3. The option Extract Method will not show up.
  4. Select the same section of code, but this time discarding the initial commented line
  5. Hit the same shortcut to trigger the Refactor iniline menu
  6. See the option for Extract Method now appears

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

Extension version: 2024.10.0 VS Code version: Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729, 2024-07-09T22:06:49.809Z) OS version: Windows_NT x64 10.0.19045 Modes:

User Settings

``` languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |Black Formatter|ms-python.black-formatter|2024.2.0| |Data Wrangler|ms-toolsai.datawrangler|1.4.2| |Dev Containers|ms-vscode-remote.remote-containers|0.375.1| |Django|batisteo.vscode-django|1.15.0| |Docker|ms-azuretools.vscode-docker|1.29.1| |Gemini Code Assist + Google Cloud Code|googlecloudtools.cloudcode|2.14.0| |GitHub Copilot|GitHub.copilot|1.211.0| |GitHub Copilot Chat|GitHub.copilot-chat|0.17.0| |JavaScript Debugger|ms-vscode.js-debug|1.91.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.2| |Markdown All in One|yzhang.markdown-all-in-one|3.6.2| |Pylance|ms-python.vscode-pylance|2024.7.1| |Python|ms-python.python|2024.10.0| |Python Debugger|ms-python.debugpy|2024.8.0| |SQLite Viewer|qwtel.sqlite-viewer|0.5.10| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9| |WSL|ms-vscode-remote.remote-wsl|0.88.2|
System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 x 4008)| |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| |Load (avg)|undefined| |Memory (System)|63.91GB (40.31GB free)| |Process Argv|--crash-reporter-id 20baf653-a07d-462e-803f-add7d33615f4| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 a9j8j154:30646983 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 2e7ec940:31000449 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 chatpanelc:31048052 dsvsc021:30996838 g316j359:31013175 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupytercf:31046870 impr_priority:31082723 ```
rchiodo commented 3 months ago

Thanks for the issue. Not sure why we don't allow a comment to start the selection. It does work with a comment between the lines.