Skip to content

Commit

Permalink
Change widget mappings (a is menu, <CR> is expand/collapse)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Dec 2, 2021
1 parent 3482567 commit 16c2274
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions doc/dap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,12 @@ View the value for the expression under the cursor in a floating window:
<


The widgets may have the following custom mappings enabled:

- `<CR>` to expand or collapse an entry
- `a` to show a menu with available actions


Available widgets entities:

- scopes
Expand Down
5 changes: 4 additions & 1 deletion lua/dap/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ variable.tree_spec = {
get_children = variable.get_children,
fetch_children = variable.fetch_children,
compute_actions = function(info)
local result = {}
local session = require('dap').session()
if not session then
return {}
end
local result = {}
local capabilities = session.capabilities
local item = info.item
if item.evaluateName and capabilities.supportsSetExpression then
Expand Down
4 changes: 1 addition & 3 deletions lua/dap/repl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local function new_buf()
if ok then
api.nvim_buf_set_option(buf, 'path', path)
end
api.nvim_buf_set_keymap(buf, 'n', '<CR>', "<Cmd>lua require('dap.repl').on_enter()<CR>", {})
api.nvim_buf_set_keymap(buf, 'n', '<CR>', "<Cmd>lua require('dap.ui').trigger_actions({ filter = 'Expand' })<CR>", {})
api.nvim_buf_set_keymap(buf, 'i', '<up>', "<Cmd>lua require('dap.repl').on_up()<CR>", {})
api.nvim_buf_set_keymap(buf, 'i', '<down>', "<Cmd>lua require('dap.repl').on_down()<CR>", {})
vim.fn.prompt_setprompt(buf, 'dap> ')
Expand Down Expand Up @@ -243,8 +243,6 @@ M.open = repl.open
--- Open the REPL if it is closed, close it if it is open.
M.toggle = repl.toggle

M.on_enter = ui.trigger_actions


local function select_history(delta)
if not repl.buf then
Expand Down
15 changes: 9 additions & 6 deletions lua/dap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,17 @@ function M.trigger_actions(opts)
lnum = lnum - 1
local info = layer.get(lnum, 0, col)
local context = info and info.context or {}
local actions = context and context.actions or {}
local compute_actions = context and context.compute_actions
if compute_actions then
vim.list_extend(actions, compute_actions(info))
local actions = {}
vim.list_extend(actions, context.actions or {})
if context.compute_actions then
vim.list_extend(actions, context.compute_actions(info))
end
if opts.filter then
actions = vim.tbl_filter(opts.filter, actions)
local filter = (type(opts.filter) == 'function'
and opts.filter
or function(x) return x.label == opts.filter end
)
actions = vim.tbl_filter(filter, actions)
end
if #actions == 0 then
utils.notify('No action possible on: ' .. api.nvim_buf_get_lines(buf, lnum, lnum + 1, true)[1], vim.log.levels.INFO)
Expand Down Expand Up @@ -404,7 +408,6 @@ function M.layer(buf)
render = function(xs, render_fn, context, start, end_)
local modifiable = api.nvim_buf_get_option(buf, 'modifiable')
api.nvim_buf_set_option(buf, 'modifiable', true)

start = start or M.get_last_lnum(buf)
end_ = end_ or start
render_fn = render_fn or tostring
Expand Down
5 changes: 4 additions & 1 deletion lua/dap/ui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ local M = {}

local function new_buf()
local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_option(buf, 'modifiable', false)
api.nvim_buf_set_option(buf, 'buftype', 'nofile')
api.nvim_buf_set_option(buf, 'modifiable', false)
api.nvim_buf_set_keymap(
buf, "n", "<CR>", "<Cmd>lua require('dap.ui').trigger_actions()<CR>", {})
buf, "n", "<CR>", "<Cmd>lua require('dap.ui').trigger_actions({ filter = 'Expand' })<CR>", {})
api.nvim_buf_set_keymap(
buf, "n", "a", "<Cmd>lua require('dap.ui').trigger_actions()<CR>", {})
api.nvim_buf_set_keymap(
buf, "n", "<2-LeftMouse>", "<Cmd>lua require('dap.ui').trigger_actions()<CR>", {})
return buf
Expand Down

0 comments on commit 16c2274

Please sign in to comment.