question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

renaming package fails with unknown workspace edit error

See original GitHub issue
Unknown workspace edit change received:
{
    "oldUri": "file:///c:/GIT/repro/renaming/somepackage",
    "newUri": "file:///c:/GIT/repro/renaming/package1",
    "options": {
        "overwrite": true,
        "ignoreIfExists": true
    }
}

Repro steps:

  1. Create this package layout image

somemodule.py: contents

def do_something():
    print('something')

myscript.py: contents

from somepackage.somemodule import do_something

def run():
    do_something()

run()
  1. Place cursor on somepackage in myscript.py, and rename it.

LSP messages trace:


[Trace - 6:29:50 PM] Sending request 'textDocument/rename - (8)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/GIT/repro/renaming/myscript.py"
    },
    "position": {
        "line": 0,
        "character": 13
    },
    "newName": "package1"
}


[Trace - 6:29:50 PM] Received response 'textDocument/rename - (8)' in 8ms.
Result: {
    "documentChanges": [
        {
            "textDocument": {
                "uri": "file:///c:/GIT/repro/renaming/myscript.py",
                "version": 0
            },
            "edits": [
                {
                    "range": {
                        "start": {
                            "line": 0,
                            "character": 5
                        },
                        "end": {
                            "line": 0,
                            "character": 9
                        }
                    },
                    "newText": ""
                },
                {
                    "range": {
                        "start": {
                            "line": 0,
                            "character": 16
                        },
                        "end": {
                            "line": 0,
                            "character": 16
                        }
                    },
                    "newText": "1"
                },
                {
                    "range": {
                        "start": {
                            "line": 0,
                            "character": 47
                        },
                        "end": {
                            "line": 0,
                            "character": 47
                        }
                    },
                    "newText": "\r"
                },
                {
                    "range": {
                        "start": {
                            "line": 1,
                            "character": 0
                        },
                        "end": {
                            "line": 1,
                            "character": 0
                        }
                    },
                    "newText": "\r"
                },
                {
                    "range": {
                        "start": {
                            "line": 2,
                            "character": 10
                        },
                        "end": {
                            "line": 2,
                            "character": 10
                        }
                    },
                    "newText": "\r"
                },
                {
                    "range": {
                        "start": {
                            "line": 3,
                            "character": 18
                        },
                        "end": {
                            "line": 3,
                            "character": 18
                        }
                    },
                    "newText": "\r"
                },
                {
                    "range": {
                        "start": {
                            "line": 4,
                            "character": 0
                        },
                        "end": {
                            "line": 4,
                            "character": 0
                        }
                    },
                    "newText": "\r"
                },
                {
                    "range": {
                        "start": {
                            "line": 5,
                            "character": 0
                        },
                        "end": {
                            "line": 5,
                            "character": 0
                        }
                    },
                    "newText": "\r"
                }
            ]
        },
        {
            "oldUri": "file:///c:/GIT/repro/renaming/somepackage",
            "newUri": "file:///c:/GIT/repro/renaming/package1",
            "options": {
                "overwrite": true,
                "ignoreIfExists": true
            }
        }
    ]
}

Proably just missing edit kind:


        {
            "kind": "rename",  // <------------- This field is required and is missing.
            "oldUri": "file:///c:/GIT/repro/renaming/somepackage",
            "newUri": "file:///c:/GIT/repro/renaming/package1",
            "options": {
                "overwrite": true,
                "ignoreIfExists": true
            }
        }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
karthiknadigcommented, May 23, 2021

So it looks like we need a fix in jedi-language-server, we will need to pass kind to RenameFile here: https://github.com/pappasam/jedi-language-server/blob/b408d6852921c98f5bbaf9942bbbf40f4cd30f07/jedi_language_server/text_edit_utils.py#L60-L66

With the above issue fixed, it looks like jedi itself might need a fix, trying to rename a namespace package leads to this error. The rename works fine if it has a __init__.py image

[Trace - 12:40:43 AM] Sending request 'textDocument/rename - (123)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/GIT/repro/demo/renametest/demo.py"
    },
    "position": {
        "line": 0,
        "character": 11
    },
    "newName": "newname"
}


ERROR:pygls.protocol:Failed to handle request 123 textDocument/rename work_done_token=None text_document=TextDocumentIdentifier(uri='file:///c%3A/GIT/repro/demo/renametest/demo.py') position=0:11 new_name='newname'
Traceback (most recent call last):
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\pygls\protocol.py", line 342, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\pygls\protocol.py", line 271, in _execute_request
    method_name, method_type, msg_id, handler(params))
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\jedi_language_server\server.py", line 433, in rename
    refactoring = jedi_script.rename(
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\jedi\api\__init__.py", line 578, in rename
    return refactoring.rename(self._inference_state, definitions, new_name)
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\jedi\api\refactoring\__init__.py", line 146, in rename
    file_renames.add(_calculate_rename(p, new_name))
  File "c:\Users\Karthik Nadig\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\lib\jedilsp\jedi\api\refactoring\__init__.py", line 129, in _calculate_rename
    dir_ = path.parent
AttributeError: 'NoneType' object has no attribute 'parent'
0reactions
anu-kacommented, May 28, 2021

@pappasam I have created a fix for this. Please have a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown workspace edit change received: #1385 - GitHub
The error message is: Unknown workspace edit change received Script file looks like: #load ".paket/load/netcoreapp3.1/Snowflake.
Read more >
NPM: ENOENT: no such file or directory, rename
When I got this error I looked for all running instances of node in my task manager (i use process explorer ...
Read more >
Specifying Dependencies - The Cargo Book
Note: crates.io does not allow packages to be published with dependencies on other registries. Specifying dependencies from git repositories. To depend on a ......
Read more >
Known issues - Relativity Documentation
When a user opens a workspace with no categorization sets and open a document, they might see a failed network call (404). Yes....
Read more >
Troubleshoot issues in Omnichannel for Customer Service
Errors occur when I try to open Omnichannel for Customer Service or Customer Service workspace with Omnichannel enabled. Issue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found