Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit path setting for term buffer #1355

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,18 @@ end


---@param terminal_win_cmd string|fun():integer, integer?
---@param filetype string
---@return integer bufnr, integer? winnr
local function create_terminal_buf(terminal_win_cmd)
local function create_terminal_buf(terminal_win_cmd, filetype)
local cur_win = api.nvim_get_current_win()
if type(terminal_win_cmd) == "string" then
api.nvim_command(terminal_win_cmd)
local bufnr = api.nvim_get_current_buf()
if vim.filetype then
local path = vim.filetype.get_option(filetype, "path")
assert(type(path) == "string", "path option must be a string")
vim.bo[bufnr].path = path
end
local win = api.nvim_get_current_win()
api.nvim_set_current_win(cur_win)
return bufnr, win
Expand All @@ -168,8 +174,9 @@ do
---@type table<integer, boolean>
local pool = {}

---@param filetype string
---@return integer, integer|nil
function terminals.acquire(win_cmd, config)
function terminals.acquire(win_cmd, config, filetype)
local buf = next(pool)
if buf then
pool[buf] = nil
Expand All @@ -179,7 +186,7 @@ do
end
end
local terminal_win
buf, terminal_win = create_terminal_buf(win_cmd)
buf, terminal_win = create_terminal_buf(win_cmd, filetype)
if terminal_win then
if vim.fn.has('nvim-0.8') == 1 then
-- older versions don't support the `win` key
Expand Down Expand Up @@ -226,7 +233,11 @@ local function run_in_terminal(lsession, request)
end
end
local cur_buf = api.nvim_get_current_buf()
local terminal_buf, terminal_win = terminals.acquire(settings.terminal_win_cmd, lsession.config)
local terminal_buf, terminal_win = terminals.acquire(
settings.terminal_win_cmd,
lsession.config,
lsession.filetype
)
local terminal_buf_name = '[dap-terminal] ' .. (lsession.config.name or body.args[1])
local terminal_name_ok = pcall(api.nvim_buf_set_name, terminal_buf, terminal_buf_name)
if not terminal_name_ok then
Expand Down
Loading