Skip to content

Commit

Permalink
Add config parameter to terminal_win_cmd function (#1395)
Browse files Browse the repository at this point in the history
Allows to customize the terminal creation based on the used configuration
  • Loading branch information
nsoufian authored Dec 9, 2024
1 parent 580d6e5 commit b08e05d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/dap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ The configuration values are set via `dap.defaults.fallback` (for global) or
the integrated terminal. (See |dap-terminal|). Either a string or a function
that must return a buffer number and a window number of the buffer/window
for the terminal.
When using a function, it receives the current debug configuration as an
argument, allowing for dynamic terminal naming and setup based on the
session's configuration.

Note that extensions like `nvim-dap-ui` use this to control the UI.
If you customize it, you may break their behavior.
Expand Down
2 changes: 1 addition & 1 deletion lua/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ M.defaults = setmetatable(
---@type "statement"|"line"|"instruction"
stepping_granularity = 'statement';

---@type string|fun(): number bufnr, number|nil win
---@type string|fun(config: dap.Configuration):(integer, integer?)
terminal_win_cmd = 'belowright new';
focus_terminal = false;
auto_continue_if_many_stopped = true;
Expand Down
9 changes: 5 additions & 4 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ local function launch_external_terminal(env, terminal, args)
end


---@param terminal_win_cmd string|fun():integer, integer?
---@param terminal_win_cmd string|fun(config: dap.Configuration):(integer, integer?)
---@param filetype string
---@param config dap.Configuration
---@return integer bufnr, integer? winnr
local function create_terminal_buf(terminal_win_cmd, filetype)
local function create_terminal_buf(terminal_win_cmd, filetype, config)
local cur_win = api.nvim_get_current_win()
if type(terminal_win_cmd) == "string" then
api.nvim_command(terminal_win_cmd)
Expand All @@ -164,7 +165,7 @@ local function create_terminal_buf(terminal_win_cmd, filetype)
return bufnr, win
else
assert(type(terminal_win_cmd) == "function", "terminal_win_cmd must be a string or a function")
return terminal_win_cmd()
return terminal_win_cmd(config)
end
end

Expand All @@ -186,7 +187,7 @@ do
end
end
local terminal_win
buf, terminal_win = create_terminal_buf(win_cmd, filetype)
buf, terminal_win = create_terminal_buf(win_cmd, filetype, config)
if terminal_win then
if vim.fn.has('nvim-0.8') == 1 then
-- older versions don't support the `win` key
Expand Down

0 comments on commit b08e05d

Please sign in to comment.