Reputation: 327
I'm having this refactoring issue where I try to rename a function through the option "Rename symbol", but it will take a long time. There's a "progress bar" moving endlessly below the document tab. It is taking around 5 min to do the renaming (also with variable names).
Is this a normal behaviour? I have about 10 python files in the same folder of around ~100 lines. BUT, I have a data folder (belonging to the project) with some 100,000 txt files (which is ignored by git, btw). Are this documents also taken into account? Is there a way to only rename in current file?
VS Code version: 1.25.0 Python extension: 2018.6.0
Thanks, Rafa
Upvotes: 22
Views: 5321
Reputation: 626
I found rope
wasn't ignoring the files in my virtual environment that were in my workspace directory. This created understandably slow refactoring performance. I added my virtual environment folder to the ignored_resources
in the rope
configuration file config.py
. Immediately after making the change, refactoring performance greatly improved.
Take the folder structure below.
-.venv
-.vscode
--.ropeproject
---config.py
---objectdb
--pythonpackage
---__init__.py
---[other files I want to refactor]
-main.py
Assuming .venv
is the name of your virtual environment, for rope
to ignore it, you need to include .venv
in the ignored_resources
list in the rope
config.py
file. Example shown below.
def set_prefs(prefs):
"""This function is called before opening the project"""
# Specify which files and folders to ignore in the project.
# Changes to ignored resources are not added to the history and
# VCSs. Also they are not returned in `Project.get_files()`.
# Note that ``?`` and ``*`` match all characters but slashes.
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
# '.svn': matches 'pkg/.svn' and all of its children
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
'.hg', '.svn', '_svn', '.git', '.tox', '.venv']
Upvotes: 2
Reputation: 2402
same problem here, it's apparently due to the Rope library (which is being used to do the refactoring) not fully supporting Python 3.
Here is an issue of people describing similar problems - https://github.com/Microsoft/vscode-python/issues/52
Update: Using Jedi instead of Microsoft Python Language Server for intellisense seems to have fixed this problem for me. Just add the following entry to your settings.json file :
"python.jediEnabled": true
Upvotes: 9