-
-
Notifications
You must be signed in to change notification settings - Fork 160
Debugging
Depends on:
- nvim-dap
- lldb-vscode (Comes with an installation of lldb)
- plenary.nvim
rust-tools supports debugging with the help of rust-analyzer. Note that the plugin does not setup nvim-dap for you, but it has its own internal configuration, so if you want a seperate debugging config then you can do it the normal way.
Currently, rust-tools support debugging in two different ways:
Similar to RustRunnables
, this command provides a list of targets that can be debugged, from specific tests to the entire project. Just run the command and chose your target, and the debugging will begin.
Put your cursor on the main function, enter the hover actions menu and select the debug option to debug the entire application.
Put your cursor on any test module or function, enter the hover actions menu and select the debug option to debug the certain test.
Future support for code lenses and telescope/runnables is also planned.
For basic debugging, lldb-vscode is good enough. But if you want something better, you might wanna read this section.
You might have noticed that lldb-vscode does not show types like strings and enums properly, but vscode does. How could this be 🤔 🤔
This is because vscode uses a wrapper over lldb which provides all the goodies. Setting it up for nvim is a bit wack, but thankfully rust-tools provides some utility functions to make the process easier.
Steps:
- Download the CodeLLDB vscode extension.
- Find out where its installed. On linux, it's usually in
$HOME/.vscode/extensions/...
- Update your configuration:
-- Update this path
local extension_path = vim.env.HOME .. '/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/'
local codelldb_path = extension_path .. 'adapter/codelldb'
local liblldb_path = extension_path .. '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 = extension_path .. "adapter\\codelldb.exe"
liblldb_path = extension_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
local opts = {
-- ... other configs
dap = {
adapter = require('rust-tools.dap').get_codelldb_adapter(codelldb_path, liblldb_path)
}
}
-- Normal setup
require('rust-tools').setup(opts)
Alternatively you can install codelldb
using mason. Update then configuration to point to the binaries where mason would download them.
-- Assuming Linux
HOME_PATH = os.getenv("HOME") .. "/"
MASON_PATH = HOME_PATH .. ".local/share/nvim/mason/packages/"
local codelldb_path = MASON_PATH .. "codelldb/extension/adapter/codelldb"
local liblldb_path = MASON_PATH .. "codelldb/extension/lldb/lib/liblldb.so"
local opts = {
-- ... other configs
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
}
}
-- Normal setup
require('rust-tool').setup(opts)