nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

Function arguments only autocompleted on subsequent completions

Open VVishion opened this issue 1 year ago • 1 comments

FAQ

  • [X] I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

nvim v0.10.2 rust-analyzer 0.3.2146-standalone

Did :Lazy sync, rust-analyzer up-to-date

init.lua

local lazy_path = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazy_path) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazy_path,
  }
end

vim.opt.rtp:prepend(lazy_path)

-- lua/plugin/
require("lazy").setup({ import = "plugin" }, {
  change_detection = {
    notify = false,
  },
})

lua/plugin/lsp-config.lua

return {
  'neovim/nvim-lspconfig',
  lazy = true,
  dependencies = {
    { 'williamboman/mason.nvim', config = true },
    'williamboman/mason-lspconfig.nvim',
    { 'j-hui/fidget.nvim', tag = 'v1.4.5', config = true },
  },
}

lua/plugin/tree-sitter.lua

return {
{
    "nvim-treesitter/nvim-treesitter",
    build = function()
      require("nvim-treesitter.install").update({ with_sync = true })()
    end,
    config = function () 
      local configs = require("nvim-treesitter.configs")

      configs.setup({
          ensure_installed = { "rust" },
          highlight = { enable = true },
          indent = { enable = true },  
        })
    end
}
}

lua/plugin/rust.lua

return {
  'mrcjkb/rustaceanvim',
  version = '^5',
  lazy = false,
  dependencies = {
   'alx741/vim-rustfmt',
  },
}

lua/plugin/completion.lua

return {
  "hrsh7th/nvim-cmp",
  dependencies = {
    "onsails/lspkind.nvim",
    "hrsh7th/cmp-nvim-lsp",
    "hrsh7th/cmp-path",
    "hrsh7th/cmp-buffer",
    "hrsh7th/cmp-nvim-lsp-signature-help",
    { "L3MON4D3/LuaSnip", build = "make install_jsregexp" },
    "saadparwaiz1/cmp_luasnip",
  },
  config = function()
    vim.opt.completeopt = { "menu", "menuone", "noselect", }
    vim.opt.shortmess:append "c"
    
    local lspkind = require "lspkind"
    lspkind.init {}
    
    local cmp = require "cmp"
    
    cmp.setup {
      sources = cmp.config.sources({
        { name = "nvim_lsp" },
        { name = "nvim_lsp_signature_help" },
        { name = "path" },
      }, {
        { name = "buffer", keyword_length = 3 },
      }),
      mapping = {
        ['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
        ['<C-n>'] = cmp.mapping.select_next_item(select_opts),
    
        ['<C-u>'] = cmp.mapping.scroll_docs(-4),
        ['<C-d>'] = cmp.mapping.scroll_docs(4),
    
        ['<C-e>'] = cmp.mapping.abort(),
        ['<C-y>'] = cmp.mapping.confirm({select = true}),
      },
      snippet = {
        expand = function(args)
          require("luasnip").lsp_expand(args.body)
        end,
      },
    }
    
  end
}

Description

Everytime I complete a function call, which I have not autocompleted since the file was opened it appends (…) to the function name. Every subsequent time it autocompletes the whole function signature, similar to some_function(some_arg, another_arg).

Steps to reproduce

Write some rust code

Expected behavior

Always autocomplete the whole function signature with args.

Actual behavior

Autocompletes some_function(some_arg, another_arg) with some_function(…) if it was the first time I autocompleted that particular function.

Additional context

What I noticed: Suggestions which autocomplete successfully only preview their name when selected. Suggestions which autocomplete with (…) also contain it in their preview when selected. Also, function without arguments never autocomplete with (…), but correctly with ().

Also, with coq it seems to happen once for all functions (instead of once for every).

VVishion avatar Oct 19 '24 22:10 VVishion

I also have this problem, but when I revert the version of rust-analyzer to 2024-09-30, the problem is gone; It seems this problem show up at newest version of rust-analyzer.

I tried to set rust-analyzer explicitly to enable: rust-analyzer.completion.callable.snippets (default: "fill_arguments"), but it doesn't work.

And the problem I encountered is:

  1. the completion not fill the function arguments, instead, it fills the argument with ellipsis(…)
  2. It won't show the document of current completion entry

DriedYellowPeach avatar Oct 20 '24 00:10 DriedYellowPeach

Soooo. I investigated your claim and it works now. What I did:

In lua/plugins/lsp-config.lua changed { 'williamboman/mason.nvim', config = true }, to { 'williamboman/mason.nvim', opts = { PATH = "append" } },

This will only use masons binaries if your system doesnt have one (in $PATH).

Then, ran rustup component add rust-src rustup component add rust-analyzer

For info: which rust-analyzer /home/vvishion/.cargo/bin/rust-analyzer rust-analyzer --version rust-analyzer 1.81.0 (eeb90cd 2024-09-04)

VVishion avatar Oct 20 '24 10:10 VVishion