Skip to content

Commit

Permalink
fix(dap): pass filetype to dap.run (#315)
Browse files Browse the repository at this point in the history
Prevents nvim-dap from using the summary window when opening a buffer
  • Loading branch information
luismeyer95 authored Dec 22, 2023
1 parent 7610198 commit 3b3fef1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/neotest/client/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function TestRunner:_run_spec(spec, tree, args, adapter_id, adapter, results_cal
local position = tree:data()
local context = {
position = position,
adapter = adapter,
}

local proc_key = self:_create_process_key(adapter_id, position.id)
Expand Down
24 changes: 23 additions & 1 deletion lua/neotest/client/strategies/dap/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
local nio = require("nio")
local lib = require("neotest.lib")
local FanoutAccum = require("neotest.types").FanoutAccum

---@param adapter neotest.Adapter
---@param position neotest.Position
---@return string|nil
local function get_test_filetype(adapter, position)
local path_matcher = position.path and string.format("^%s$", position.path)
local test_bufnr = nio.fn.bufnr(path_matcher or -1)
if test_bufnr ~= -1 then
return nio.api.nvim_buf_get_option(test_bufnr, "filetype")
end

for _, buf in ipairs(nio.api.nvim_list_bufs()) do
local name = nio.api.nvim_buf_get_name(buf)
local real = lib.files.path.real(name)
if real and adapter.is_test_file(real) then
return nio.api.nvim_buf_get_option(buf, "filetype")
end
end
end

---@param spec neotest.RunSpec
---@param context neotest.StrategyContext
---@return neotest.StrategyResult?
return function(spec)
return function(spec, context)
if vim.tbl_isempty(spec.strategy) then
return
end
Expand Down Expand Up @@ -36,6 +57,7 @@ return function(spec)

nio.scheduler()
dap.run(vim.tbl_extend("keep", spec.strategy, { env = spec.env, cwd = spec.cwd }), {
filetype = get_test_filetype(context.adapter, context.position),
before = function(config)
dap.listeners.after.event_output[handler_id] = function(_, body)
if vim.tbl_contains({ "stdout", "stderr" }, body.category) then
Expand Down
1 change: 1 addition & 0 deletions lua/neotest/types/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ M.ResultStatus = {

---@class neotest.StrategyContext
---@field position neotest.Position
---@field adapter neotest.Adapter

---@alias neotest.Strategy async fun(spec: neotest.RunSpec, context: neotest.StrategyContext): neotest.Process

Expand Down

0 comments on commit 3b3fef1

Please sign in to comment.