Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefanwatt opened this issue May 20, 2023 · 7 comments
Open

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

stefanwatt opened this issue May 20, 2023 · 7 comments

Comments

@stefanwatt
Copy link

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
Copy link
Author

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
Copy link
Author

@nemmtor
Copy link

nemmtor commented Dec 23, 2023

@stefanwatt
Did you find solution?

@diegoulloao
Copy link

Any update on this? Same issue, is very annoying

@Shougo
Copy link

Shougo commented Feb 21, 2024

I think the items are cached...

@Shougo
Copy link

Shougo commented Feb 21, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants