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

Rename of variables (with rope) fails bluntly if there is a SyntaxError #725

Open
krassowski opened this issue Jan 4, 2020 · 2 comments

Comments

@krassowski
Copy link

If I rename a function or variable in a document which contains a SytnaxError (or IndentationError, or anything else which causes the document not to be a valid Python source code), the rename fails with IndexError: list index out of range. The failing rename is not a problem in itself, but the unclear error may cause distress in users trying to understand what is going on.

Full backtrace is attached here. From what I understand, this is because rope cannot load the file (as it is not a valid Python source) thus lines list remain empty (so the requested position is out of range).

Expected behaviour: an informative error is passed to the client, e.g.

"Rename could not be performed due to a SyntaxError at line X"

Question: should it be solved in pyls or in rope?

Proposed solution: the code in rope_rename.py could by wrapped in try-except to catch rope errors, or (if you advise such) I could fill an issue in rope repository.

References: https://github.com/krassowski/jupyterlab-lsp/pull/115, https://github.com/krassowski/jupyterlab-lsp/pull/127 (while we already got a UX workaround, I thought that reporting it here may help others who implement LSP/use the pyls server).

@krassowski krassowski changed the title Rename of varaibles (with rope) fails bluntly if there is a SyntaxError Rename of variables (with rope) fails bluntly if there is a SyntaxError Jan 4, 2020
@ccordoba12
Copy link
Contributor

the code in rope_rename.py could by wrapped in try-except to catch rope errors

I'm fine with that. Please submit a PR to do it

@mcepl
Copy link

mcepl commented Feb 20, 2020

Or you can send PR to me at python-rope/rope, I will happily consider anything you throw my way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants