Skip to content

Commit

Permalink
feat(testables): add crate_test_executor option for --all-targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Feb 11, 2024
1 parent c369a48 commit 1ffc8c3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions doc/rustaceanvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/rustaceanvim/config/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions lua/rustaceanvim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions lua/rustaceanvim/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,

Expand Down
3 changes: 2 additions & 1 deletion lua/rustaceanvim/runnables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
Expand Down

0 comments on commit 1ffc8c3

Please sign in to comment.