Skip to content

Commit

Permalink
feat(lsp): support falling back to ui select for testables/runnables (
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Mar 8, 2024
1 parent c1cd072 commit 19f1217
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.12.0] - 2024-03-08

### Fixed

- DAP: `:RustLsp! debuggables` not falling back to UI select
when no debuggable is found.

### Added

- LSP: Support falling back to UI select for `:RustLsp! runnables`
and `:RustLsp! testables`.

## [4.11.1] - 2024-03-04

### Fixed
Expand Down
33 changes: 25 additions & 8 deletions lua/rustaceanvim/cached_commands.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local M = {}

---@alias RARunnablesChoice { choice: integer, runnables: RARunnable[] }

---@class CommandCache
local cache = {
---@type RARunnableArgs | nil
last_debuggable = nil,
---@type { choice: integer, runnables: RARunnable[] }
---@type RARunnablesChoice
last_runnable = nil,
---@type { choice: integer, runnables: RARunnable[] }
---@type RARunnablesChoice
last_testable = nil,
}

Expand All @@ -33,34 +35,49 @@ M.set_last_debuggable = function(args)
cache.last_debuggable = args
end

M.execute_last_debuggable = function()
---@param executableArgsOverride? string[]
M.execute_last_debuggable = function(executableArgsOverride)
local args = cache.last_debuggable
if args then
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
args.executableArgs = executableArgsOverride
end
local rt_dap = require('rustaceanvim.dap')
rt_dap.start(args)
else
local debuggables = require('rustaceanvim.commands.debuggables')
debuggables()
debuggables.debuggables(executableArgsOverride)
end
end

---@param choice RARunnablesChoice
---@param executableArgsOverride? string[]
local function override_executable_args_if_set(choice, executableArgsOverride)
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
choice.runnables[choice.choice].args.executableArgs = executableArgsOverride
end
end

M.execute_last_testable = function()
M.execute_last_testable = function(executableArgsOverride)
local action = cache.last_testable
local runnables = require('rustaceanvim.runnables')
if action then
override_executable_args_if_set(action, executableArgsOverride)
runnables.run_command(action.choice, action.runnables)
else
runnables.runnables { tests_only = true }
runnables.runnables(executableArgsOverride, { tests_only = true })
end
end

M.execute_last_runnable = function()
---@param executableArgsOverride? string[]
M.execute_last_runnable = function(executableArgsOverride)
local action = cache.last_runnable
local runnables = require('rustaceanvim.runnables')
if action then
override_executable_args_if_set(action, executableArgsOverride)
runnables.run_command(action.choice, action.runnables)
else
runnables.runnables()
runnables.runnables(executableArgsOverride)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lua/rustaceanvim/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ local rustlsp_command_tbl = {
end,
},
debuggables = {
---@param args string[]
---@param opts vim.api.keyset.user_command
impl = function(args, opts)
if opts.bang then
require('rustaceanvim.cached_commands').execute_last_debuggable()
require('rustaceanvim.cached_commands').execute_last_debuggable(args)
else
require('rustaceanvim.commands.debuggables').debuggables(args)
end
Expand Down Expand Up @@ -89,7 +90,7 @@ local rustlsp_command_tbl = {
---@param opts vim.api.keyset.user_command
impl = function(args, opts)
if opts.bang then
require('rustaceanvim.cached_commands').execute_last_runnable()
require('rustaceanvim.cached_commands').execute_last_runnable(args)
else
require('rustaceanvim.runnables').runnables(args)
end
Expand Down

0 comments on commit 19f1217

Please sign in to comment.