Skip to content

Commit b411a0f

Browse files
authored
feat: scopes view (#30)
* feat: scopes view * docs: mention scopes view * docs(README): remove non-goals section since it no longer makes sense * fix(scopes): make sure buffer exists before refresh
1 parent 98cad74 commit b411a0f

File tree

6 files changed

+84
-36
lines changed

6 files changed

+84
-36
lines changed

README.md

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
- [Highlight Groups](#highlight-groups)
2424
- [Filetypes and autocommands](#filetypes-and-autocommands)
2525
- [Roadmap](#roadmap)
26-
- [Non-goals](#non-goals)
2726
- [Known Issues](#known-issues)
2827
- [Acknowledgements](#acknowledgements)
2928
<!--toc:end-->
@@ -75,7 +74,7 @@ return {
7574
7675
## Features
7776

78-
The plugin provides 5 "views" that share the same window (so there's clutter)
77+
The plugin provides 6 "views" that share the same window (so there's clutter)
7978

8079
- Watches view
8180
- Shows a list of (user defined) expressions, that are evaluated by the debug adapter
@@ -111,7 +110,13 @@ The plugin provides 5 "views" that share the same window (so there's clutter)
111110

112111
![REPL view](https://github.com/user-attachments/assets/43caeb02-ff9e-47ea-a4c1-ab5dd30d8a3c)
113112

114-
You can also interact with the console provided by `nvim-dap` (though, arguably, that's not a feature from `nvim-dap-view`). By the default, the console has its own window, but it can be configured to be shown with the other views, details on the [defaul config](#configuration) section.
113+
- Scopes view
114+
- Use the scopes widget provided by nvim-dap
115+
- Expand variables with `<CR>`
116+
117+
![scopes view](https://github.com/user-attachments/assets/2628ae8e-9224-4b2f-94c7-88e7800c232b)
118+
119+
You can also interact with the console, which is also provided by `nvim-dap`. By the default, the console has its own window, but it can be configured to be shown with the other views. See details on the [defaul config](#configuration) section.
115120

116121
The console's default size (height) is resized to match your `nvim-dap-view` configuration. You can also either completely [hide](#hide-terminal) it (if it's not being used at all) or hide it only during session initialization.
117122

@@ -129,7 +134,7 @@ return {
129134
winbar = {
130135
show = true,
131136
-- You can add a "console" section to merge the terminal with the other views
132-
sections = { "watches", "exceptions", "breakpoints", "threads", "repl" },
137+
sections = { "watches", "scopes", "exceptions", "breakpoints", "threads", "repl" },
133138
-- Must be one of the sections declared above
134139
default_section = "watches",
135140
},
@@ -155,9 +160,9 @@ Start a regular debugging session. When desired, you can use `:DapViewOpen` to
155160
start the plugin. You can switch to a view (section) using the letter outlined
156161
in the `'winbar'` (e.g., `B` for the breakpoints view).
157162

158-
Both the breakpoints view and the exceptions view have only 1 mapping: `<CR>`.
159-
It jumps to a breakpoint and toggles an exception filter, respectively. The
160-
watches view comes with 3 mappings:
163+
The breakpoints view, the exceptions view and the scopes view only have 1
164+
mapping: `<CR>`. It jumps to a breakpoint, toggles an exception filter, and
165+
expands a variable, respectively. The watches view comes with 3 mappings:
161166

162167
- `i` to insert a new expression
163168
- `e` to edit an expression
@@ -181,7 +186,7 @@ In total, there are 5 commands:
181186
- `DapViewWatch`
182187
- `DapViewJump [view]`
183188

184-
You can `:DapViewJump [view]` to jump directly to a view, from any window. For instance, to jump to the REPL, you can use `:DapViewJump repl` to jump to REPL.
189+
You can `:DapViewJump [view]` to jump directly to a view, from any window. For instance, to jump to the REPL, you can use `:DapViewJump repl`.
185190

186191
Additionally, you can use `DapViewClose!` and `DapViewToggle!` to also hide the
187192
terminal window, if you'd rather have a tidy view.
@@ -294,7 +299,7 @@ They are linked to (somewhat) reasonable defaults, but they may look odd with yo
294299

295300
| Window | Filetype |
296301
| -------------------------------- | ------------- |
297-
| watches, exceptions, breakpoints | dap-view |
302+
| watches, exceptions, ... | dap-view |
298303
| terminal | dap-view-term |
299304

300305
These filetypes can be used to override buffer and window options set by `nvim-dap-view`
@@ -325,31 +330,6 @@ vim.api.nvim_create_autocmd({ "FileType" }, {
325330
Missing something? Create an issue with a [feature
326331
request](https://github.com/igorlfs/nvim-dap-view/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.yml&title=feature%3A+)!
327332

328-
## Non-goals
329-
330-
Implement every feature from [nvim-dap-ui](https://github.com/rcarriga/nvim-dap-ui). More specifically,
331-
332-
- **There will be no "scopes" view** (i.e., list all variables in scope). The rationale is that `nvim-dap` already provides a very nice UI for that, using widgets (see `:h dap-widgets`). The TLDR is that you can use
333-
334-
```lua
335-
local widgets = require("dap.ui.widgets")
336-
widgets.centered_float(widgets.scopes, { border = "rounded" })
337-
```
338-
339-
to create a nice, centered floating window, where you can navigate and explore variables. A major advantage from this approach is that you're not limited to a small window at the bottom of your screen (which can be troublesome in noisy environments or languages).
340-
341-
![nvim-dap's Scopes widget](https://github.com/user-attachments/assets/f320392d-e0c8-4b70-8521-db97e115ef5e)
342-
343-
- Likewise, **there will be no "hover" view**, since that's also perfectly handled by `nvim-dap`'s widgets. You can use
344-
345-
```lua
346-
require("dap.ui.widgets").hover(nil, { border = "rounded" })
347-
```
348-
349-
to create a nice floating window to display the variable under the cursor.
350-
351-
![nvim-dap's Hover widget](https://github.com/user-attachments/assets/bdb29360-65dd-426f-b59b-fa0b61377e9c)
352-
353333
## Known Issues
354334

355335
- Breakpoints view doesn't show breakpoint conditions

lua/dap-view/config.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ local M = {}
1414
---@field height integer
1515
---@field terminal TerminalConfig
1616

17-
---@alias SectionType '"breakpoints"' | '"exceptions"' | '"watches"' | '"repl"' | '"threads"' | '"console"'
17+
---@alias SectionType '"breakpoints"' | '"exceptions"' | '"watches"' | '"repl"' | '"threads"' | '"console"' | '"scopes"'
1818

1919
---@class Config
2020
---@field winbar WinbarConfig
2121
---@field windows WindowsConfig
2222
M.config = {
2323
winbar = {
2424
show = true,
25-
sections = { "watches", "exceptions", "breakpoints", "threads", "repl" },
25+
sections = { "watches", "scopes", "exceptions", "breakpoints", "threads", "repl" },
2626
default_section = "watches",
2727
},
2828
windows = {

lua/dap-view/events.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local dap = require("dap")
33
local state = require("dap-view.state")
44
local breakpoints = require("dap-view.breakpoints.view")
55
local watches = require("dap-view.watches.view")
6+
local scopes = require("dap-view.scopes.view")
67
local threads = require("dap-view.threads.view")
78
local exceptions = require("dap-view.exceptions.view")
89
local term = require("dap-view.term.init")
@@ -57,6 +58,13 @@ dap.listeners.after.evaluate[SUBSCRIPTION_ID] = function()
5758
end
5859
end
5960

61+
dap.listeners.after.scopes[SUBSCRIPTION_ID] = function()
62+
-- nvim-dap needs a buffer to operate
63+
if state.current_section == "scopes" and state.bufnr then
64+
scopes.refresh()
65+
end
66+
end
67+
6068
dap.listeners.after.variables[SUBSCRIPTION_ID] = function()
6169
if state.current_section == "watches" then
6270
watches.show()

lua/dap-view/options/winbar.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ local winbar_info = {
1515
end
1616
end,
1717
},
18+
scopes = {
19+
desc = "Scopes [S]",
20+
keymap = "S",
21+
action = function()
22+
if vim.tbl_contains(setup.config.winbar.sections, "scopes") then
23+
require("dap-view.views").switch_to_view(require("dap-view.scopes.view").show)
24+
end
25+
end,
26+
},
1827
exceptions = {
1928
desc = "Exceptions [E]",
2029
keymap = "E",

lua/dap-view/scopes/view.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
local dap = require("dap")
2+
3+
local widgets = require("dap.ui.widgets")
4+
5+
local views = require("dap-view.views")
6+
local winbar = require("dap-view.options.winbar")
7+
local state = require("dap-view.state")
8+
9+
local M = {}
10+
11+
local scopes_widget
12+
13+
local new_widget = function()
14+
return widgets
15+
.builder(widgets.scopes)
16+
.new_buf(function()
17+
return state.bufnr
18+
end)
19+
.new_win(function()
20+
return state.winnr
21+
end)
22+
.build()
23+
end
24+
25+
M.show = function()
26+
winbar.update_winbar("scopes")
27+
28+
if views.cleanup_view(not dap.session(), "No active session") then
29+
return
30+
end
31+
32+
if scopes_widget == nil then
33+
scopes_widget = new_widget()
34+
end
35+
36+
scopes_widget.open()
37+
end
38+
39+
M.refresh = function()
40+
if scopes_widget == nil then
41+
scopes_widget = new_widget()
42+
43+
scopes_widget.open()
44+
else
45+
scopes_widget.refresh()
46+
end
47+
end
48+
49+
return M

lua/dap-view/views/keymaps.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ M.set_keymaps = function()
1313
require("dap-view.threads.actions").jump_or_noop()
1414
elseif state.current_section == "exceptions" then
1515
require("dap-view.exceptions.actions").toggle_exception_filter()
16+
elseif state.current_section == "scopes" then
17+
require("dap.ui").trigger_actions({ mode = "first" })
1618
end
1719
end, { buffer = state.bufnr })
1820

0 commit comments

Comments
 (0)