Skip to content

Commit

Permalink
feat(eval): warn on no session
Browse files Browse the repository at this point in the history
See #163
  • Loading branch information
rcarriga committed Nov 3, 2022
1 parent f889edb commit 6a82715
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
7 changes: 1 addition & 6 deletions lua/dapui/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ local function dep_warning(message)
vim.schedule(function()
if not dep_warnings[message] then
dep_warnings[message] = true
vim.notify(message, vim.log.levels.WARN, {
title = "nvim-dap-ui",
on_open = function(win)
vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
end,
})
require("dapui.util").notify(message, vim.log.levels.WARN)
end
end)
end
Expand Down
19 changes: 10 additions & 9 deletions lua/dapui/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---@tag nvim-dap-ui

local dap = require("dap")
local dapui = {}

local windows = require("dapui.windows")
local config = require("dapui.config")
local util = require("dapui.util")
local ui_state

---@return Element
Expand Down Expand Up @@ -78,12 +81,16 @@ local prev_expr = nil
---@field height integer: Fixed height of window
---@field enter boolean: Whether or not to enter the window after opening
function dapui.eval(expr, settings)
if not dap.session() then
util.notify("No active debug session", vim.log.levels.WARN)
return
end
settings = settings or {}
if not expr then
if vim.fn.mode() == "v" then
local start = vim.fn.getpos("v")
local finish = vim.fn.getpos(".")
local lines = require("dapui.util").get_selection(start, finish)
local lines = util.get_selection(start, finish)
expr = table.concat(lines, "\n")
else
expr = expr or vim.fn.expand("<cexpr>")
Expand Down Expand Up @@ -121,13 +128,9 @@ end
local refresh_control_panel = function() end

function dapui.setup(user_config)
local dap = require("dap")
local render = require("dapui.render")
if ui_state then
vim.notify("Setup called twice", vim.log.levels.DEBUG, {
title = "nvim-dap-ui",
icon = "",
})
util.notify("Setup called twice", vim.log.levels.DEBUG)
end
render.loop.clear()

Expand All @@ -150,7 +153,7 @@ function dapui.setup(user_config)
end
end

if config.controls.enabled and config.controls.element ~= '' then
if config.controls.enabled and config.controls.element ~= "" then
local buf_name = buf_name_map[config.controls.element]

local group = vim.api.nvim_create_augroup("DAPUIControls", {})
Expand Down Expand Up @@ -351,8 +354,6 @@ function dapui.toggle(opts)
refresh_control_panel()
end

local dap = require("dap")

_G._dapui = {
play = function()
local session = dap.session()
Expand Down
2 changes: 1 addition & 1 deletion lua/dapui/render/canvas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function M._mapping(action)
local line = vim.fn.line(".")
local callbacks = _mappings[buffer][action][line]
if not callbacks then
vim.notify("No " .. action .. " action for current line", vim.log.levels.INFO)
util.notify("No " .. action .. " action for current line", vim.log.levels.INFO)
return
end
for _, callback in pairs(callbacks) do
Expand Down
6 changes: 3 additions & 3 deletions lua/dapui/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function UIState:set_variable(container_ref, variable, value)
{ expression = variable.evaluateName, value = value, frameId = frame_id },
function(err)
if err then
vim.notify(util.format_error(err))
util.notify(util.format_error(err))
end
end
)
Expand All @@ -243,12 +243,12 @@ function UIState:set_variable(container_ref, variable, value)
{ variablesReference = container_ref, name = variable.name, value = value },
function(err)
if err then
vim.notify(util.format_error(err))
util.notify(util.format_error(err))
end
end
)
else
vim.notify(
util.notify(
"Debug server doesn't support setting " .. (variable.evaluateName or variable.name),
vim.log.levels.WARN
)
Expand Down
18 changes: 16 additions & 2 deletions lua/dapui/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ function M.round(num)
end
end

function M.notify(msg, level, opts)
return vim.notify(
msg,
level or vim.log.levels.INFO,
vim.tbl_extend("keep", opts or {}, {
title = "nvim-dap-ui",
icon = "",
on_open = function(win)
vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
end,
})
)
end

function M.is_uri(path)
local scheme = path:match("^([a-z]+)://.*")
if scheme then
Expand Down Expand Up @@ -76,7 +90,7 @@ function M.jump_to_frame(frame, session, set_frame)
return
end
if not response.body.content then
vim.notify("No source available for frame", vim.log.levels.WARN)
M.notify("No source available for frame", vim.log.levels.WARN)
return
end
vim.api.nvim_buf_set_lines(buf, 0, 0, true, vim.split(response.body.content, "\n"))
Expand All @@ -88,7 +102,7 @@ function M.jump_to_frame(frame, session, set_frame)
end

if not source.path then
vim.notify("No source available for frame", vim.log.levels.WARN)
M.notify("No source available for frame", vim.log.levels.WARN)
end

local path = source.path
Expand Down
2 changes: 1 addition & 1 deletion lua/dapui/windows/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function create_win_states(win_configs)
win_state.init_size = win_state.size
win_states[#win_states + 1] = win_state
else
vim.notify("nvim-dap-ui: Element " .. win_state.id .. " does not exist", vim.log.levels.WARN)
util.notify("nvim-dap-ui: Element " .. win_state.id .. " does not exist", vim.log.levels.WARN)
end
end
return win_states
Expand Down

0 comments on commit 6a82715

Please sign in to comment.