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

Add configurable window width, and possibility to hide the terminal window #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
38 changes: 37 additions & 1 deletion lua/dap-view/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,41 @@ M.close = function()
end
end

-- Calculate the window width based on parent window and
-- configuration. Numbers between 0 and 1 are interpreted
-- as a percentage.
local function get_window_size(config)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, can you add a type annotation for the param here?

local win_width = 0.5

local parent_width = vim.api.nvim_win_get_width(0)
if config.windows.width > 1 then
win_width = config.windows.width
end

if config.windows.width < 1 then
win_width = math.floor(parent_width * config.windows.width)
end

if config.windows.width == 1 then
win_width = parent_width
end

return win_width
end
Comment on lines +41 to +61
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this function to a new file? Could be a lua/util/win.lua.


-- If the window should be 100% width, we have already hidden
-- the terminal and should split below. If the terminal window
-- is open we should split to the right of it.
local function get_window_split(config)
local split = "right"

if config.windows.width == 1 then
split = "below"
end

return split
end

M.open = function()
M.close()

Expand All @@ -59,9 +94,10 @@ M.open = function()
local config = setup.config

local winnr = api.nvim_open_win(bufnr, false, {
split = "right",
split = get_window_split(config),
win = term_winnr,
height = config.windows.height,
width = get_window_size(config),
})

assert(winnr ~= 0, "Failed to create dap-view window")
Expand Down
2 changes: 2 additions & 0 deletions lua/dap-view/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local M = {}

---@class WindowsConfig
---@field height integer
---@field width number|integer Width of the window in either characters or percentage (as decimal: 0.75). Window size of 1 means 100% width, which will hide the terminal window.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---@field width number|integer Width of the window in either characters or percentage (as decimal: 0.75). Window size of 1 means 100% width, which will hide the terminal window.
---@field width number|integer Width of the main window in either characters or percentage (as decimal: 0.75). Window size of 1 means 100% width, which will hide the terminal window.


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

Expand All @@ -22,6 +23,7 @@ M.config = {
},
windows = {
height = 12,
width = 0.5,
},
}

Expand Down
4 changes: 4 additions & 0 deletions lua/dap-view/term/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ M.term_buf_win_init = function()

util_buf.quit_buf_autocmd(state.term_bufnr, M.close_term_buf_win)

if config.windows.width == 1 then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest main, what we would do instead is add (yet) another condition to the if that spawns the window.

vim.api.nvim_win_hide(state.term_winnr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanna make a more throughout review later, but have you tested this with adapters other than delve?

end

dap.defaults.fallback.terminal_win_cmd = function()
return state.term_bufnr, state.term_winnr
end
Expand Down