simrat39 / rust-tools.nvim

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

The selected configuration references adapter `rt_lldb`, but dap.adapters.rt_lldb is undefined #268

Closed TornaxO7 closed 1 year ago

TornaxO7 commented 2 years ago

I'm getting the following error, if I run: RustDebuggables. What do I have to do to fix this?

The selected configuration references adapter `rt_lldb`, but dap.adapters.rt_lldb is undefined

This is how I start rust tools:

local rt = require("rust-tools")

local function loader(on_attach, capabilities)
    rt.setup({
        server = {
            on_attach = on_attach,
            capabilities = capabilities,
        },
    })
end

return loader
DavidePatria commented 1 year ago

have you solved this?

TornaxO7 commented 1 year ago

Sadly not :(

DavidePatria commented 1 year ago

by naming the configuration as the plugin wants the problem gets solved

dap.configurations.rust = {{
  name = 'Launch file',
  type = 'rt_lldb',
  request = 'launch',

  program =
    function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,

  cwd = '${workspaceFolder}',
  stopOnEntry = false,
  args = {},
}}
iceaway commented 1 year ago

I had the same issue. I tried changing line 131 in dap.lua from type = "rt_lld" to type = "rust", that solved it for me but I did not want to change the plugin source code. So I did more digging and figured out that I had to change my call to the setup function of rust-tools, and include this:

dap = {
    adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path)
  }

In dap.lua dap.adapters.rt_lldb will be set to whatever rt.config.options.dap.adapter is set to (which is where the stuff above ends up in).

So my complete call to setup() for rust-tools now looks like this (I use mason to handle LSP servers):

local rt = require("rust-tools")

local mason_registry = require("mason-registry")
local codelldb_root = mason_registry.get_package("codelldb"):get_install_path() .. "/extension/"
local codelldb_path = codelldb_root .. "adapter/codelldb"
local liblldb_path = codelldb_root .. "lldb/lib/liblldb.so"

local opts = {
  server = {
    on_attach = function(_, bufnr)
      -- Rust specific keymaps
      local wk = require('which-key')
      wk.register({
        r = {
          name = "Rust",
          -- Hover actions
          h = { rt.hover_actions.hover_actions, "Hover Actions", buffer = bufnr },
          -- Code action groups
          a = { rt.code_action_group.code_action_group, "Code Action", buffer = bufnr },
          -- Display runnables (run, test, check etc)
          r = { vim.cmd.RustRunnables, "Runnables" },
          -- Display debuggables (run, test, check etc)
          d = { vim.cmd.RustDebuggables, "Runnables" },
        }
      }, { prefix = "<leader>" })
      -- Add generic shortcuts
      custom_on_attach(_, bufnr)
    end,
  },
  dap = {
    adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path)
  }
}

rt.setup(opts)
TornaxO7 commented 1 year ago

@iceaway May I ask where you got this line from?

local mason_registry = require("mason-registry")

I can't find mason-registry in the docs of mason.

TornaxO7 commented 1 year ago

Wait, it works now. Yaaaaaaaaaaay

Thank you for your answer @iceaway it works and thank you for the trick with mason-registry!

iceaway commented 1 year ago

Wait, it works now. Yaaaaaaaaaaay

Thank you for your answer @iceaway it works and thank you for the trick with mason-registry!

Glad I could help! Not entirely sure where I got that line from, I came across it when I was looking for solutions.