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

textEdit completion item property is not resolved lazily #72

Open
ypomortsev opened this issue Oct 14, 2024 · 7 comments · May be fixed by #75
Open

textEdit completion item property is not resolved lazily #72

ypomortsev opened this issue Oct 14, 2024 · 7 comments · May be fixed by #75

Comments

@ypomortsev
Copy link

ypomortsev commented Oct 14, 2024

rust-analyzer 2024-10-07 and newer does not send the textEdit completion property by if the client can resolve it lazily, introduced in rust-lang/rust-analyzer#18167.

cmp-nvim-lsp includes textEdit in its default_capabilities but does not seem to resolve it lazily, breaking completion:

Observed with textEdit in capabilities:

Screenshot from 2024-10-14 13-20-39
(pressing Enter to complete)
Screenshot from 2024-10-14 13-21-16

Expected, without textEdit in capabilities:

Screenshot from 2024-10-14 13-21-59
(pressing Enter to complete)
Screenshot from 2024-10-14 13-22-22

@kalvinpearce
Copy link

Same issue on my end. A workaround for now is to use the 2024-09-30 release of rust-analyzer.
For those using mason to handle language servers, you can uninstall the current version of rust-analyzer and then run :MasonInstall rust-analyzer@2024-09-30

@ouuan
Copy link

ouuan commented Oct 21, 2024

Another workaround is to not override the default capabilities with require 'cmp_nvim_lsp'.default_capabilities() for rust_analyzer. Not sure about the downsides, though.

@coder3101
Copy link

Actually default_capabilities() take an override table which can be used to override some capabilities. In our case, resolve support properties can be overridden as

require("cmp_nvim_lsp").default_capabilities(
    {
        resolveSupport = {
            properties = {
                "documentation",
                "detail",
                "additionalTextEdits",
                "sortText",
                "filterText",
                "insertText",
                "insertTextFormat",
                "insertTextMode"
            }
        }
    }
)

imo this is better than not having to override the complete cmp default capabilities.

@VVishion
Copy link

VVishion commented Oct 21, 2024

Doing

local capabilities = require("cmp_nvim_lsp").default_capabilities(
    {
        resolveSupport = {
            properties = {
                "documentation",
                "detail",
                "additionalTextEdits",
                "sortText",
                "filterText",
                "insertText",
                "insertTextFormat",
                "insertTextMode"
            }
        }
    }
)

vim.g.rustaceanvim = {
  server = {
    capabilities = capabilities,
...

with the newest ra version didnt work for me

@ypomortsev
Copy link
Author

Repro with minimal config:

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 = {
      { 'neovim/nvim-lspconfig' },
      { 'williamboman/mason-lspconfig.nvim' },
    }
  },
  {
    'hrsh7th/nvim-cmp',
    dependencies = {
      { 'hrsh7th/cmp-buffer' },
      { 'hrsh7th/cmp-nvim-lsp' },
    },
    config = function()
      local cmp = require('cmp')
      cmp.setup({
        sources = cmp.config.sources({
          { name = 'nvim_lsp' },
        }),
        snippet = {
          expand = function(args)
            vim.snippet.expand(args.body)
          end,
        },
        mapping = cmp.mapping.preset.insert({
          ['<C-Space>'] = cmp.mapping.complete(),
          ['<C-e>'] = cmp.mapping.abort(),
          ['<CR>'] = cmp.mapping.confirm({ select = true }),
        }),
      })
    end
  }
})

require('mason').setup()

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

local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities(
  {
    resolveSupport = {
      properties = {
        "documentation",
        "detail",
        "additionalTextEdits",
        "sortText",
        "filterText",
        "insertText",
        -- Remove `textEdit` to fix https://github.com/hrsh7th/cmp-nvim-lsp/issues/72
        "textEdit",
        "insertTextFormat",
        "insertTextMode",
      }
    }
  }
)

local lspconfig = require('lspconfig')

lspconfig.rust_analyzer.setup({
  capabilities = lsp_capabilities,
})

Cargo.toml

[package]
name = "cmp-nvim-lsp-72"
version = "0.1.0"
edition = "2021"
  1. mkdir cmp-nvim-lsp-72 && cd cmp-nvim-lsp-72 && mkdir src && touch src/main.rs
  2. Create init.lua
  3. Create Cargo.toml
  4. vim -u init.lua src/main.rs
  5. Type:
    fn main() {
    Enter
    print
    Ctrl-N (should select println!(…))
    Enter (completes println!(…) but should complete println!(|) with cursor between parens)

@tan-wei
Copy link

tan-wei commented Oct 28, 2024

Hmm, met the same issue now with the latest version (and I can confirm it is the recently commit will cause this problem).

@marcelarie
Copy link

marcelarie commented Oct 30, 2024

Doing
with the newest ra version didnt work for me

@VVishion for me what fixed it with the rustaceanvim config is to use vim.lsp.protocol.make_client_capabilities directly.

vim.g.rustaceanvim = {
   server = {
     capabilities = vim.lsp.protocol.make_client_capabilities(),
   }
}

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

Successfully merging a pull request may close this issue.

7 participants