Skip to content

Commit 273bcde

Browse files
authored
feat(terminal): config position (#9)
* feat: adds configuration option to configure terminal split type (left or right) * ref: use config.window.terminal.position to set terminal window position * fix: when terminal position is on the left, set dap fallback.switchbuf to "useopen" to prevent terminal window from being used for goto breakpoint * fix: set dap.defaults.fallback.switchbuf to "useopen" to prevent dap-view window from being used for breakpoint focusing * ref: use "left" as fallback for terminal position chore: resolve merge conflicts with main ref: removes dep switchbuf fallback setting fix: removes trailing comma * doc: adds terminal configuration section to the readme * fix: add position to windows.terminal validation * doc: updates readme to indicate how to override default nvim-dap switchbuf option
1 parent fc27ec1 commit 273bcde

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [Usage](#usage)
1818
- [Recommended Setup](#recommended-setup)
1919
- [Hide Terminal](#hide-terminal)
20+
- [Terminal Position and Integration](#terminal-position-and-integration)
2021
- [Highlight Groups](#highlight-groups)
2122
- [Filetypes and autocommands](#filetypes-and-autocommands)
2223
- [Roadmap](#roadmap)
@@ -119,6 +120,8 @@ return {
119120
windows = {
120121
height = 12,
121122
terminal = {
123+
-- 'left'|'right': Terminal position in layout
124+
position = "left",
122125
-- List of adapters for which the terminal should be hidden
123126
hide = {},
124127
},
@@ -196,6 +199,21 @@ return {
196199
}
197200
```
198201

202+
#### Terminal Position and Integration
203+
204+
When setting `windows.terminal.position` to `right` the views window may be used
205+
to display the current breakpoint because `nvim-dap` defaults to the global
206+
`switchbuf` setting. A common solution is to set `switchbuf` to "useopen":
207+
208+
```lua
209+
require("dap").defaults.fallback.switchbuf = "useopen"
210+
```
211+
212+
If you are using an adapter that does not natively support the `nvim-dap` integrated
213+
terminal, you can get the `winnr` and `bufnr` of the `nvim-dap-view` terminal via
214+
`dap-view.state` and use `vim.fn.jobstart` to start your debugger in the `nvim-dap-view`
215+
terminal! An example can be found [here](https://github.com/catgoose/nvim/blob/a783e0fe931a5e417c4e3cc7e964793d895862e6/lua/config/dap/go.lua)
216+
199217
### Highlight Groups
200218

201219
`nvim-dap-view` defines 8 highlight groups:

lua/dap-view/actions.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ M.open = function()
5757

5858
local is_term_win_valid = term_winnr ~= nil and api.nvim_win_is_valid(term_winnr)
5959

60+
local term_position = config.windows.terminal.position == "left" and "right" or "left"
61+
6062
local winnr = api.nvim_open_win(bufnr, false, {
61-
split = is_term_win_valid and "right" or "below",
63+
split = is_term_win_valid and term_position or "below",
6264
win = is_term_win_valid and term_winnr or -1,
6365
height = config.windows.height,
6466
})

lua/dap-view/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local M = {}
88

99
---@class TerminalConfig
1010
---@field hide string[] Hide the terminal for listed adapters.
11+
---@field position 'right' | 'left'
1112

1213
---@class WindowsConfig
1314
---@field height integer
@@ -27,6 +28,7 @@ M.config = {
2728
windows = {
2829
height = 12,
2930
terminal = {
31+
position = "left",
3032
hide = {},
3133
},
3234
},

lua/dap-view/setup/validate/windows.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function M.validate(config)
1010
}, config)
1111

1212
validate("windows.terminal", {
13+
position = { config.terminal.position, "string" },
1314
hide = { config.terminal.hide, "table" },
1415
}, config.terminal)
1516
end

0 commit comments

Comments
 (0)