godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

VSCode: refactor name failed

Open ka23ppa3 opened this issue 4 years ago • 5 comments

When you trying to make auto-name-refactor(F2 by default) of field or method etc. in your game script you will get popup error in VSCode looking like this:

Refactor failed. Syntax error in file <addons/pythonscript/osx-64/lib/Tix8.4.3/pref/WmDefault.py> line <86>: inconsistent use of tabs and spaces in indentation
[<FrameSummary file /home/user/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/refactor.py, line 380 in watch>, <FrameSummary file /home/user/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/refactor.py, line 346 in _process_request>, <FrameSummary file /home/user/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/refactor.py, line 259 in _rename>, <FrameSummary file /home/user/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/refactor.py, line 128 in refactor>, <FrameSummary file /home/user/.vscode-oss/extensions/ms-python.python-2020.10.332292344/pythonFiles/refactor.py, line 156 in onRefactor>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/refactor/rename.py, line 97 in get_changes>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/refactor/rename.py, line 195 in rename_in_module>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/refactor/occurrences.py, line 76 in find_occurrences>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/utils/__init__.py, line 12 in _wrapper>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/refactor/occurrences.py, line 392 in source_code>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/utils/__init__.py, line 12 in _wrapper>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/refactor/occurrences.py, line 412 in pymodule>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/project.py, line 116 in get_pymodule>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/pycore.py, line 142 in resource_to_pyobject>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/pycore.py, line 254 in get_pymodule>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/pyobjectsdef.py, line 162 in __init__>, <FrameSummary file /home/user/.local/lib/python3.9/site-packages/rope/base/pyobjectsdef.py, line 191 in _init_source>]

In the end name-refactor makes no effect. I think I just need to exclude somehow /addons/pythonscript from VSCode view so it will stop trying to look where it doesn`t need but have no clue how to do it properly.

How to reproduce:

  1. Create or open project
  2. Import pythonscript plugin from assetlib
  3. Create your first python-script and open it with VSCode
  4. Declare a variable and try to rename it, using refactor feature(F2 by default)
  5. And now you here...

Sorry if this issue is a little to offtopic but anyway someone else will encounter it I think, so might be helpful to leave it here. Give me a tip. Thanks.

ka23ppa3 avatar May 25 '21 18:05 ka23ppa3

Hi @ka23ppa3

I think you should configure VSCode to ignore the addons/pythonscript folder altogether (you definitely don't want to change things in there, otherwise you may end up with really hard to track bugs !) The most straighforward solution is to use the folders.exclude VSCode setting, another solution is to add this folder to your .gitignore (VSCode takes this file into account if search.useIgnoreFiles is enabled, which is the case by default)

touilleMan avatar May 26 '21 07:05 touilleMan

I think you mean files.exclude, which seems to work for folders too. I created exclusion for **/addons/pythonscript everywhere it was possible and as result this folder disappeared from project view in VSCode... BUT renaming still failing with same error so I have no luck.

I tried next patterns:

**/addons/pythonscript
**/addons/pythonscript/
**/addons/pythonscript/*
**/addons/pythonscript/*/**

ka23ppa3 avatar May 26 '21 19:05 ka23ppa3

When you trying firstly to make refactor in python script you getting popup request to install some "rope"-called python package and only after it installed you can make refactor. I think this package might have no sync with VSCode exclusions and still trying to refactor excluded folders. What do you think?

ka23ppa3 avatar May 26 '21 19:05 ka23ppa3

@ka23ppa3 I don't know how rope works, but I would expect it to fetch its configuration from a configuration file (typically something like rope.ini, setup.cfg or pyproject.toml at the root of the project)

touilleMan avatar Jun 07 '21 13:06 touilleMan

@ka23ppa3 Can you share link how to do debugging python using VSCode? I think if VSCode is working, VS2019 should work? What do you think?

GeorgeS2019 avatar Dec 01 '21 09:12 GeorgeS2019