simrat39 / rust-tools.nvim

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

debuggin not working with neovim 0.9.0 #378

Closed salimp2009 closed 1 year ago

salimp2009 commented 1 year ago

Hi, I have been using rust-tool with lvim (which is a nvim based config) with nvim 0.8. Since switched to nvim 0.9.0 debugging is not working. All other functionality works ; like expand macro, runnables but when I start debuggable with a simple rust code it gives an error as attached image Did any one test it with neovim 0.9.0. It seems that issue is nvim-dap. Here is my rust.lua config. the keymapping is in after/ftplugin but the whole setup is below. It is also on github ; https://github.com/salimp2009/deskmach_config/blob/main/lvim/.config/lvim/lua/user/lsp/languages/rust.lua

vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" })

local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "lvim/mason/")
-- print(mason_path)
local codelldb_adapter = {
    type = "server",
    port = "${port}",
    executable = {
        command = mason_path .. "bin/codelldb",
        -- command = "/usr/bin/lldb-vscode",
        args = { "--port", "${port}" },
        -- On windows you may have to uncomment this:
        -- detached = false,
    },
}

pcall(function()
    require("rust-tools").setup({
        tools = {
            executor = require("rust-tools/executors").termopen, -- can be quickfix or termopen
            reload_workspace_from_cargo_toml = true,
            runnables = {
                use_telescope = true,
            },
            inlay_hints = {
                auto = true,
                only_current_line = false,
                show_parameter_hints = true,
                parameter_hints_prefix = "<-",
                other_hints_prefix = "=>",
                max_len_align = false,
                max_len_align_padding = 1,
                right_align = false,
                right_align_padding = 7,
                highlight = "Comment",
            },
            hover_actions = {
                border = "rounded",
            },
            on_initialized = function()
                vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter", "CursorHold", "InsertLeave" }, {
                    pattern = { "*.rs" },
                    callback = function()
                        local _, _ = pcall(vim.lsp.codelens.refresh)
                    end,
                })
            end,
        },
        dap = {
            adapter = codelldb_adapter,
        },
        server = {
            on_attach = function(client, bufnr)
                require("lvim.lsp").common_on_attach(client, bufnr)
                local rt = require("rust-tools")
                vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr })
            end,

            capabilities = require("lvim.lsp").common_capabilities(),
            settings = {
                ["rust-analyzer"] = {
                    lens = {
                        enable = true,
                    },
                    checkOnSave = {
                        enable = true,
                        command = "clippy",
                    },
                },
            },
        },
    })
end)

lvim.builtin.dap.on_config_done = function(dap)
    dap.adapters.codelldb = codelldb_adapter
    dap.configurations.rust = {
        {
            name = "Launch file",
            type = "codelldb",
            request = "launch",
            program = function()
                return vim.fn.input({ "Path to executable: ", vim.fn.getcwd(), "/" .. "file" })
                -- return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
                -- return vim.fn.input("Path to executable: " .. vim.fn.getcwd() .. "/" .. "file")
            end,
            cwd = "${workspaceFolder}",
            stopOnEntry = false,
        },
    }
end

vim.api.nvim_set_keymap("n", "<m-d>", "<cmd>RustOpenExternalDocs<Cr>", { noremap = true, silent = true })

