simrat39 / rust-tools.nvim

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

How to fix: proc macro `openapi` not expanded: Proc-macro dylib loading failed: unsupported metadata version 7 [unresolved-proc-macro] #348

Closed xbladesub closed 1 year ago

xbladesub commented 1 year ago

I started to getting this, not sure probably after update to new nightly version.

image

My config:

    local codelldb_path = '/Users/nshv/.vscode/extensions/vadimcn.vscode-lldb-1.8.1/adapter/codelldb'
    local liblldb_path = '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB' -- MacOS: This may be .dylib

    local executors = require "rust-tools.executors"
    require("rust-tools").setup {
        dap = {
            adapter = require('rust-tools.dap').get_codelldb_adapter(
                codelldb_path, liblldb_path)
        },
        tools = {
            executor = executors.toggleterm,
            runnables = {
                use_telescope = true,
            },
            autoSetHints = true,
            inlay_hints = { show_parameter_hints = true },
            hover_actions = { auto_focus = true }
        },
        server = {
            cmd = { "/Users/nshv/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rust-analyzer" },
            on_attach = function(client, bufnr)
                require("lvim.lsp").common_on_attach(client, bufnr)
                local rt = require "rust-tools"
                vim.keymap.set("n", "<leader>lA", rt.code_action_group.code_action_group, { buffer = bufnr })
            end,
            on_init = require("lvim.lsp").common_on_init,
            settings = {
                ["rust-analyzer"] = {
                    rustfmt = {
                        extraArgs = { "+nightly", },
                    },
                    -- diagnostics = {
                    --  disabled = { "unresolved-proc-macro" },
                    lens = {
                        enable = true,
                    },
                    checkOnSave = {
                        command = "clippy",
                    },
                },
            },
        },
    }

versions:

rustup check
stable-aarch64-apple-darwin - Up to date : 1.67.1 (d5a82bbd2 2023-02-07)
nightly-aarch64-apple-darwin - Up to date : 1.70.0-nightly (900c35403 2023-03-08)
rustup - Up to date : 1.25.2
rustup show
Default host: aarch64-apple-darwin
rustup home:  /Users/nshv/.rustup

installed toolchains
--------------------

stable-aarch64-apple-darwin
nightly-2021-02-16-aarch64-apple-darwin
nightly-aarch64-apple-darwin (default)
bpf
sbf

active toolchain
----------------

nightly-aarch64-apple-darwin (default)
rustc 1.70.0-nightly (900c35403 2023-03-08)
which rust-analyzer
/Users/nshv/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rust-analyzer
ok-nick commented 1 year ago

I have the same issue using thiserror::Error on the latest nightly build

jcrist1 commented 1 year ago

I upgraded my rust version and got similar errors for bevy::{AsBindGroup, TypeUuid}, sqlx::FromRow and serde::{Serialize, Deserialize}. Currently using astro-nvim 3.1.1. with the following config init.lua in my user config

return {
  lsp = {
    setup_handlers = {
      -- add custom handler
      rust_analyzer = function(_, opts) require("rust-tools").setup { server = opts } end
    },
  },
  plugins = {
    {
      "simrat39/rust-tools.nvim", -- add lsp plugin
      opts = {
        ['rust-analyzer'] = {
          procMacro = {
            enable = true,
          },
        }
      },
    },
    {
      "williamboman/mason-lspconfig.nvim",
      opts = {
        ensure_installed = { "rust_analyzer" },
      },
    },
    {
      "nvim-treesitter/nvim-treesitter",
      opts = {
        ensure_installed = { "lua" },
      },
    },
  },
}
philss commented 1 year ago

I got the same error and it was fixed after upgrading rust-analyzer - I'm using version 0.3.1443-standalone now. The process was the same as installing: https://rust-analyzer.github.io/manual.html#installation

jcrist1 commented 1 year ago

Can confirm. Upgrading rust-analyzer seems to fix the problem.

rrichardson commented 1 year ago

I have just upgraded rust-analyzer to the latest and still get this problem. I've also run rustup update and cargo clean

$ rust-analyzer --version
rust-analyzer 0.3.1489-standalone
rrichardson commented 1 year ago

I managed to get mine to work by telling rust-tools/lsp to use the rust-analyzer installed by rustup component add --toolchain X rust-analyzer
Copying that rust-analyzer elsewhere into my path wasn't enough. I had to reference it in place. So I tweaked my nvim config a bit.

In the future I will figure out a way to make it adapt to the currently active toolchain. For now, this'll have to do.

rt.setup({
    server = {
        cmd = { '/home/me/.rustup/toolchains/nightly-2023-04-20-x86_64-unknown-linux-gnu/bin/rust-analyzer' },
        ...
utkarshgupta137 commented 1 year ago

I managed to get mine to work by telling rust-tools/lsp to use the rust-analyzer installed by rustup component add --toolchain X rust-analyzer Copying that rust-analyzer elsewhere into my path wasn't enough. I had to reference it in place. So I tweaked my nvim config a bit.

In the future I will figure out a way to make it adapt to the currently active toolchain. For now, this'll have to do.

rt.setup({
    server = {
        cmd = { '/home/me/.rustup/toolchains/nightly-2023-04-20-x86_64-unknown-linux-gnu/bin/rust-analyzer' },
        ...

Since rustup 1.26, they've added a proxy for rust-analyzer, so you probably don't need to specify the complete path.

rrichardson commented 1 year ago

Since rustup 1.26, they've added a proxy for rust-analyzer, so you probably don't need to specify the complete path.

Interestingly. If I change command to rust-analyzer or remove cmd = { '...' } entirely... the `dylib loading failed" error returns.

I wonder if this is somehow related to our usage of rust-toolchain.toml at the root of our project, changing the toolchain to nightly. Maybe the proxy isn't working correctly for rust-analyzer-proc-macro-srv ?