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

Renaming packages/folders does not work #1175

Closed
mrtolkien opened this issue Apr 20, 2021 · 12 comments
Closed

Renaming packages/folders does not work #1175

mrtolkien opened this issue Apr 20, 2021 · 12 comments
Assignees
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@mrtolkien
Copy link

Issue Type: Bug

Renaming packages, both from the symbol or from the folder name, doesn’t work:
video

Test setup:

PACKAGE
├── __init__.py (import SUBPACKAGE)
└── SUBPACKAGE
    └── __init__.py (print("hello"))

This import syntax is right and works properly, and running python PACKAGE/__init__.py or import PACKAGE works.

But trying to refactor SUBPACKAGE in PACKAGE/__init__.py does not work:

  • With Jedi, I get Refactor failed. Unknown Change [<FrameSummary file /home/tolki/.vscode-server/extensions/ms-python.python-2021.4.765268190/pythonFiles/refactor.py, line 380 in watch>, <FrameSummary file /home/tolki/.vscode-server/extensions/ms-python.python-2021.4.765268190/pythonFiles/refactor.py, line 346 in _process_request>, <FrameSummary file /home/tolki/.vscode-server/extensions/ms-python.python-2021.4.765268190/pythonFiles/refactor.py, line 259 in _rename>, <FrameSummary file /home/tolki/.vscode-server/extensions/ms-python.python-2021.4.765268190/pythonFiles/refactor.py, line 128 in refactor>, <FrameSummary file /home/tolki/.vscode-server/extensions/ms-python.python-2021.4.765268190/pythonFiles/refactor.py, line 163 in onRefactor>]
  • With Pylance, I get No result

VS Code version: Code 1.55.2 (3c4e3df9e89829dce27b7b5c24508306b151f30d, 2021-04-13T09:35:57.887Z)
OS version: Windows_NT x64 10.0.19042
Remote OS version: Linux x64 5.4.72-microsoft-standard-WSL2

System Info
Item Value
CPUs AMD Ryzen 7 5800X 8-Core Processor (16 x 3793)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.94GB (17.16GB free)
Process Argv --crash-reporter-id ea62742e-2d7a-4234-b611-aca124c7078b
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu-20.04
OS Linux x64 5.4.72-microsoft-standard-WSL2
CPUs AMD Ryzen 7 5800X 8-Core Processor (16 x 3792)
Memory (System) 25.01GB (19.83GB free)
VM 0%
Extensions (13)
Extension Author (truncated) Version
better-comments aar 2.1.0
bracket-pair-colorizer Coe 1.0.61
auto-close-tag for 0.5.10
remote-containers ms- 0.166.1
remote-wsl ms- 0.54.6
material-icon-theme PKi 4.6.0
path-intellisense chr 2.3.0
vscode-markdownlint Dav 0.40.3
prettier-vscode esb 6.3.2
vscode-docker ms- 1.12.1
python ms- 2021.4.765268190
vscode-pylance ms- 2021.4.1
jupyter ms- 2021.5.745244803
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspyt653:30270858
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstry244:30276681
pythonvsdeb440:30248342
pythonvsded773:30248341
pythonvspyt875:30259475
pythonvsnew554:30281908
pythontb:30283811
openwslfolder:30282073
vspre833cf:30267465
pythonptprofiler:30281270
vshan820:30276952
pythondataviewer:30285071
vscus158cf:30286554

@mrtolkien
Copy link
Author

Also tried doing it fully in Windows, without going through WSL, and I get a very lengthy error with Jedi:

