Skip to content

Commit a59639a

Browse files
committed
feat: handle emptiness in views
1 parent 08ad351 commit a59639a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lua/dap-view/breakpoints/view.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local globals = require("dap-view.globals")
44
local vendor = require("dap-view.breakpoints.vendor")
55
local extmarks = require("dap-view.exceptions.util.extmarks")
66
local treesitter = require("dap-view.exceptions.util.treesitter")
7+
local views = require("dap-view.views")
78

89
local api = vim.api
910

@@ -56,13 +57,14 @@ local populate_buf_with_breakpoints = function()
5657
-- Clear previous content
5758
api.nvim_buf_set_lines(state.bufnr, 0, -1, true, {})
5859

59-
-- TODO: decide between getting breakpoints
60-
-- (A) by getting placed signs (nvim-dap approach)
61-
-- (B) by listing breakpoints via QuickFix list (might have some issues if using the qflist for something else)
6260
local breakpoints = vendor.get()
6361

6462
local line_count = 0
6563

64+
if views.cleanup_view(vim.tbl_isempty(breakpoints), "No Breakpoints") then
65+
return
66+
end
67+
6668
for buf, buf_entries in pairs(breakpoints) do
6769
local filename = api.nvim_buf_get_name(buf)
6870
local relative_path = vim.fn.fnamemodify(filename, ":.")

lua/dap-view/views/init.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local state = require("dap-view.state")
2+
local globals = require("dap-view.globals")
3+
4+
local M = {}
5+
6+
local api = vim.api
7+
8+
---@param cond boolean
9+
---@param message string
10+
M.cleanup_view = function(cond, message)
11+
if cond then
12+
vim.wo[state.winnr].cursorline = false
13+
14+
api.nvim_buf_set_lines(state.bufnr, 0, -1, false, { message })
15+
api.nvim_buf_set_extmark(
16+
state.bufnr,
17+
globals.NAMESPACE,
18+
0,
19+
0,
20+
{ end_col = #message, hl_group = "DapBreakpoint" }
21+
)
22+
else
23+
vim.wo[state.winnr].cursorline = true
24+
end
25+
26+
return cond
27+
end
28+
29+
return M

lua/dap-view/watches/view.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local state = require("dap-view.state")
22
local winbar = require("dap-view.options.winbar")
33
local globals = require("dap-view.globals")
4+
local views = require("dap-view.views")
45

56
local M = {}
67

@@ -14,7 +15,7 @@ M.show = function()
1415
api.nvim_buf_set_lines(state.bufnr, 0, -1, true, {})
1516
api.nvim_buf_clear_namespace(state.bufnr, globals.NAMESPACE, 0, -1)
1617

17-
if #state.watched_expressions == 0 then
18+
if views.cleanup_view(#state.watched_expressions == 0, "No Expressions") then
1819
return
1920
end
2021

0 commit comments

Comments
 (0)