hrsh7th / cmp-nvim-lsp

nvim-cmp source for neovim builtin LSP client
MIT License
1.31k stars 52 forks source link

lsp completion items not updating unless I restart the server #56

Open stefanwatt opened 1 year ago

stefanwatt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

nemmtor commented 11 months ago

@stefanwatt Did you find solution?

diegoulloao commented 9 months ago

Any update on this? Same issue, is very annoying

Shougo commented 9 months ago

I think the items are cached...

Shougo commented 9 months ago

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

acederberg commented 6 months ago

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.