Refactor failed. maximum recursion depth exceeded while calling a Python object [<FrameSummary file c:\Users\garym\.vscode\extensions\ms-python.python-2021.4.765268190\pythonFiles\refactor.py, line 380 in watch>, <FrameSummary file c:\Users\garym\.vscode\extensions\ms-python.python-2021.4.765268190\pythonFiles\refactor.py, line 346 in _process_request>, <FrameSummary file c:\Users\garym\.vscode\extensions\ms-python.python-2021.4.765268190\pythonFiles\refactor.py, line 259 in _rename>, <FrameSummary file c:\Users\garym\.vscode\extensions\ms-python.python-2021.4.765268190\pythonFiles\refactor.py, line 128 in refactor>, <FrameSummary file c:\Users\garym\.vscode\extensions\ms-python.python-2021.4.765268190\pythonFiles\refactor.py, line 156 in onRefactor>, <FrameSummary file C:\Users\garym\AppData\Roaming\Python\Python39\site-packages\rope\refactor\rename.py, line 83 in get_changes>, <FrameSummary file C:\Users\garym\AppData\Roaming\Python\Python39\site-packages\rope\refactor\rename.py, line 214 in _is_local>, <FrameSummary file C:\Users\garym\AppData\Roaming\Python\Python39\site-packages\rope\base\pyobjects.py, line 211 in get_scope>, <FrameSummary file C:\Users\garym\AppData\Roaming\Python\Python39\site-packages\rope\base\pyobjectsdef.py, line 272 in _create_scope>, <FrameSummary file C:\Users\garym\AppData\Roaming\Python\Python39\site-packages\rope\base\pyobjects.py, line 211 in get_scope>, ...

The lines 211 and 272 loop afterwards for hundreds of lines.

@mrtolkien
Copy link
Author

Tried in a completely clean environment with:

  • VSCode Insiders
  • Only the Python extension installed

And I still get the Refactor failed. Unknown Change... error

Second test setup:
Extension version: 2021.4.765268190
VS Code version: Code - Insiders 1.56.0-insider (8aff878db2542eea2dfb571c8bb485118bbb3113, 2021-04-19T05:15:35.845Z)
OS version: Windows_NT x64 10.0.19042

System Info
Item Value
CPUs AMD Ryzen 7 5800X 8-Core Processor (16 x 3793)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.94GB (16.82GB free)
Process Argv
Screen Reader no
VM 0%
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstry244:30244315
pythonvsdeb440:30224570
pythonvsded773:30223139
pythonvspyt875:30259475
pythonvsnew554:30265444
pythontb:30258533
openwslfolder:30278404
vsc_aacf:30263846
vspre833cf:30267465
pythonptprofiler:30281269
vscnewfiletextcf:30288478
vshan820:30276952
pythondataviewer:30285072
vscus158cf:30286554
vscgsv2ct:30286873

@mrtolkien mrtolkien changed the title Renaming packages does not work Renaming packages/folders does not work Apr 20, 2021
@karthiknadig
Copy link
Member

@mrtolkien I will move this request to pylance since this is also not working with pylance.

But for jedi, I recommend that you try with JediLSP as the language server. When using Jedi as a language server it uses rope for refactoring and may not support this. With JediLSP it will use latest jedi itself for refactoring. It may not work with JediLSP either, but the error and stack that you can get will be accurate for the latest Jedi. Once you have those, please file an issue on jedi.

Use this setting in your user settings to get verbose logs from the language servers when using either Pylance or JediLSP. You should see logs in Output > Python Language Server panel.

"python.trace.server": "verbose"

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Apr 20, 2021
@mrtolkien
Copy link
Author

mrtolkien commented Apr 20, 2021

Here is the feedback with JediLSP.

Settings:

    "python.languageServer": "JediLSP",
    "python.analysis.logLevel": "Trace",

Error:

Unknown workspace edit change received:
{
    "oldUri": "file:///home/tolki/dev/rename_test/PACKAGE/SUBPACKAGE",
    "newUri": "file:///home/tolki/dev/rename_test/PACKAGE/SUBPACKAGE_RE",
    "options": {
        "overwrite": true,
        "ignoreIfExists": true
    }
}

@mrtolkien
Copy link
Author

Pylance actually renames the folder/symbol without issuing an error but does not properly propagate the change through the project.

@karthiknadig
Copy link
Member

@mrtolkien I have file a bug on jedi-language-server for this it can be tracked here pappasam/jedi-language-server#134.

Leaving this open for continue pylance discussions here.

@savannahostrowski savannahostrowski added the needs investigation Could be an issue - needs investigation label Apr 21, 2021
@github-actions github-actions bot removed the triage label Apr 21, 2021
@savannahostrowski
Copy link
Contributor

Pylance doesn't currently support this functionality. I'll mark this as an enhancement and leave it open for upvotes.

@savannahostrowski savannahostrowski added enhancement New feature or request needs spec and removed needs investigation Could be an issue - needs investigation labels Apr 21, 2021
@mrtolkien
Copy link
Author

mrtolkien commented Apr 22, 2021

I see, I thought that might have been the case. Is it due to the complexity of the feature or is it due to a lack of interest?

It seems like a pretty crucial feature to me as changing a folder/subpackage name for more clarity can be very useful, but can also have ripples in hundreds of files in big projects and is not really doable by hand.

I would have loved to contribute but unfortunately pylance is closed source, so I will return to Jedi/rope and make sure I can make it work there.

@savannahostrowski
Copy link
Contributor

I'm actually going to leave this open because it'll be a feature we want to look at.

@thistlillo
Copy link

Are there any news on this?

My installation (latest Pylance) on Windows 10, does not reflect folder renaming events. PyLance:

  • still "finds" imports using the old name in renamed folders (that do not exist any more with the old name)
  • does not find the imports with the new name (i.e., using the existing, current name of renamed folders).

@jakebailey
Copy link
Member

As for the original issue, we're working on a number of module related refactorings.

Your issue sounds different, as you aren't trying to use VS Code's rename/refactor system to do that. If you are renaming things in the workspace, we should be detecting that the imports are now unresolved. I would file a new issue.

@judej judej removed the in backlog label Mar 22, 2022
@heejaechang heejaechang self-assigned this Mar 23, 2022
@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Mar 29, 2022
@bschnurr
Copy link
Member

This issue has been fixed in version 2022.3.4, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

8 participants