Skip to content

Commit 8b34809

Browse files
committed
usability: various changes to help useability
various changes which make the UI a little easier to use. CTToggle is renamed to CTPanel. Signed-off-by: ldelossa <louis.delos@gmail.com>
1 parent 5cfe069 commit 8b34809

File tree

6 files changed

+103
-57
lines changed

6 files changed

+103
-57
lines changed

doc/calltree.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ A unified panel would feel similar to IDE's such as VSCode where you can "hide"
6969
and "unhide" a persistent informational panel. Both the symbol tree and the call tree will
7070
always be present in the toggled panel, unless you manually close a window.
7171
Toggling the panel will recreate any closed windows. This functionality
72-
is provided via the "CTToggle" command.
72+
is provided via the "CTPanel" command.
7373

7474
If you'd rather use each individual component separately this is possible
7575
too. Utilize the "CTOpen/CTClose" and "STOpen/STClose" commands. These commands
@@ -89,20 +89,25 @@ Calltree exports several commands for manipulating the calltree UI.
8989
*:CTOpen*
9090
:CTOpen
9191
Open the calltree window with the most recent call tree present.
92+
As a convenience, calling this again will jump back to the window
93+
which opened the calltree.
9294

9395
*:CTClose*
9496
:CTClose
9597
Closes the calltree window.
96-
*:STOpen*
98+
9799

98-
*:CTToggle*
99-
:CTToggle
100+
*:CTPanel*
101+
:CTPanel
100102
Treats calltree as a persistent panel and toggles it open or close.
101103
Using this command will always toggle both the symboltree and calltree
102104
components as if they were a single unified panel.
103105

106+
*:STOpen*
104107
:STOpen
105108
Open the symboltree window with the most recent outline tree present.
109+
As a convenience, calling this again will jump back to the window
110+
which opened the symboltree.
106111

107112
*:STClose*
108113
:STClose
@@ -155,8 +160,13 @@ Calltree exports several commands for manipulating the calltree UI.
155160

156161
*:CTDumpTree*
157162
:CTDumpTree
158-
Echos the current calltree in lua dictonary syntax.
159-
Useful for debugging.
163+
Only valid when inside a calltree window.
164+
Dumps the tree data structure to a buffer for debugging.
165+
166+
*:CTDumpNode*
167+
:CTDumpNode
168+
Same as CTDumpTree but dumps the current node and it's children to
169+
a buffer for debugging.
160170

161171
====================================================================================
162172
MAPPINGS *calltree-mappings*
@@ -200,8 +210,6 @@ The config table is described below:
200210
-- int - An integer used in the initial "resize" command for
201211
-- the ui.
202212
layout_size = 30,
203-
-- whether to automatically open the calltree and symboltree ui on start.
204-
auto_open = false,
205213
-- the method used when jumping to a symbol in the calltree
206214
-- "invoking" - Jumping to a symbol will use the window which the calltree
207215
-- was initially invoked from.
@@ -245,6 +253,10 @@ The config table is described below:
245253
-- if set to true calling LSP functions which trigger calltree UI
246254
-- will open the unified panel. see *calltree-usage* for details.
247255
unified_panel = false
256+
-- whether to automatically open the unified ui on start.
257+
-- unified_panel need not be true to open the panel
258+
-- on start.
259+
auto_open_panel = false,
248260
-- automatic highlighting and window position updates when
249261
-- navigating the symboltree UI. Set to false to disable.
250262
auto_highlight = true

