Skip to content

Commit 19f1217

Browse files
authored
feat(lsp): support falling back to ui select for testables/runnables (#277)
1 parent c1cd072 commit 19f1217

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ 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+
## [4.12.0] - 2024-03-08
10+
11+
### Fixed
12+
13+
- DAP: `:RustLsp! debuggables` not falling back to UI select
14+
when no debuggable is found.
15+
16+
### Added
17+
18+
- LSP: Support falling back to UI select for `:RustLsp! runnables`
19+
and `:RustLsp! testables`.
20+
921
## [4.11.1] - 2024-03-04
1022

1123
### Fixed

lua/rustaceanvim/cached_commands.lua

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
local M = {}
22

3+
---@alias RARunnablesChoice { choice: integer, runnables: RARunnable[] }
4+
35
---@class CommandCache
46
local cache = {
57
---@type RARunnableArgs | nil
68
last_debuggable = nil,
7-
---@type { choice: integer, runnables: RARunnable[] }
9+
---@type RARunnablesChoice
810
last_runnable = nil,
9-
---@type { choice: integer, runnables: RARunnable[] }
11+
---@type RARunnablesChoice
1012
last_testable = nil,
1113
}
1214

@@ -33,34 +35,49 @@ M.set_last_debuggable = function(args)
3335
cache.last_debuggable = args
3436
end
3537

36-
M.execute_last_debuggable = function()
38+
---@param executableArgsOverride? string[]
39+
M.execute_last_debuggable = function(executableArgsOverride)
3740
local args = cache.last_debuggable
3841
if args then
42+
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
43+
args.executableArgs = executableArgsOverride
44+
end
3945
local rt_dap = require('rustaceanvim.dap')
4046
rt_dap.start(args)
4147
else
4248
local debuggables = require('rustaceanvim.commands.debuggables')
43-
debuggables()
49+
debuggables.debuggables(executableArgsOverride)
50+
end
51+
end
52+
53+
---@param choice RARunnablesChoice
54+
---@param executableArgsOverride? string[]
55+
local function override_executable_args_if_set(choice, executableArgsOverride)
56+
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
57+
choice.runnables[choice.choice].args.executableArgs = executableArgsOverride
4458
end
4559
end
4660

47-
M.execute_last_testable = function()
61+
M.execute_last_testable = function(executableArgsOverride)
4862
local action = cache.last_testable
4963
local runnables = require('rustaceanvim.runnables')
5064
if action then
65+
override_executable_args_if_set(action, executableArgsOverride)
5166
runnables.run_command(action.choice, action.runnables)
5267
else
53-
runnables.runnables { tests_only = true }
68+
runnables.runnables(executableArgsOverride, { tests_only = true })
5469
end
5570
end
5671

57-
M.execute_last_runnable = function()
72+
---@param executableArgsOverride? string[]
73+
M.execute_last_runnable = function(executableArgsOverride)
5874
local action = cache.last_runnable
5975
local runnables = require('rustaceanvim.runnables')
6076
if action then
77+
override_executable_args_if_set(action, executableArgsOverride)
6178
runnables.run_command(action.choice, action.runnables)
6279
else
63-
runnables.runnables()
80+
runnables.runnables(executableArgsOverride)
6481
end
6582
end
6683

lua/rustaceanvim/commands/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ local rustlsp_command_tbl = {
3131
end,
3232
},
3333
debuggables = {
34+
---@param args string[]
3435
---@param opts vim.api.keyset.user_command
3536
impl = function(args, opts)
3637
if opts.bang then
37-
require('rustaceanvim.cached_commands').execute_last_debuggable()
38+
require('rustaceanvim.cached_commands').execute_last_debuggable(args)
3839
else
3940
require('rustaceanvim.commands.debuggables').debuggables(args)
4041
end
@@ -89,7 +90,7 @@ local rustlsp_command_tbl = {
8990
---@param opts vim.api.keyset.user_command
9091
impl = function(args, opts)
9192
if opts.bang then
92-
require('rustaceanvim.cached_commands').execute_last_runnable()
93+
require('rustaceanvim.cached_commands').execute_last_runnable(args)
9394
else
9495
require('rustaceanvim.runnables').runnables(args)
9596
end

0 commit comments

Comments
 (0)