Skip to content

Commit

Permalink
feat(testables): prettier selection options
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 31, 2024
1 parent 3015cf3 commit 28d8c92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
buffer to which the LSP client is attached.
If you do so, `tools.test_executor` will default to a new `'neotest'`
executor, which will use neotest to run `testables` or `runnables` that are tests.
- `:RustLsp testables`: Prettier selection options.

## [4.3.0] - 2024-01-31

Expand Down
26 changes: 23 additions & 3 deletions lua/rustaceanvim/runnables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,33 @@ end
---@field cargoExtraArgs string[]
---@field executableArgs string[]

---@param option string
---@return string
local function prettify_test_option(option)
for _, prefix in pairs { 'test-mod ', 'test ', 'cargo test -p ' } do
if vim.startswith(option, prefix) then
return option:sub(prefix:len() + 1, option:len()):gsub('%-%-all%-targets', '(all targets)') or option
end
end
return option:gsub('%-%-all%-targets', '(all targets)') or option
end

---@param result RARunnable[]
---@param executableArgsOverride? string[]
local function get_options(result, executableArgsOverride)
---@param opts RunnablesOpts
---@return string[]
local function get_options(result, executableArgsOverride, opts)
local option_strings = {}

for _, runnable in ipairs(result) do
local str = runnable.label .. (executableArgsOverride and ' -- ' .. table.concat(executableArgsOverride, ' ') or '')
local str = runnable.label
.. (
executableArgsOverride and #executableArgsOverride > 0 and ' -- ' .. table.concat(executableArgsOverride, ' ')
or ''
)
if opts.tests_only then
str = prettify_test_option(str)
end
table.insert(option_strings, str)
end

Expand Down Expand Up @@ -117,7 +137,7 @@ local function mk_handler(executableArgsOverride, opts)
end

-- get the choice from the user
local options = get_options(runnables, executableArgsOverride)
local options = get_options(runnables, executableArgsOverride, opts)
vim.ui.select(options, { prompt = 'Runnables', kind = 'rust-tools/runnables' }, function(_, choice)
---@cast choice integer
M.run_command(choice, runnables)
Expand Down

0 comments on commit 28d8c92

Please sign in to comment.