simrat39 / rust-tools.nvim

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

Debugging not running through hover menu or Debuggables command #380

Open Quessou opened 1 year ago

Quessou commented 1 year ago

No matter if I try to debug a test or a binary, tests seem to never really launch, I don't seem to have any output related to debugging whatsoever. My terminal does not split either. When I launch a binary without debugging, I do have a split that shows the output of both the build and the execution though.

If I launch a Debuggable I just have the following output without anything else happening :

1: build --package gngn --bin gngn
2: test --no-run --package gngn --bin gngn -- tests --nocapture
3: test --no-run --package gngn --bin gngn -- tests::test_toto --exact --nocapture
4: test --no-run --package gngn --all-targets
Type number and <Enter> or click with the mouse (q or empty cancels): 2
Compiling a debug build for debugging. This might take some time...

Debugger never seem to launch, whether I put a breakpoint in the test or not. I, however, manage to debug my main binary by calling require("dap").continue(), using breakpoints and watches.

I use CodeLLDB as my debugger and the part of the configuration related to the DAP looks like this :

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

I tried to change codelldb_path to some dumb value to see if I not messed up my paths obviously, and even though nothing change in the behavior I observed, I kinda ruled it out after triple checking :

local extension_path = vim.fn.stdpath("data") .. "/mason/packages/codelldb/extension"
local codelldb_path = extension_path .. 'adapter/codelldb'
local liblldb_path = extension_path .. 'lldb/lib/liblldb.so'

Even though it seems kind of irrelevant (unless... ?), here are my DAP configurations for Rust. I tried to just remove them, thinking that could override the ones rust-tools use internally, but it didn't change anything apparently :

dap.configurations.rust = {
    {
        name = "Launch default executable",
        type = "codelldb",
        request = "launch",
        program = function()
            vim.fn.jobstart('cargo build')
            local output = execute('find target/debug -name $(basename $(pwd))')
            print(output)
            --find target/debug -name (basename (pwd))
            --return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
            return output --return "/tmp/toto"
        end,
        cwd = "${workspaceFolder}",
        stopOnEntry = false,
        showDisassembly = "never"
    },
    {
        name = "Launch an executable",
        type = "codelldb",
        request = "launch",
        program = function()
            vim.fn.jobstart('cargo build')
            return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
        end,
        cwd = "${workspaceFolder}",
        stopOnEntry = false,
        showDisassembly = "never"
    },
}

Could someone explain to me the dumb thing I missed/the mistake(s) I made in my attempts to make debugging through rust-tools work, please ? :grimacing:

Thanks in advance !!

Quessou commented 1 year ago

Ok so I managed to make it work by editing dap.lua and changing the default debug configuration, replacing rt_lldb by codelldb, is there something that I missed to configure the debugger used without editing directly the source code of rust-tools, or is this the expected behavior ?

salimp2009 commented 1 year ago

Hey , Hoover menu does not give me action either but I can run debuggables and test thru keybinding (thank you helping me to set up for dap in nvim 0.9) This is my key binding ; using lvim (which is nvim based configuration) uses which-key plugin http://neovimcraft.com/plugin/folke/which-key.nvim/index.html . Here is my keybinding set up . Maybe it helps

local status_ok, which_key = pcall(require, "which-key")
if not status_ok then
    return
end

local opts = {
    mode = "n", -- NORMAL mode
    prefix = "<leader>",
    buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
    silent = true, -- use `silent` when creating keymaps
    noremap = true, -- use `noremap` when creating keymaps
    nowait = true, -- use `nowait` when creating keymaps
}

local mappings = {
    C = {
        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" },
    },
    -- R = {
    --  name = "Rust Neotest-Debug",
    --  n = { "<cmd>lua require('neotest').run.run()<cr>", "NeoTest Method Test" },
    --  N = { "<cmd>lua require('neotest').run.run(vim.fn.expand(' % '))<cr>", "NeoTest Class Test" },
    --  d = { "<cmd>lua require('neotest').run.run({strategy = 'dap'})<cr>", "NeoTest Method DAP" },
    --  D = { "<cmd>lua require('neotest').run.run({vim.fn.expand('%'), strategy = 'dap'})<cr>", "NeoTest Class DAP" },
    -- },
}

which_key.register(mappings, opts)

I have not tested neotest on rust yet. rust-tools debuggables show up . and this is my rust-tools setup

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,
            adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
        },
        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)
salimp2009 commented 1 year ago

here is how it starts after pressing Space Cd (but hoover does not work anymore nore code actions)

image and both tests and debugging starts

salimp2009 commented 1 year ago

also code figured out code lenses work too image