-- lvim.builtin.which_key.mappings["R"] = {
--  name = "Rust",
--  r = { "<cmd>RustRunnables<Cr>", "Runnables" },
--  t = { "<cmd>lua _CARGO_TEST()<cr>", "Cargo Test" },
--  m = { "<cmd>RustExpandMacro<Cr>", "Expand Macro" },
--  c = { "<cmd>RustOpenCargo<Cr>", "Open Cargo" },
--  p = { "<cmd>RustParentModule<Cr>", "Parent Module" },
--  d = { "<cmd>RustDebuggables<Cr>", "Debuggables" },
--  v = { "<cmd>RustViewCrateGraph<Cr>", "View Crate Graph" },
--  R = {
--      "<cmd>lua require('rust-tools/workspace_refresh')._reload_workspace_from_cargo_toml()<Cr>",
--      "Reload Workspace",
--  },
--  o = { "<cmd>RustOpenExternalDocs<Cr>", "Open External Docs" },
--  y = { "<cmd>lua require'crates'.open_repository()<cr>", "[crates] open repository" },
--  P = { "<cmd>lua require'crates'.show_popup()<cr>", "[crates] show popup" },
--  i = { "<cmd>lua require'crates'.show_crate_popup()<cr>", "[crates] show info" },
--  f = { "<cmd>lua require'crates'.show_features_popup()<cr>", "[crates] show features" },
--  D = { "<cmd>lua require'crates'.show_dependencies_popup()<cr>", "[crates] show dependencies" },
-- }
duanyuluo commented 1 year ago

same issue...waiting

Quessou commented 1 year ago

I'm not a contributor to rust-tools or anything like that, but if I can allow myself to make a suggestion after investigating on my side and trying to fix the issue :

I managed to solve this exact error by removing the whole codelldb_adapter definition, and add the following section to the configuration of rust-tools

    dap =
    {
        adapter = function()
            return require('rust-tools.dap').get_codelldb_adapter(
                codelldb_path, liblldb_path)
        end
    }

It is suggested here : https://github.com/simrat39/rust-tools.nvim/wiki/Debugging Hope it does help you :)

salimp2009 commented 1 year ago

I'm not a contributor to rust-tools or anything like that, but if I can allow myself to make a suggestion after investigating on my side and trying to fix the issue :

I managed to solve this exact error by removing the whole codelldb_adapter definition, and add the following section to the configuration of rust-tools

    dap =
    {
        adapter = function()
            return require('rust-tools.dap').get_codelldb_adapter(
                codelldb_path, liblldb_path)
        end
    }

It is suggested here : https://github.com/simrat39/rust-tools.nvim/wiki/Debugging Hope it does help you :)

I will try thank you. Report here

salimp2009 commented 1 year ago

I'm not a contributor to rust-tools or anything like that, but if I can allow myself to make a suggestion after investigating on my side and trying to fix the issue :

I managed to solve this exact error by removing the whole codelldb_adapter definition, and add the following section to the configuration of rust-tools

    dap =
    {
        adapter = function()
            return require('rust-tools.dap').get_codelldb_adapter(
                codelldb_path, liblldb_path)
        end
    }

It is suggested here : https://github.com/simrat39/rust-tools.nvim/wiki/Debugging Hope it does help you :)

I tried but I got the same error ; nothing changed image

salimp2009 commented 1 year ago

UPDATE : This did work after I made a change in my mason_path. Awesome . So I am closing this ; and recommend setting described in It is suggested here : https://github.com/simrat39/rust-tools.nvim/wiki/Debugging

I used the recommended setting and updated the path as required (OS: Linux)

local package_path = vim.env.HOME .. "/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/"
local codelldb_path = mason_path .. "bin/codelldb"
local liblldb_path = mason_path .. "packages/codelldb/extension/lldb/lib/liblldb"
local this_os = vim.loop.os_uname().sysname

-- The path in windows is different
if this_os:find("Windows") then
    codelldb_path = package_path .. "adapter\\codelldb.exe"
    liblldb_path = package_path .. "lldb\\bin\\liblldb.dll"
else
    -- The liblldb extension is .so for linux and .dylib for macOS
    liblldb_path = liblldb_path .. (this_os == "Linux" and ".so" or ".dylib")
end

also the dap settings

        dap = {
            -- adapter= codelldb_adapter,
            adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
        },
salimp2009 commented 1 year ago

Here are some working shots it even goes into assembly when you go into macros image

image

thank you so much. rust-tool is awesome and thnk you @Quessou