"Extract variable/method" consistently throws "Error in refactoring:<New line> Canceled" in Output despite actually succeeding unless variable/method name is left at default
See original GitHub issueEnvironment data
- VS Code version: 1.31.0
- Extension version (available under the Extensions sidebar): 2019.1.0
- OS and version: Microsoft Windows [Version 10.0.17134.523]
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.2
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
- Relevant/affected Python packages and their versions:
rope 0.11.0
installed frompip
Note
This issue applied to both “Extract variable” and “Extract method” feature of this extension. Therefore, variables or methods will be referred to as symbols throughout the description
Expected behaviour
No errors should be seen in outputs after extracting a symbol and choosing an appropriate name for the symbol. (since the extraction process actually succeeded)
Actual behaviour
Despite the refactoring being done correctly, an error message is seen in the Outputs tab by selecting “Python” from the drop down menu in that tab:
##########Refactor Output##########
Error in refactoring:
Canceled
after the naming process (VSCode asking you for a name for the new symbol) is complete.
More annoyingly, due to the implementation of an error notification feature (See #3268), an error notification will appear on the corner saying the same thing as in the output:
Cannot perform refactoring using selected element(s). (Canceled)
which is how I’m notified of this issue
Steps to reproduce:
- Create a new Python file in a folder using VSCode
- Type something that can be correctly “extracted”. For example, type
print(1 + 1)
- Note: make sure there are no errors (red squiggly lines) in the Python file. To be sure, you can install and use
pylint
or any other linter to check
- Select the code that can be extracted to a symbol. In the example above, it is
1 + 1
- Right click (Ctrl-click on macOS) and click “Extract variable” or “Extract method” in the menu, either one will reproduce the issue
- Choose a different and new name for the symbol
- The refactoring should be performed correctly (since there are no syntax errors in this file), yet a misleading failure notification will pop up (See Actual Behavior)
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
##########Refactor Output##########
Error in refactoring:
Canceled
That’s the error I described in Actual Behavior. I believed that the error come from the language server that do the actual refactoring after the extraction rather than rope
itself because that message only appears after choosing a name for the symbol, and doesn’t appear at all (neither does the error notification) if you accept the default name, which almost nobody will do.
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging
)
Cannot perform refactoring using selected element(s). (Canceled)
t.onDidNotificationChange @ notificationsAlerts.ts:40
That’s the only line that I think is useful
Edit: The outputs seems misleading as it implies that the refactoring “fails”, but just to clarify that the refactoring is actually done correctly (with the appropriate symbol extracted) I posted this issue solely because the error notification is too annoying.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:8 (1 by maintainers)
Top GitHub Comments
This is indeed a reproduceable bug, and I have trapped it in the debugger. Note that I reproduced this using Python 3.7 and
rope==0.11.0
andrope==0.12.0
.See file
src\client\refactor\proxy.ts
(called fromsrc\client\providers\simpleRefactorProvider.ts
) on line 124. At first glance, thehandleStdError
method seems to be expecting JSON values (line 136) but we are receiving text lines instead.My Repro
1 + 1
expression and right-click on the highlighted block, choose 'Extract Method`.Expected results
A method is created and contains
return 1 + 1
.Observed results
The command is issued on line 105 of
src\client\refactor\proxy.ts
:But results in stderr string on line 124 of
src\client\refactor\proxy.ts
this.handleStdError(output.out);
:Which ultimately raises the error:
This works in Jedi behind LSP and rope is being removed in our 2021.10 release.