diff --git a/CHANGELOG.md b/CHANGELOG.md index 55656962..622966db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Testables: Add `tools.crate_test_executor` option for running + crate test suites (`--all-targets`). - Rustc: Do not require a main function, and support the 2024 edition via `unstable-options`. diff --git a/doc/rustaceanvim.txt b/doc/rustaceanvim.txt index ab39a4b4..8bb5d13d 100644 --- a/doc/rustaceanvim.txt +++ b/doc/rustaceanvim.txt @@ -130,6 +130,7 @@ RustaceanToolsOpts *RustaceanToolsOpts* Fields: ~ {executor?} (RustaceanExecutor|executor_alias) The executor to use for runnables/debuggables {test_executor?} (RustaceanExecutor|test_executor_alias) The executor to use for runnables that are tests / testables + {crate_test_executor?} (RustaceanExecutor|test_executor_alias) The executor to use for runnables that are crate test suites (--all-targets) {enable_nextest?} (boolean) Whether to enable nextest. If enabled, `cargo test` commands will be transformed to `cargo nextest run` commands. Defaults to `true` if cargo-nextest is detected. {enable_clippy?} (boolean) Whether to enable clippy checks on save if a clippy installation is detected. Default: `true` {on_initialized?} (fun(health:RustAnalyzerInitializedStatus)) Function that is invoked when the LSP server has finished initializing diff --git a/lua/rustaceanvim/config/check.lua b/lua/rustaceanvim/config/check.lua index 5c5ea78e..464764f9 100644 --- a/lua/rustaceanvim/config/check.lua +++ b/lua/rustaceanvim/config/check.lua @@ -75,6 +75,7 @@ function M.validate(cfg) ok, err = validate('tools', { executor = { tools.executor, { 'table', 'string' } }, test_executor = { tools.test_executor, { 'table', 'string' } }, + crate_test_executor = { tools.crate_test_executor, { 'table', 'string' } }, enable_nextest = { tools.enable_nextest, 'boolean' }, enable_clippy = { tools.enable_clippy, 'boolean' }, on_initialized = { tools.on_initialized, 'function', true }, diff --git a/lua/rustaceanvim/config/init.lua b/lua/rustaceanvim/config/init.lua index 0416949d..b1355abd 100644 --- a/lua/rustaceanvim/config/init.lua +++ b/lua/rustaceanvim/config/init.lua @@ -57,6 +57,7 @@ vim.g.rustaceanvim = vim.g.rustaceanvim ---@class RustaceanToolsOpts ---@field executor? RustaceanExecutor | executor_alias The executor to use for runnables/debuggables ---@field test_executor? RustaceanExecutor | test_executor_alias The executor to use for runnables that are tests / testables +---@field crate_test_executor? RustaceanExecutor | test_executor_alias The executor to use for runnables that are crate test suites (--all-targets) ---@field enable_nextest? boolean Whether to enable nextest. If enabled, `cargo test` commands will be transformed to `cargo nextest run` commands. Defaults to `true` if cargo-nextest is detected. ---@field enable_clippy? boolean Whether to enable clippy checks on save if a clippy installation is detected. Default: `true` ---@field on_initialized? fun(health:RustAnalyzerInitializedStatus) Function that is invoked when the LSP server has finished initializing diff --git a/lua/rustaceanvim/config/internal.lua b/lua/rustaceanvim/config/internal.lua index 6c14ea9f..7f864722 100644 --- a/lua/rustaceanvim/config/internal.lua +++ b/lua/rustaceanvim/config/internal.lua @@ -29,16 +29,22 @@ local function is_lldb_adapter(adapter) return adapter.type == 'executable' end +---@return RustaceanExecutor +local function get_crate_test_executor() + if vim.fn.has('nvim-0.10.0') == 1 then + return executors.background + else + return executors.termopen + end +end + ---@return RustaceanExecutor local function get_test_executor() if package.loaded['rustaceanvim.neotest'] ~= nil then -- neotest has been set up with rustaceanvim as an adapter return executors.neotest - elseif vim.fn.has('nvim-0.10.0') == 1 then - return executors.background - else - return executors.termopen end + return get_crate_test_executor() end ---@class RustaceanConfig @@ -54,6 +60,9 @@ local RustaceanDefaultConfig = { ---@type RustaceanExecutor test_executor = get_test_executor(), + ---@type RustaceanExecutor + crate_test_executor = get_crate_test_executor(), + ---@type boolean enable_nextest = true, diff --git a/lua/rustaceanvim/runnables.lua b/lua/rustaceanvim/runnables.lua index fb6ae94f..c8007679 100644 --- a/lua/rustaceanvim/runnables.lua +++ b/lua/rustaceanvim/runnables.lua @@ -106,7 +106,8 @@ function M.run_command(choice, runnables) end if #args > 0 and (vim.startswith(args[1], 'test') or vim.startswith(args[1], 'nextest')) then - opts.test_executor.execute_command(command, args, cwd, { + local test_executor = vim.tbl_contains(args, '--all-targets') and opts.crate_test_executor or opts.test_executor + test_executor.execute_command(command, args, cwd, { bufnr = vim.api.nvim_get_current_buf(), runnable = runnables[choice], })