Skip to content

Commit

Permalink
feat(status): display as virtual text
Browse files Browse the repository at this point in the history
See #61
  • Loading branch information
rcarriga committed Jul 7, 2022
1 parent 4f04d0a commit b86e558
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 34 deletions.
9 changes: 7 additions & 2 deletions doc/neotest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ neotest.setup({user_config}) *neotest.setup()*
enabled = true
},
status = {
enabled = true
enabled = true,
signs = true,
virtual_text = false
},
strategies = {
integrated = {
Expand Down Expand Up @@ -150,6 +152,7 @@ neotest.Config *neotest.Config*
{strategies} (neotest.Config.strategies)
{summary} (neotest.Config.summary)
{output} (neotest.Config.output)
{status} (neotest.Config.status)


neotest.Config.discovery *neotest.Config.discovery*
Expand Down Expand Up @@ -239,7 +242,9 @@ neotest.Config.status *neotest.Config.status*


Fields: ~
{enabled} (boolean)
{enabled} (boolean)
{virtual_text} (boolean) Display status using virtual text
{signs} (boolean) Display status using signs



Expand Down
5 changes: 5 additions & 0 deletions lua/neotest/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vim.cmd([[
---@field strategies neotest.Config.strategies
---@field summary neotest.Config.summary
---@field output neotest.Config.output
---@field status neotest.Config.status
--
---@class neotest.Config.discovery
---@field enabled boolean
Expand Down Expand Up @@ -73,6 +74,8 @@ vim.cmd([[

---@class neotest.Config.status
---@field enabled boolean
---@field virtual_text boolean: Display status using virtual text
---@field signs boolean: Display status using signs

---@type neotest.Config
local default_config = {
Expand Down Expand Up @@ -151,6 +154,8 @@ local default_config = {
},
status = {
enabled = true,
virtual_text = false,
signs = true,
},
run = {
enabled = true,
Expand Down
74 changes: 42 additions & 32 deletions lua/neotest/consumers/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,56 @@ local config = require("neotest.config")

---@param client neotest.Client
local function init(client)
vim.fn.sign_define(
"neotest_passed",
{ text = config.icons.passed, texthl = config.highlights.passed }
)
vim.fn.sign_define(
"neotest_skipped",
{ text = config.icons.skipped, texthl = config.highlights.skipped }
)
vim.fn.sign_define(
"neotest_failed",
{ text = config.icons.failed, texthl = config.highlights.failed }
)
vim.fn.sign_define(
"neotest_running",
{ text = config.icons.running, texthl = config.highlights.running }
)
local statuses = {
passed = { text = config.icons.passed, texthl = config.highlights.passed },
skipped = { text = config.icons.skipped, texthl = config.highlights.skipped },
failed = { text = config.icons.failed, texthl = config.highlights.failed },
running = { text = config.icons.running, texthl = config.highlights.running },
}
for status, conf in pairs(statuses) do
async.fn.sign_define("neotest_" .. status, conf)
end

local namespace = async.api.nvim_create_namespace(sign_group)

local function place_sign(buf, pos, adapter_id, results)
local status
if client:is_running(pos.id, { adapter = adapter_id }) then
status = "running"
elseif results[pos.id] then
local result = results[pos.id]
status = result.status
end
if not status then
return
end
if config.status.signs then
async.fn.sign_place(0, sign_group, "neotest_" .. status, pos.path, {
lnum = pos.range[1] + 1,
priority = 1000,
})
end
if config.status.virtual_text then
async.api.nvim_buf_set_extmark(buf, namespace, pos.range[1], 0, {
virt_text = {
{ statuses[status].text, statuses[status].texthl },
},
})
end
end

local function render_files(adapter_id, files)
for _, file_path in pairs(files) do
local results = client:get_results(adapter_id)
async.fn.sign_unplace(sign_group, { buffer = file_path })
async.api.nvim_buf_clear_namespace(async.fn.bufnr(file_path), namespace, 0, -1)
local tree = client:get_position(file_path, { adapter = adapter_id })
if not tree then
return
end
for _, pos in tree:iter() do
if pos.type ~= "file" then
local icon
if client:is_running(pos.id, { adapter = adapter_id }) then
icon = "neotest_running"
elseif results[pos.id] then
local result = results[pos.id]
icon = "neotest_" .. result.status
end
if icon then
async.fn.sign_place(
0,
sign_group,
icon,
pos.path,
{ lnum = pos.range[1] + 1, priority = 1000 }
)
end
place_sign(async.fn.bufnr(file_path), pos, adapter_id, results)
end
end
end
Expand Down

0 comments on commit b86e558

Please sign in to comment.