Rust-analyzer autocompletes functions with an ellipsis instead of parameters

Hello all,

rust-analyzer typically omits the full function signature in the LSP autocompletion entries it provides (which I presume is due to rust-analyzer.completion.fullFunctionSignatures.enable being set to false by default.)

However, for some reason, this omission of the signature persists beyond accepting the autocompletion, which leads to the function being inserted as foo(...), with only an ellipsis instead of parameters and my cursor being behind the closing bracket. I can not jump through and replace anything and must manually delete the bracket and the ellipsis, and then type out the parameters.

Image of autocompletion only inserting ellipsis

I use neovim as my editor with nvim-cmp for completion and luasnip as my snippet engine.

The fault could naturally lie in either of these two, but with the exact same setup but using clang and a .c file instead, it works flawlessly, which leads me to believe this is a problem with rust-analyzer.

My configuration for these plugins is as follows (it is managed my lazy.nvim)

local emulate = function(is_shift)
	local api = vim.api;
	local replaced = api.nvim_replace_termcodes(is_shift and "<S-Tab>" or "<Tab>", true, false, true)
	api.nvim_feedkeys(replaced, 'n', false)
end

local keymaps = function()
	local ls = require "luasnip"
	local keys = {
		{ "<Tab>",   mode = { "i" }, function() if ls.expand_or_jumpable() then ls.expand_or_jump() else emulate(false) end end },
		{ "<Tab>",   mode = { "s" }, function() if ls.jumpable(1) then ls.jump(1) else emulate(false) end end },
		{ "<S-Tab>", mode = { "i" }, function() if ls.jumpable(-1) then ls.jump(-1) else emulate(true) end end },
		{ "<S-Tab>", mode = { "s" }, function() if ls.jumpable(-1) then ls.jump(-1) else emulate(true) end end },
	}

	return keys
end

return {
	{
		"L3MON4D3/LuaSnip",
		build = "make install_jsregexp",
		config = function()
			require("luasnip.loaders.from_vscode").lazy_load()
			require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets/" })
			require("luasnip").config.set_config({
				enable_autosnippets = true,
				store_selection_keys = "<Tab>"
			})
		end,
		dependencies = { "rafamadriz/friendly-snippets" },
		keys = keymaps
	},
	{
		"hrsh7th/nvim-cmp",
		event = "InsertEnter",

		dependencies = {
			"saadparwaiz1/cmp_luasnip",
			"hrsh7th/cmp-nvim-lsp",
		},

		config = function()
			local cmp = require("cmp")

			cmp.setup({
				completion = { autocomplete = false },
				snippet = {
					expand = function(args)
						require("luasnip").lsp_expand(args.body)
					end,
				},
				preselect = cmp.PreselectMode.None,
				sources = {
					{ name = "luasnip" },
					{ name = "nvim_lsp" },
				},
				mapping = {
					["<CR>"] = cmp.mapping.confirm({ select = false }),
					["<C-e>"] = cmp.mapping.close(),
					["<C-Space>"] = cmp.mapping.complete(),
					["<C-j>"] = cmp.mapping.select_next_item(),
					["<C-k>"] = cmp.mapping.select_prev_item(),
				},
			})
		end,
	},
}

I would greatly appreciate any help on this matter :people_hugging:

Cheers,
hyperpastel

I had exactly same issue and it seems like cmp-nvim-lsp's bug which is caused by recent rust-analyzer update.

For now, the problem can be fixed by using a version of rust-analyzer earlier than 2024-10-07.

1 Like