Skip to content

Commit 1c6b0a5

Browse files
committed
feat(neotest): Expose doctests on Neotest summary window
The current neotest integration reports any 'test' runnable as a valid position, except for 'doctests'. This commit introduces logic necessary to also expose 'doctests' as part of the summary, so it can be visualized and trigger. It tries to approach it with the minimal changes, so exported labels follows the same name convention as test runnables, without indication they are doctests on the summary window. This can be changed if necessary. In order for neotest to consider these items part of the tree, we must also return a 'pos' with `pos.type = 'file'`, otherwhise those test items would not have a parent, and it prevents being displayed. This is done by reporting a 'file' always, but I'm not sure what is the reason behind returning only if `#namespaces > 0`.
1 parent 4987d41 commit 1c6b0a5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## Unreleased
10+
11+
### Added
12+
- Neotest: Expose doctests on `:Neotest summary` window
13+
914
## [4.7.5] - 2024-02-20
1015

1116
### Fixed

lua/rustaceanvim/neotest/init.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,16 @@ NeotestAdapter.discover_positions = function(file_path)
184184
end
185185
sort_positions(sorted_positions)
186186

187-
if #namespaces > 0 then
188-
local file_pos = {
189-
id = file_path,
190-
name = vim.fn.fnamemodify(file_path, ':t'),
191-
type = 'file',
192-
path = file_path,
193-
range = { 0, 0, max_end_row, 0 },
194-
-- use the shortest namespace for the file runnable
195-
runnable = namespaces[#namespaces].runnable,
196-
}
197-
table.insert(sorted_positions, 1, file_pos)
198-
end
187+
local file_pos = {
188+
id = file_path,
189+
name = vim.fn.fnamemodify(file_path, ':t'),
190+
type = 'file',
191+
path = file_path,
192+
range = { 0, 0, max_end_row, 0 },
193+
-- use the shortest namespace for the file runnable
194+
runnable = #namespaces > 0 and namespaces[#namespaces].runnable or nil,
195+
}
196+
table.insert(sorted_positions, 1, file_pos)
199197

200198
return require('neotest.types.tree').from_list(sorted_positions, function(x)
201199
return x.name

lua/rustaceanvim/neotest/trans.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function M.runnable_to_position(file_path, runnable)
2727
type = 'dir'
2828
elseif vim.startswith(runnable.label, 'test-mod') then
2929
type = 'namespace'
30-
elseif vim.startswith(runnable.label, 'test') then
30+
elseif vim.startswith(runnable.label, 'test') or vim.startswith(runnable.label, "doctest") then
3131
type = 'test'
3232
else
3333
return

0 commit comments

Comments
 (0)