simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.16k stars 158 forks source link

Error loading in nvim 0.8.0 #261

Closed jknoetzke closed 2 years ago

jknoetzke commented 2 years ago

Removing rust-tools plugin removes this error.. This was working fine for me in 0.7.x

Not sure if this is a nvim error or an error in this plugin. If it's in nvim, let me know and I'll open a issue with nvim

Error executing vim.schedule lua callback: ...llar/neovim/0.8.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:289: Cannot serialise function: type not supported
stack traceback:
        [C]: in function 'encode'
        ...llar/neovim/0.8.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:289: in function 'notify'
        ...w/Cellar/neovim/0.8.0/share/nvim/runtime/lua/vim/lsp.lua:1333: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue
LSP[id=1] client has shut down while creating progress report
Press ENTER or type command to continue
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-004.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.0/share/nvim"
nahuakang commented 2 years ago

I'm experiencing the same issue. May I ask why you closed it and, if applicable, how you resolved your issue? Thanks.

nahuakang commented 2 years ago

Ok, it seems using the following inside init.lua file would be fine:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = function(_, bufnr)
      -- Hover actions
      vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
      -- Code action groups
      vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
    end,
  },
})

But if you were following a blog like this one and do the following, you might get the error:

local rt = {
    server = {
        settings = {
            on_attach = function(_, bufnr)
                -- Hover actions
                vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
                -- Code action groups
                vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
                require 'illuminate'.on_attach(client)
            end,
            ["rust-analyzer"] = {
                checkOnSave = {
                    command = "clippy"
                }, 
            },
        }
    },
}
require('rust-tools').setup(rt)

At least this is how I resolved the issue on my terminal.

Integralist commented 2 years ago

What about the settings field? How do you configure ["rust-analyzer"]? Or is it just the on_attach that needs to be moved up out of the settings field?

nahuakang commented 2 years ago

@Integralist Hey Mark, I ignored the settings field and do it like this:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = function(_, bufnr)
      -- Hover actions
      vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
      -- Code action groups
      vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
    end,
    ["rust-analyzer"] = {
        checkOnSave = {
            command = "clippy"
        },
    },
  },
})

Checking the official README, it doesn't seem that settings field is needed 🤔

Integralist commented 2 years ago

@nahuakang ah nice! Thanks 🙂