lua/calltree.lua

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ local M = {}
44
M.config = {
55
layout = "left",
66
layout_size = 30,
7-
auto_open = false,
87
jump_mode = "invoking",
98
icons = "none",
109
no_hls = false,
@@ -13,6 +12,7 @@ M.config = {
1312
hls = {},
1413
resolve_symbols = true,
1514
unified_panel = false,
15+
auto_open_panel = false,
1616
auto_highlight = true
1717
}
1818

@@ -74,6 +74,33 @@ function _setup_default_highlights()
7474
end
7575
end
7676

77+
local function sanatize_config()
78+
-- sanatize the config
79+
if (M.config.layout ~= "left")
80+
and (M.config.layout ~= "right")
81+
and (M.config.layout ~= "top")
82+
and (M.config.layout ~= "bottom")
83+
then
84+
M.config.layout = "left"
85+
end
86+
if M.config.layout_size < 10 then
87+
M.config.layout_size = 10
88+
end
89+
if M.config.jump_mode ~= "invoking" and M.config.jump_mode ~= "neighbor" then
90+
M.config.jump_mode = "neighbor"
91+
end
92+
if M.config.icons ~= "codicons" and M.config.icons ~= "nerd" then
93+
M.config.icons = "none"
94+
else
95+
if M.config.icons == "codicons" then
96+
M.active_icon_set = M.codicons
97+
end
98+
if M.config.icons == "nerd" then
99+
M.active_icon_set = M.nerd
100+
end
101+
end
102+
end
103+
77104
function M.setup(user_config)
78105
-- hijack the normal lsp handlers
79106
vim.lsp.handlers['callHierarchy/incomingCalls'] = vim.lsp.with(
@@ -108,30 +135,7 @@ function M.setup(user_config)
108135
end
109136
end
110137

111-
-- sanatize the config
112-
if (M.config.layout ~= "left")
113-
and (M.config.layout ~= "right")
114-
and (M.config.layout ~= "top")
115-
and (M.config.layout ~= "bottom")
116-
then
117-
M.config.layout = "left"
118-
end
119-
if M.config.layout_size < 10 then
120-
M.config.layout_size = 10
121-
end
122-
if M.config.jump_mode ~= "invoking" and M.config.jump_mode ~= "neighbor" then
123-
M.config.jump_mode = "neighbor"
124-
end
125-
if M.config.icons ~= "codicons" and M.config.icons ~= "nerd" then
126-
M.config.icons = "none"
127-
else
128-
if M.config.icons == "codicons" then
129-
M.active_icon_set = M.codicons
130-
end
131-
if M.config.icons == "nerd" then
132-
M.active_icon_set = M.nerd
133-
end
134-
end
138+
sanatize_config()
135139

136140
-- setup default highlights
137141
if not M.config.no_hls then
@@ -140,32 +144,31 @@ function M.setup(user_config)
140144

141145
-- automatically open the ui elements on buf enters.
142146
if M.config.auto_open then
143-
vim.cmd([[au BufEnter * lua require('calltree.ui').open_calltree()]])
144-
vim.cmd([[au BufEnter * lua require('calltree.ui').open_symboltree()]])
147+
vim.cmd([[au VimEnter * lua require('calltree.ui').toggle_panel()]])
145148
end
146149

147150
-- will keep the outline view up to date when moving around buffers.
148-
vim.cmd([[au TextChanged,BufEnter,BufWritePost * lua require('calltree.ui').refresh_symbol_tree()]])
151+
vim.cmd([[au TextChanged,BufEnter,BufWritePost,WinEnter * lua require('calltree.ui').refresh_symbol_tree()]])
149152

150153
-- will enable symboltree ui tracking with source code lines.
151154
vim.cmd([[au CursorHold * lua require('calltree.ui').source_tracking()]])
152155

153-
-- setup commands
154-
vim.cmd("command! CTOpen lua require('calltree.ui').open_to('calltree')")
155-
vim.cmd("command! STOpen lua require('calltree.ui').open_to('symboltree')")
156-
vim.cmd("command! CTToggle lua require('calltree.ui').toggle_panel()")
157-
vim.cmd("command! CTClose lua require('calltree.ui').close_calltree()")
158-
vim.cmd("command! STClose lua require('calltree.ui').close_symboltree()")
159-
vim.cmd("command! CTExpand lua require('calltree.ui').expand()")
160-
vim.cmd("command! CTCollapse lua require('calltree.ui').collapse()")
161-
vim.cmd("command! CTSwitch lua require('calltree.ui').switch_direction()")
162-
vim.cmd("command! CTFocus lua require('calltree.ui').focus()")
163-
vim.cmd("command! CTJump lua require('calltree.ui').jump()")
164-
vim.cmd("command! CTHover lua require('calltree.ui').hover()")
165-
vim.cmd("command! CTDetails lua require('calltree.ui').details()")
166-
vim.cmd("command! CTClearHL lua require('calltree.ui.jumps').set_jump_hl(false)")
167-
vim.cmd("command! CTDumpTree lua require('calltree.ui').dump_tree()")
168-
vim.cmd("command! CTDumpNode lua require('calltree.ui').dump_node()")
156+
-- setup commands
157+
vim.cmd("command! CTOpen lua require('calltree.ui').open_to('calltree')")
158+
vim.cmd("command! STOpen lua require('calltree.ui').open_to('symboltree')")
159+
vim.cmd("command! CTPanel lua require('calltree.ui').toggle_panel()")
160+
vim.cmd("command! CTClose lua require('calltree.ui').close_calltree()")
161+
vim.cmd("command! STClose lua require('calltree.ui').close_symboltree()")
162+
vim.cmd("command! CTExpand lua require('calltree.ui').expand()")
163+
vim.cmd("command! CTCollapse lua require('calltree.ui').collapse()")
164+
vim.cmd("command! CTSwitch lua require('calltree.ui').switch_direction()")
165+
vim.cmd("command! CTFocus lua require('calltree.ui').focus()")
166+
vim.cmd("command! CTJump lua require('calltree.ui').jump()")
167+
vim.cmd("command! CTHover lua require('calltree.ui').hover()")
168+
vim.cmd("command! CTDetails lua require('calltree.ui').details()")
169+
vim.cmd("command! CTClearHL lua require('calltree.ui.jumps').set_jump_hl(false)")
170+
vim.cmd("command! CTDumpTree lua require('calltree.ui').dump_tree()")
171+
vim.cmd("command! CTDumpNode lua require('calltree.ui').dump_node()")
169172
end
170173

171174
-- the configured icon set after setup() is ran.

lua/calltree/lsp/handlers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ M.ch_lsp_handler = function(direction)
6868
if config.resolve_symbols then
6969
lsp_util.gather_symbols_async(root, children, ui_state, function()
7070
tree.add_node(ui_state.calltree_handle, root, children)
71-
ui.open_to("calltree")
71+
ui._open_calltree()
7272
end)
7373
return
7474
end
7575
tree.add_node(ui_state.calltree_handle, root, children)
76-
ui.open_to("calltree")
76+
ui._open_calltree()
7777
end
7878
end
7979

lua/calltree/ui/buffer.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ function M._setup_buffer(name, buffer_handle, tab)
7373
vim.api.nvim_buf_set_option(buffer_handle, 'textwidth', 0)
7474
vim.api.nvim_buf_set_option(buffer_handle, 'wrapmargin', 0)
7575

76-
-- au to clear highlights on window close
76+
-- au to clear jump highlights on window close
7777
vim.cmd("au BufWinLeave <buffer=" .. buffer_handle .. "> lua require('calltree.ui.jumps').set_jump_hl(false)")
78+
7879
-- au to close popup with cursor moves or buffer is closed.
7980
vim.cmd("au CursorMoved,BufWinLeave,WinLeave <buffer=" .. buffer_handle .. "> lua require('calltree.ui.buffer').close_all_popups()")
8081

82+
-- au to (re)set source code highlights when a symboltree node is hovered.
8183
if config.auto_highlight then
8284
vim.cmd("au BufWinLeave,WinLeave <buffer=" .. buffer_handle .. "> lua require('calltree.ui').auto_highlight(false)")
8385
vim.cmd("au CursorHold <buffer=" .. buffer_handle .. "> lua require('calltree.ui').auto_highlight(true)")

lua/calltree/ui/help_buffer.lua

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
local config = require('calltree').config
12
local M = {}
23

4+
local function map_resize_keys(buffer_handle, opts)
5+
local l = config.layout
6+
if l == "top" or l == "bottom" then
7+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Right>", ":vert resize +5<cr>", opts)
8+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Left>", ":vert resize -5<cr>", opts)
9+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Up>", ":resize +5<cr>", opts)
10+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Down>", ":resize -5<cr>", opts)
11+
elseif l == "bottom" then
12+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Right>", ":vert resize +5<cr>", opts)
13+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Left>", ":vert resize -5<cr>", opts)
14+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Down>", ":resize +5<cr>", opts)
15+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Up>", ":resize -5<cr>", opts)
16+
elseif l == "left" then
17+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Up>", ":resize +5<cr>", opts)
18+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Down>", ":resize -5<cr>", opts)
19+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Left>", ":vert resize -5<cr>", opts)
20+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Right>", ":vert resize +5<cr>", opts)
21+
elseif l == "right" then
22+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Up>", ":resize +5<cr>", opts)
23+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Down>", ":resize -5<cr>", opts)
24+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Left>", ":vert resize +5<cr>", opts)
25+
vim.api.nvim_buf_set_keymap(buffer_handle, "n", "<Right>", ":vert resize -5<cr>", opts)
26+
end
27+
end
28+
329
-- _setup_help_buffer performs an idempotent creation
430
-- of the calltree help buffer
531
--
@@ -21,7 +47,7 @@ function M._setup_help_buffer(help_buf_handle)
2147
help_buf_handle = buf
2248
local lines = {
2349
"CALLTREE HELP:",
24-
"press 'c' to close",
50+
"press '?' to close",
2551
"",
2652
"KEYMAP:",
2753
"zo - expand a symbol",
@@ -46,7 +72,8 @@ function M._setup_help_buffer(help_buf_handle)
4672

4773
-- set buffer local keymaps
4874
local opts = {silent=true}
49-
vim.api.nvim_buf_set_keymap(help_buf_handle, "n", "c", ":lua require('calltree.ui').help(false)<CR>", opts)
75+
vim.api.nvim_buf_set_keymap(help_buf_handle, "n", "?", ":lua require('calltree.ui').help(false)<CR>", opts)
76+
map_resize_keys(help_buf_handle, opts)
5077

5178
return help_buf_handle
5279
end

lua/calltree/ui/window.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ end
9999
-- which want to refresh the state of the UI but not
100100
-- close the panels.
101101
function M._toggle_panel(ui_state, keep_open)
102+
local cur_win = vim.api.nvim_get_current_win()
102103
local open = true
103104
if not keep_open then
104105
for _, win_name in pairs(type_to_ui_state_win) do
@@ -118,6 +119,7 @@ function M._toggle_panel(ui_state, keep_open)
118119
-- the pannel open
119120
M._open_window("calltree", ui_state)
120121
M._open_window("symboltree", ui_state)
122+
vim.api.nvim_set_current_win(cur_win)
121123
end
122124

123125
-- setup_window evaluates the current layout and the desired layout

0 commit comments

Comments
 (0)