neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
83.69k stars 5.72k forks source link

LSP: rust_analyzer: -32802: server cancelled the request #30985

Closed vikulikov closed 3 days ago

vikulikov commented 1 month ago

Problem

editor is being interrupted with message rust_analyzer: -32802: server cancelled the request while typing on every keystroke after the latest updates of rust-analyzer

Steps to reproduce using "nvim -u minimal_init.lua"

Just start typing in main.rs inside fn main() {|} of cargo new --bin test_project

local pattern = 'rust'
local cmd = { '/opt/homebrew/bin/rust-analyzer' }
-- Add files/folders here that indicate the root of a project
local root_markers = { 'Cargo.toml' }
-- Change to table with settings if required
local settings = vim.empty_dict()

vim.api.nvim_create_autocmd('FileType', {
    pattern = pattern,
    callback = function(args)
        local match = vim.fs.find(root_markers, { path = args.file, upward = true })[1]
        local root_dir = match and vim.fn.fnamemodify(match, ':p:h') or nil
        vim.lsp.start({
            name = 'rust-analyzer',
            cmd = cmd,
            root_dir = root_dir,
            settings = settings
        })
    end
})

Expected behavior

There is no this message with interrupt

Nvim version (nvim -v)

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382

Language server name/version

rust-analyzer 0.0.0 (3b3a87fe9 2024-10-27)

Operating system/version

macos 15.1

Log file

No response

MariaSolOs commented 4 weeks ago

Seems to be caused by https://github.com/rust-lang/rust-analyzer/pull/18408/commits/8eef1c52757f1ca444792b22433e696364a2b86d

MariaSolOs commented 4 weeks ago

Hmm I can't reproduce this using rust-analyzer 1.84.0-nightly (1e4f10ba 2024-10-29) and master Neovim. Are you sure that no further settings are needed?

https://github.com/user-attachments/assets/f0df20f4-76b3-4387-bfe8-352dec59acc7

glepnir commented 4 weeks ago

rust-analyzer 0.0.0 (468b5cd43 2024-10-29)

Image

vikulikov commented 4 weeks ago

https://github.com/user-attachments/assets/4d6a6048-25ab-473f-82d5-05d24ecca966

Sorry, thought gif from glepnir was enough. I guess something fast should happen to trigger cancellation of the previous request to the server. fast typing or typing before server has indexed the project

And the configuration is really basic as attached in the issue description

Jesse-Bakker commented 4 weeks ago

Workaround to ignore the ServerCancelled error:


for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do
    local default_diagnostic_handler = vim.lsp.handlers[method]
    vim.lsp.handlers[method] = function(err, result, context, config)
        if err ~= nil and err.code == -32802 then
            return
        end
        return default_diagnostic_handler(err, result, context, config)
    end
end
samvv commented 4 weeks ago

I can confirm that this issue affects me too. Using Arch and the problem was introduced after doing pacman -Suy.

The workaround of @Jesse-Bakker worked for me, thanks!

youshitsune commented 2 weeks ago

For now I have downgraded version of rust-analyzer to 2024-10-14

filmil commented 2 weeks ago

Where would one put this workaround?

I added that into the section of init.lua that installs an OnAttach hook for the LSP subsystem. I add all per-buffer LSP setup in the callback for that hook.

praveenperera commented 2 weeks ago

Where would one put this workaround?

I put it in my ftplugin/rust: https://github.com/praveenperera/dotfiles/commit/3cd2a6d3c1cc05f3c8f6245e3d918e350859a33a

getcisher commented 1 week ago

seem the lua script that put in init.lua not work on astronvim. Downgrade is seem work for me.

praveenperera commented 1 week ago

@getcisher im using astronvim and putting it in after works, see comment above.

vext01 commented 1 week ago

I have the same on today's Rust and today's Neovim.

vext01 commented 1 week ago

In :LspLog I see errors like this:

2024-11-20T10:32:20.078245832Z ERROR synthetic syntax

Not sure if it's related?

chardoncs commented 1 week ago

Same here, but it will be gone seconds later.

Image

I use nvim-lspconfig and cmp in my config instead and it's simpler:

local lspconfig = require("lspconfig")
local capabilities = require('cmp_nvim_lsp').default_capabilities()

local function default_config(t)
    for _, name in ipairs(t) do
      lspconfig[name].setup {
        capabilities = capabilities,
      }
    end
  end

default_config({
   -- SNIP --
    "rust_analyzer",
   -- SNIP --
})
glepnir commented 1 week ago

Please do not add duplicate problem descriptions! Issue reports already have a clear minimal reproduce config to reproduce the problem and before comments has a workaround as temporary solution.

JonoPrest commented 1 week ago

Same is happening to me, downgrading to 2024-10-14 seems to remove the problem 👍🏼