rust-tools.nvim
rust-tools.nvim copied to clipboard
Re-run last Runnable
Hello,
First thing I want to say, very nice plugin! It unifies the whole dev experience.
It would be cool if there were a way to re-run the last ran Runnable (and maybe debuggable). It would be helpful when running tests. Is there a way to do this already (baked in)?
I guess I could pipe in rt.runnables.runnables()
into telescope myself and save the choice into a var.
Thanks!
Edit:
Managed to patch up something ugly to do this:
local rt = require('rust-tools')
local last_runnable = nil
local executor = require("rust-tools/executors").termopen;
local execute_command = executor.execute_command;
executor.execute_command = function (command, args, cwd)
last_runnable = {
command = command,
args = args,
cwd = cwd,
}
return execute_command(command, args, cwd)
end
local run_last = function (...)
if last_runnable == nil then
rt.runnables.runnables(...)
else
executor.execute_command(
last_runnable.command,
last_runnable.args,
last_runnable.cwd
)
end
end
and on_attach
:
on_attach = function(client, bufnr)
-- ...
vim.keymap.set('n', '<leader>cd', rt.debuggables.debuggables, { buffer = bufnr })
vim.keymap.set('n', '<leader>cr', rt.runnables.runnables, { buffer = bufnr })
vim.keymap.set('n', '<leader>cR', run_last, { buffer = bufnr })
-- ...
end