Skip to content

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

@krassowski

Description

@krassowski

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions