Lsp rename does not work

Hello, I have LSP configured with pyright for python development and vim.lsp.buf.rename() does not work. When I run :lua vim.lsp.buf.rename(), it asks for the new name, but doesn’t change the name, and I don’t get any error either.

Configured servers: pyright
Neovim logs at: /Users/foo/.cache/nvim/lsp.log

1 client(s) attached to this buffer: pyright

  Client: pyright (id 1)
    root:      /private/tmp/servicenow-tmp
    filetypes: python
    cmd:       pyright-langserver --stdio



1 active client(s):

  Client: pyright (id 1)
    root:      /private/tmp/servicenow-tmp
    filetypes: python
    cmd:       pyright-langserver --stdio



Clients that match the filetype python:

  Config: pyright
    cmd:               pyright-langserver --stdio
    cmd is executable: True
    identified root:   /private/tmp
    custom handlers:

This is what lsp log shows

[ DEBUG ] 2021-07-06T08:08:03-0700 ] ...l/Cellar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp.lua:895 ]  "LSP[pyright]"  "client.request"        1       "textDocument/rename"   {  newName = "api2",  position = {    character = 4,    line = 15  },  textDocument = {    uri = "file:///private/tmp/servicenow-tmp/server.py"  }}   <function 1>    1
[ DEBUG ] 2021-07-06T08:08:03-0700 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:395 ]  "rpc.send.payload"      {  id = 6,  jsonrpc = "2.0",  method = "textDocument/rename",  params = {    newName = "api2",    position = {      character = 4,      line = 15    },    textDocument = {      uri = "file:///private/tmp/servicenow-tmp/server.py"    }  }}
[ DEBUG ] 2021-07-06T08:08:03-0700 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:496 ]  "decoded"       {  id = 6,  jsonrpc = "2.0",  result = vim.NIL}
[ DEBUG ] 2021-07-06T08:08:03-0700 ] ...neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/handlers.lua:434 ]  "default_handler"       "textDocument/rename"   {  bufnr = 1,  client_id = 1}

I’m not sure what to tell you other than that I use vim.lsp.buf.rename() daily with pyright, and do not have this issue. There’s a short lag period while pyright is indexing your brought when sending rename will not invoke an immediate action.

Thanks for the response. Anything I can do to debug this further? This git repo only has one file so there’s not much to index.

Steps:

  1. mkdir my_temp_project && cd my_temp_project && git init
  2. touch main.py
  3. nvim main.py, add the following
def test():
    pass

def main():
    test()
  1. put cursor on test() and call vim.lsp.buf.rename() → test1

Does that not work for you?

Yes, that does work. Also when I copy the python file from my project to this directory, the rename works. My project directory has venv configured, but rename doesn’t work whether or not I have sourced bin/activate.

When I delete these directories and files (related to venv), the rename works.
bin/
lib/
include/
pyvenv.cfg

Which seems strange to me. I have tried deleting one directory at a time and rename doesn’t work until all four (bin/, lib/, include/, pyvenv.cfg) are deleted

I’m guessing pyright is busy indexing all of your virtual environment’s libraries which is why rename doesn’t work initially.

hm, I have nvim session running since I started this post. Can I kick off indexing from the command line somehow, so i can be sure that indexing is complete?

What is strange is that when I delete bin/, include/, and lib/ it still doesn’t work when I have pyvenv.cfg in the root directory. There is nothing to index at that point.

I added an empty file to the example directory by touch my_temp_project/pyvenv.cfg, and rename stops working in main.py