Skip to content

Commit 6ce6213

Browse files
committed
feat: validate user config for hide adapters
1 parent e9a264f commit 6ce6213

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

lua/dap-view/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ M.open = function()
5555

5656
local config = setup.config
5757

58-
local is_term_win_valid = term_winnr ~= nil and api.nvim_win_is_valid(term_winnr) or false
58+
local is_term_win_valid = term_winnr ~= nil and api.nvim_win_is_valid(term_winnr)
5959

6060
local winnr = api.nvim_open_win(bufnr, false, {
6161
split = is_term_win_valid and "right" or "below",

lua/dap-view/config.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ local M = {}
66
---@field default_section SectionType
77
---@field show boolean
88

9+
---@class TerminalConfig
10+
---@field hide string[] Hide the terminal for listed adapters.
11+
912
---@class WindowsConfig
1013
---@field height integer
11-
12-
---@class TerminalConfig
13-
---@field exclude_adapters string[] Disable the terminal view for selected adapters.
14+
---@field terminal TerminalConfig
1415

1516
---@alias SectionType '"breakpoints"' | '"exceptions"' | '"watches"' | '"repl"'
1617

1718
---@class Config
1819
---@field winbar WinbarConfig
1920
---@field windows WindowsConfig
20-
---@field terminal TerminalConfig
2121
M.config = {
2222
winbar = {
2323
show = true,
@@ -26,9 +26,9 @@ M.config = {
2626
},
2727
windows = {
2828
height = 12,
29-
},
30-
terminal = {
31-
exclude_adapters = {},
29+
terminal = {
30+
hide = {},
31+
},
3232
},
3333
}
3434

lua/dap-view/events.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dap.listeners.before.initialize[SUBSCRIPTION_ID] = function(session, _)
1919
-- (B) Uses the terminal, after a session that doesn't
2020
-- The terminal wouldn't show up, since it's hidden
2121
--
22-
-- To handle scenarios, we have to close the terminal buffer
22+
-- To handle these scenarios, we have to close the terminal buffer
2323
-- However, if we always close the terminal, dap-view will be shifted very quickly (if open),
2424
-- causing a flickering effect.
2525
--
@@ -28,6 +28,7 @@ dap.listeners.before.initialize[SUBSCRIPTION_ID] = function(session, _)
2828
if state.last_active_adapter ~= session.config.type then
2929
term.clear_term_bufnr()
3030
end
31+
state.last_active_adapter = session.config.type
3132

3233
term.open_term_buf_win()
3334
end
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
local M = {}
22

3+
local validate = require("dap-view.setup.validate.util").validate
4+
35
---@param config WindowsConfig
46
function M.validate(config)
5-
require("dap-view.setup.validate.util").validate("windows", {
7+
validate("windows", {
68
height = { config.height, "number" },
9+
terminal = { config.terminal, "table" },
710
}, config)
11+
12+
validate("windows.terminal", {
13+
hide = { config.terminal.hide, "table" },
14+
}, config.terminal)
815
end
916

1017
return M

lua/dap-view/term/init.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ end
3636
M.open_term_buf_win = function()
3737
-- When (re)opening the terminal we should NOT close it,
3838
-- since it's the default standard output for most adapters
39-
-- Therefore, closing it could delete useful information from past sessions
39+
-- Therefore, closing it could delete useful information from the last session
4040

41-
if term_bufnr == nil then
41+
if not term_bufnr then
4242
term_bufnr = api.nvim_create_buf(true, false)
4343

4444
assert(term_bufnr ~= 0, "Failed to create nvim-dap-view buffer")
@@ -48,19 +48,15 @@ M.open_term_buf_win = function()
4848

4949
local config = setup.config
5050

51-
if term_winnr == nil then
52-
for _, adapter in ipairs(config.terminal.exclude_adapters) do
53-
dap.defaults[adapter].terminal_win_cmd = function(session)
54-
state.last_active_adapter = session.type
55-
51+
if not term_winnr then
52+
for _, adapter in ipairs(config.windows.terminal.hide) do
53+
dap.defaults[adapter].terminal_win_cmd = function()
5654
return term_bufnr
5755
end
5856
end
5957

60-
dap.defaults.fallback.terminal_win_cmd = function(session)
61-
state.last_active_adapter = session.type
62-
63-
local is_win_valid = state.winnr ~= nil and api.nvim_win_is_valid(state.winnr) or false
58+
dap.defaults.fallback.terminal_win_cmd = function()
59+
local is_win_valid = state.winnr ~= nil and api.nvim_win_is_valid(state.winnr)
6460
term_winnr = api.nvim_open_win(term_bufnr, false, {
6561
split = is_win_valid and "left" or "below",
6662
win = is_win_valid and state.winnr or -1,

0 commit comments

Comments
 (0)