Skip to content

Commit b0c03f0

Browse files
author
Marc Jakobi
committed
feat(lsp): cache runnables and debuggables run with commands/code lenses
1 parent 5cca364 commit b0c03f0

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [3.17.0] - 2024-01-20
10+
11+
### Added
12+
13+
- Cache runnables and debuggables run with commands/code lenses.
14+
915
## [3.16.3] - 2024-01-20
1016

1117
### Changed

ftplugin/rust.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ end
1010

1111
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
1212
local runnables = require('rustaceanvim.runnables')
13+
local cached_commands = require('rustaceanvim.cached_commands')
14+
cached_commands.set_last_runnable(1, command.arguments)
1315
runnables.run_command(1, command.arguments)
1416
end
1517

@@ -26,9 +28,12 @@ end
2628

2729
vim.lsp.commands['rust-analyzer.debugSingle'] = function(command)
2830
local overrides = require('rustaceanvim.overrides')
29-
overrides.sanitize_command_for_debugging(command.arguments[1].args.cargoArgs)
31+
local args = command.arguments[1].args
32+
overrides.sanitize_command_for_debugging(args)
33+
local cached_commands = require('rustaceanvim.cached_commands')
34+
cached_commands.set_last_debuggable(args)
3035
local rt_dap = require('rustaceanvim.dap')
31-
rt_dap.start(command.arguments[1].args)
36+
rt_dap.start(args)
3237
end
3338

3439
lsp.start()

lua/rustaceanvim/cached_commands.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ local M = {}
44
local cache = {
55
---@type RADebuggableArgs | nil
66
last_debuggable = nil,
7-
---@type { choice: integer, runnable: RARunnable }
7+
---@type { choice: integer, runnables: RARunnable[] }
88
last_runnable = nil,
99
}
1010

1111
---@param choice integer
12-
---@param runnable RARunnable
13-
M.set_last_runnable = function(choice, runnable)
12+
---@param runnables RARunnable[]
13+
M.set_last_runnable = function(choice, runnables)
1414
cache.last_runnable = {
1515
choice = choice,
16-
runnable = runnable,
16+
runnables = runnables,
1717
}
1818
end
1919

@@ -37,7 +37,7 @@ M.execute_last_runnable = function()
3737
local action = cache.last_runnable
3838
local runnables = require('rustaceanvim.runnables')
3939
if action then
40-
runnables.run_command(action.choice, action.runnable)
40+
runnables.run_command(action.choice, action.runnables)
4141
else
4242
runnables.runnables()
4343
end

lua/rustaceanvim/runnables.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020
---@field cargoExtraArgs string[]
2121
---@field executableArgs string[]
2222

23-
---@param result RARunnable
23+
---@param result RARunnable[]
2424
local function get_options(result)
2525
local option_strings = {}
2626

@@ -70,7 +70,7 @@ function M.run_command(choice, runnables)
7070
opts.executor.execute_command(command, args, cwd)
7171
end
7272

73-
---@param result RARunnable
73+
---@param result RARunnable[]
7474
local function handler(_, result)
7575
if result == nil then
7676
return

0 commit comments

Comments
 (0)