Skip to content

Commit

Permalink
feat: wrap plenary async, rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Mar 13, 2022
1 parent de63cec commit 22383da
Show file tree
Hide file tree
Showing 32 changed files with 437 additions and 197 deletions.
129 changes: 103 additions & 26 deletions doc/neotest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Each consumer can be accessed as a property of the neotest module
neotest.setup({user_config}) *neotest.setup()*
Configure Neotest strategies and consumers
See: ~
|NeotestConfig|
|neotest.Config|

Default values:
{
adapters = {},
diagnostics = {
diagnostic = {
enabled = true
},
floating = {
Expand Down Expand Up @@ -87,6 +87,7 @@ neotest.setup({user_config}) *neotest.setup()*
},
strategies = {
integrated = {
height = 40,
width = 120
}
},
Expand All @@ -108,7 +109,7 @@ neotest.setup({user_config}) *neotest.setup()*
}

Parameters: ~
{user_config} (NeotestConfig)
{user_config} (neotest.Config)


neotest.run({args}) *neotest.run()*
Expand Down Expand Up @@ -172,20 +173,20 @@ neotest.attach({args}) *neotest.attach()*
================================================================================
*neotest.config*

NeotestConfig *NeotestConfig*
neotest.Config *neotest.Config*


Fields: ~
{adapters} (NeotestAdapter[])
{icons} (NeotestIconsConfig)
{highlights} (NeotestHighlightsConfig)
{floating} (NeotestFloatingConfig)
{strategies} (NeotestStrategiesConfig)
{summary} (NeotestSummaryConfig)
{output} (NeotestOutputConfig)
{adapters} (neotest.Adapter[])
{icons} (neotest.Config.icons)
{highlights} (neotest.Config.highlights)
{floating} (neotest.Config.floating)
{strategies} (neotest.Config.strategies)
{summary} (neotest.Config.summary)
{output} (neotest.Config.output)


NeotestIconsConfig *NeotestIconsConfig*
neotest.Config.icons *neotest.Config.icons*


Fields: ~
Expand All @@ -198,7 +199,7 @@ NeotestIconsConfig *NeotestIconsConfig*
{expanded} (string)


NeotestHighlightsConfig *NeotestHighlightsConfig*
neotest.Config.highlights *neotest.Config.highlights*


Fields: ~
Expand All @@ -216,7 +217,7 @@ NeotestHighlightsConfig *NeotestHighlightsConfig*
{adapter_name} (string)


NeotestFloatingConfig *NeotestFloatingConfig*
neotest.Config.floating *neotest.Config.floating*


Fields: ~
Expand All @@ -227,32 +228,34 @@ NeotestFloatingConfig *NeotestFloatingConfig*
window


NeotestIntegratedStrategyConfig *NeotestIntegratedStrategyConfig*
neotest.Config.strategies.integrated *neotest.Config.strategies.integrated*


Fields: ~
{width} (integer) Width to pass to the pty runnning commands


NeotestStrategiesConfig *NeotestStrategiesConfig*
neotest.Config.strategies *neotest.Config.strategies*


Fields: ~
{integrated} (NeotestIntegratedStrategyConfig)
{integrated} (neotest.Config.strategies.integrated)


NeotestSummaryConfig *NeotestSummaryConfig*
neotest.Config.summary *neotest.Config.summary*


Fields: ~
{enabled} (boolean)
{follow} (boolean) Expand user's current file
{expand_errors} (boolean) Expand all failed positions
{mappings} (NeotestSummaryMappings) Buffer mappings for summary
window
{follow} (boolean) Expand user's
current file
{expand_errors} (boolean) Expand all failed
positions
{mappings} (neotest.Config.summary.mappings) Buffer mappings for
summary window


NeotestSummaryMappings *NeotestSummaryMappings*
neotest.Config.summary.mappings *neotest.Config.summary.mappings*


Fields: ~
Expand All @@ -268,27 +271,101 @@ NeotestSummaryMappings *NeotestSummaryMappings*
{run} (string|string[]) Run selected position


NeotestOutputConfig *NeotestOutputConfig*
neotest.Config.output *neotest.Config.output*


Fields: ~
{enabled} (boolean)
{open_on_run} (boolean) Open nearest test result after running


NeotestDiagnosticsConfig *NeotestDiagnosticsConfig*
neotest.Config.diagnostic *neotest.Config.diagnostic*


Fields: ~
{enabled} (boolean)


NeotestStatusConfig *NeotestStatusConfig*
neotest.Config.status *neotest.Config.status*


Fields: ~
{enabled} (boolean)



================================================================================
*neotest.output*

A consumer that displays the output of test results.

neotest.output.open({opts}) *neotest.output.open()*
Open the output of a test result
>
lua require("neotest").open({ enter = true })
<


Parameters: ~
{opts} (table)

Fields: ~
{short} (boolean) Show shortened output
{enter} (boolean) Enter output window
{position_id} (string) Open output for position with this ID, opens
nearest position if not given



================================================================================
*neotest.status*

A consumer that displays the results of tests as signs beside their
declaration. This consumer is completely passive and so has no interface.


================================================================================
*neotest.diagnostic*

A consumer that displays error messages using the vim.diagnostic API. This
consumer is completely passive and so has no interface.

You can configure the diagnostic API for neotest using the "neotest" namespace
See: ~
|vim.diagnostic.config()|


================================================================================
*neotest.summary*

A consumer that displays the structure of the test suite, along with results
and allows running tests.
See: ~
|neotest.Config.summary.mappings| for all mappings in the summary window

neotest.summary.open() *neotest.summary.open()*
Open the summary window
>
lua require("neotest").summary.open()
<



neotest.summary.close() *neotest.summary.close()*
Close the summary window
>
lua require("neotest").summary.close()
<



neotest.summary.toggle() *neotest.summary.toggle()*
Toggle the summary window
>
lua require("neotest").summary.toggle()
<




vim:tw=78:ts=8:ft=help:norl:
30 changes: 19 additions & 11 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
NeotestConfig neotest.txt /*NeotestConfig*
NeotestDiagnosticsConfig neotest.txt /*NeotestDiagnosticsConfig*
NeotestFloatingConfig neotest.txt /*NeotestFloatingConfig*
NeotestHighlightsConfig neotest.txt /*NeotestHighlightsConfig*
NeotestIconsConfig neotest.txt /*NeotestIconsConfig*
NeotestIntegratedStrategyConfig neotest.txt /*NeotestIntegratedStrategyConfig*
NeotestOutputConfig neotest.txt /*NeotestOutputConfig*
NeotestStatusConfig neotest.txt /*NeotestStatusConfig*
NeotestStrategiesConfig neotest.txt /*NeotestStrategiesConfig*
NeotestSummaryConfig neotest.txt /*NeotestSummaryConfig*
NeotestSummaryMappings neotest.txt /*NeotestSummaryMappings*
neotest neotest.txt /*neotest*
neotest.Config neotest.txt /*neotest.Config*
neotest.Config.diagnostic neotest.txt /*neotest.Config.diagnostic*
neotest.Config.floating neotest.txt /*neotest.Config.floating*
neotest.Config.highlights neotest.txt /*neotest.Config.highlights*
neotest.Config.icons neotest.txt /*neotest.Config.icons*
neotest.Config.output neotest.txt /*neotest.Config.output*
neotest.Config.status neotest.txt /*neotest.Config.status*
neotest.Config.strategies neotest.txt /*neotest.Config.strategies*
neotest.Config.strategies.integrated neotest.txt /*neotest.Config.strategies.integrated*
neotest.Config.summary neotest.txt /*neotest.Config.summary*
neotest.Config.summary.mappings neotest.txt /*neotest.Config.summary.mappings*
neotest.attach() neotest.txt /*neotest.attach()*
neotest.config neotest.txt /*neotest.config*
neotest.diagnostic neotest.txt /*neotest.diagnostic*
neotest.output neotest.txt /*neotest.output*
neotest.output.open() neotest.txt /*neotest.output.open()*
neotest.run() neotest.txt /*neotest.run()*
neotest.setup() neotest.txt /*neotest.setup()*
neotest.status neotest.txt /*neotest.status*
neotest.stop() neotest.txt /*neotest.stop()*
neotest.summary.close() neotest.txt /*neotest.summary.close()*
neotest.summary.open() neotest.txt /*neotest.summary.open()*
neotest.summary.toggle() neotest.txt /*neotest.summary.toggle()*
neotest.summmary neotest.txt /*neotest.summmary*
4 changes: 2 additions & 2 deletions lua/neotest/adapters/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local async = require("plenary.async")
local async = require("neotest.async")
local config = require("neotest.config")
local lib = require("neotest.lib")

---@class AdapterGroup
---@class neotest.AdapterGroup
local AdapterGroup = {}

function AdapterGroup.adapters_with_root_dir(cwd)
Expand Down
16 changes: 8 additions & 8 deletions lua/neotest/adapters/interface.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@class NeotestAdapter
---@class neotest.Adapter
---@field name string
local NeotestAdapter = {}

Expand All @@ -14,16 +14,16 @@ function NeotestAdapter.is_test_file(file_path) end

---@async
---@param file_path string
---@return Tree | nil
---@return neotest.Tree | nil
function NeotestAdapter.discover_positions(file_path) end

---@param args NeotestRunArgs
---@return NeotestRunSpec
---@param args neotest.RunArgs
---@return neotest.RunSpec
function NeotestAdapter.build_spec(args) end

---@async
---@param spec NeotestRunSpec
---@param result NeotestStrategyResult
---@param tree Tree
---@return table<string, NeotestResult>
---@param spec neotest.RunSpec
---@param result neotest.StrategyResult
---@param tree neotest.Tree
---@return table<string, neotest.Result>
function NeotestAdapter.results(spec, result, tree) end
29 changes: 29 additions & 0 deletions lua/neotest/async.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local plen_async = require("plenary.async")

local function proxy_vim(prop)
return setmetatable({}, {
__index = function(_, k)
return function(...)
-- if we are in a fast event await the scheduler
if vim.in_fast_event() then
plen_async.util.scheduler()
end

return vim[prop][k](...)
end
end,
})
end

local async_wrapper = {
api = proxy_vim("api"),
fn = proxy_vim("fn"),
}

setmetatable(async_wrapper, {
__index = function(_, k)
return plen_async[k]
end,
})

return async_wrapper
6 changes: 3 additions & 3 deletions lua/neotest/client/events/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local async = require("plenary.async")
local async = require("neotest.async")
local logger = require("neotest.logging")

local M = {}
Expand All @@ -18,9 +18,9 @@ local NeotestEvents = {
M.events = NeotestEvents

---@class NeotestEventListeners
---@field discover_positions table<string, fun(adapter_id: integer, path: string, tree: Tree)>
---@field discover_positions table<string, fun(adapter_id: integer, path: string, tree: neotest.Tree)>
---@field run table<string, fun(adapter_id: integer, position_ids: string[])>
---@field results table<string, fun(adapter_id: integer, results: table<string, NeotestResult>)>
---@field results table<string, fun(adapter_id: integer, results: table<string, neotest.Result>)>
---@field test_file_focused table<string,fun(file_path: string)>>

---@class NeotestEventProcessor
Expand Down
Loading

0 comments on commit 22383da

Please sign in to comment.