diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b7d2fa9..d9f9d60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lua/rustaceanvim/runnables.lua b/lua/rustaceanvim/runnables.lua index e7498f92..3841b828 100644 --- a/lua/rustaceanvim/runnables.lua +++ b/lua/rustaceanvim/runnables.lua @@ -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 @@ -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)