LSP Rename makes me rename things twice

I’m not sure quite why, and am not familiar enough with how LSPs work in Neovim to even start debugging this. (On a small tangent: how does one debug Neovim configs, in general? Is there a way to put breakpoints in Lua functions and step through them, line by line?)

My issue is that using vim.lsp.buf.rename() requires me to enter in the new variable name I’d like twice in a row. After entering it the first time, the “prompt” is reset to the old variable name, and I have to enter the new name again.

The language I’m having issues with is Python – I have Pyright and Jedi installed through nvim-lsp-installer, so I thought maybe the issue was having two LSPs simultaneously. But when I comment out the lines initializing Pyright, nothing changes.

I’m unfortunately confused enough that I’m not even sure which files would be helpful to share here, so let me know if there are functions or parts of my config you’d like to see. I’d really be grateful for help, even just for hints in the right direction!

@vergesslicherich

How about doing this?

:LspUninstall Pyright

@kay-adamof After uninstalling pyright, I am only prompted to rename once, but after pressing enter, no renaming happens, and I see the error message:

Language server couldn't provide rename result

After reinstalling pyright and uninstalling Jedi, renaming works completely as it’s supposed to. Maybe my solution is just not to use Jedi? I honestly can’t remember why I installed both it and pyright…

@vergesslicherich

No.

Though I’ve tried “jedi” pattern , in my case “jedi” works correctly.

Here my all code:

local ensure_packer = function()
	local fn = vim.fn
	local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
	if fn.empty(fn.glob(install_path)) > 0 then
		fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
		vim.cmd([[packadd packer.nvim]])
		return true
	end
	return false
end

local packer_bootstrap = ensure_packer()

require("packer").startup(function(use)
	use("wbthomason/packer.nvim")
	use("neovim/nvim-lspconfig")
	if packer_bootstrap then
		require("packer").sync()
	end
end)
local on_attach = function(client, bufnr)
	vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
	local bufopts = { noremap = true, silent = true, buffer = bufnr }
	vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
end

local lsp_flags = {
	debounce_text_changes = 150,
}
-- require("lspconfig").pyright.setup({
-- 	on_attach = on_attach,
-- 	flags = lsp_flags,
-- })
require("lspconfig").jedi_language_server.setup({
	on_attach = on_attach,
	flags = lsp_flags,
})

I also installed both “jedi” and “pyright”:

pip install pyright
pip install -U jedi-language-server

I wonder why your “jedi” doesn’t work…

I’m having a similar problem and all I have is a command:

vim.api.nvim_create_user_command('RenameIdentifier', function()
	vim.lsp.buf.rename()
end, {})

However, if I run :lua vim.lsp.buf.rename() manually I only need to enter the rename once so it doesn’t seem to be the LSP server… more like the command being registered twice or something like that.

I don’t have the same issue. I copied-pasted your code in my config. And
it runs as is: rename it once.