Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Fix cached_commands.lua #360

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lua/rust-tools/cached_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ local cache = {
last_runnable = nil,
}

-- @param action
M.set_last_runnable = function(c, r)
-- @param action
M.set_last_runnable = function(choice, result)
cache.last_runnable = { choice, result }
end

-- @param args
-- @param args
M.set_last_debuggable = function(args)
cache.last_debuggable = args
end
Expand All @@ -27,8 +27,8 @@ end

M.execute_last_runnable = function()
local action = cache.last_runnable
if action then
rt.runnables.run_command(action[0], action[1])
if action then
rt.runnables.run_command(action[1], action[2])
else
rt.runnables.runnables()
end
Expand Down
13 changes: 8 additions & 5 deletions lua/rust-tools/runnables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function M.run_command(choice, result)
local command, args, cwd = getCommand(choice, result)

opts.executor.execute_command(command, args, cwd)
rt.cached_commands.set_last_runnable(choice, result)
end

local function handler(_, result)
Expand All @@ -57,11 +58,13 @@ local function handler(_, result)
end
-- get the choice from the user
local options = get_options(result)
vim.ui.select(options, { prompt = "Runnables", kind = "rust-tools/runnables" }, function(_, choice)
M.run_command(choice, result)

rt.cached_commands.set_last_runnable(choice, result)
end)
vim.ui.select(
options,
{ prompt = "Runnables", kind = "rust-tools/runnables" },
function(_, choice)
M.run_command(choice, result)
end
)
end

-- Sends the request to rust-analyzer to get the runnables and handles them
Expand Down