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

Closed
ypomortsev opened this issue Oct 14, 2024 · 12 comments · Fixed by #77
Closed

textEdit completion item property is not resolved lazily #72

ypomortsev opened this issue Oct 14, 2024 · 12 comments · Fixed by #77

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(),
   }
}

@tan-wei
Copy link

tan-wei commented Nov 26, 2024

@marcelarie It works, thanks.

@sineptic
Copy link

For me it works the same as

capabilities = {
    textDocument = {
        completion = {
            completionItem = {
                snippetSupport = false,
            },
        },
    },
},

Now some snippets doesn't work. For example:
"asfd".dbg -> dbg!("asdf")
or
"asfd".ok -> Ok("asdf")

@sineptic
Copy link

sineptic commented Nov 26, 2024

Also issue doesn't occur if first item selected.
https://github.com/user-attachments/assets/69bc4ed6-88d4-413c-bf54-cc3609a135ef

@ttytm
Copy link

ttytm commented Nov 27, 2024

IMHO a very high severity issue. It frequently breaks workflows and often results in unusable completions.

ttytm added a commit to tenxsoydev/nxvim that referenced this issue Nov 27, 2024
causing unintentional confirm on a completion when cycling through items

Ref.: hrsh7th/cmp-nvim-lsp#72
@ogios
Copy link

ogios commented Nov 28, 2024

I think this might be a better solution(temporarily) as to snippetSupport is indeed useful in most circumstances (for me).

  {
    "hrsh7th/nvim-cmp",
    opts = function(_, opts)
      local cmp = require("cmp")
      opts.mapping = vim.tbl_extend("force", opts.mapping, {
        ["<Tab>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), -- This used to be `cmp.SelectBehavior.Insert`
        ["<S-Tab>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
      })
    end,
  },

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