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

lsp completion items not updating unless I restart the server

Open stefanwatt opened this issue 1 year ago • 7 comments

I don't think the languages matter and it's probably a general issue, but describing the scenario probably helps you understand.

  1. importing a TypeScript function (translate(key:TranslationKey)) from a Svelte file. TranslationKey being defined like so:type TranslationKey = 'foo' | 'bar'
  2. Trigger completion in svelte file by typing translate('b
  3. cmp correctly suggests bar
  4. update type to type TranslationKey = 'foo' | 'bar'| 'baz'
  5. Trigger completion in svelte file again by typing translate('b
  6. cmp still only suggests 'bar' and not 'baz'
  7. :LspRestart svelte
  8. Trigger completion in svelte file again by typing translate('b
  9. cmp correctly suggests 'bar' and 'baz'

I get the same behavior importing the translation file from an Astro component (*.astro). So it's not a problem with the Svelte LS.

stefanwatt avatar May 20 '23 19:05 stefanwatt

Minimal init.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

require("lazy").setup({
  {
    'williamboman/mason.nvim',
    dependencies = {
      -- LSP Support
      { 'neovim/nvim-lspconfig' },
      { 'williamboman/mason-lspconfig.nvim' },
    }
  },
  {
    'hrsh7th/nvim-cmp',
    dependencies = {
      { 'hrsh7th/cmp-buffer' },
      { 'saadparwaiz1/cmp_luasnip' },
      { 'hrsh7th/cmp-nvim-lsp' },
      { 'L3MON4D3/LuaSnip' },
    },
    config = function()
      local cmp = require('cmp')
      local luasnip = require('luasnip')
      cmp.setup({
        sources = cmp.config.sources({
          { name = 'nvim_lsp' },
          { name = 'luasnip' }
        }),
        snippet = {
          expand = function(args)
            require('luasnip').lsp_expand(args.body)
          end,
        },
      })
    end
  }
})

require('mason').setup()

local servers = {
  'svelte',
  'tsserver',
}

local mason_lspconfig = require('mason-lspconfig')
mason_lspconfig.setup({
  ensure_installed = servers,
  automatic_installation = true,
})

local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities()

local lspconfig = require('lspconfig')

for k, server in pairs(servers) do
  lspconfig[server].setup({
    on_attach = function()
    end,
    capabilities = lsp_capabilities,
  })
end

stefanwatt avatar May 22 '23 16:05 stefanwatt

repo to reproduce: https://github.com/stefanwatt/minimal-repro-cmp-nvim-lsp-56

stefanwatt avatar May 22 '23 17:05 stefanwatt

@stefanwatt Did you find solution?

nemmtor avatar Dec 23 '23 12:12 nemmtor

Any update on this? Same issue, is very annoying

diegoulloao avatar Feb 20 '24 21:02 diegoulloao

I think the items are cached...

Shougo avatar Feb 21 '24 01:02 Shougo

It seems cached by LSP server side. Because it is fixed by LSP server restart. Please check it is only reproduced with nvim-cmp.

Shougo avatar Feb 21 '24 09:02 Shougo

Hi everybody,

I wonder if this is related to something I've been dealing with. I added nvim_lsp as a source to cmp.setup but got

# unknown source names
- otter
- nvim_lsp

from :CmpStatus. I noticed (using the above methodology) eventually that these unknown source names would disappear once I wrote the the loaded file. I assume that such behavior is not desired, but I do not know for sure.

acederberg avatar May 12 '24 16:05 acederberg