Skip to content

Commit

Permalink
ui,notifications: add a module which creates a notification popup
Browse files Browse the repository at this point in the history
this commit adds a lua module for generating a notification popup.

wired into the async symbol gather function so users get an idea that
work is being done instead of just waiting for the calltree to open.

Signed-off-by: ldelossa <[email protected]>
  • Loading branch information
ldelossa committed Dec 5, 2021
1 parent 5e620a7 commit 5cfe069
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua/calltree/lsp/util.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local tree_node = require('calltree.tree.node')
local notify = require('calltree.ui.notify')
local M = {}

M.multi_client_request = function(clients, method, params, handler, bufnr)
Expand Down Expand Up @@ -199,10 +200,11 @@ function M.gather_symbols_async(root, children, ui_state, callback)
table.insert(all_nodes, child)
end
co = coroutine.create(function()
for _, node in ipairs(all_nodes) do
for i, node in ipairs(all_nodes) do
local params = {
query = node.name,
}
notify.notify_popup("gathering symbols [" .. i .. "/" .. #all_nodes .. "]")
M.multi_client_request(
ui_state.active_lsp_clients,
"workspace/symbol",
Expand All @@ -212,6 +214,7 @@ function M.gather_symbols_async(root, children, ui_state, callback)
ui_state.invoking_calltree_win
)
node.symbol = coroutine.yield()
notify.close_notify_popup()
end
callback()
end)
Expand Down
51 changes: 51 additions & 0 deletions lua/calltree/ui/notify.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local M = {}

local float_wins = {}

function M.close_notify_popup()
for _, float_win in ipairs(float_wins) do
if vim.api.nvim_win_is_valid(float_win) then
vim.api.nvim_win_close(float_win, true)
end
end
float_wins = nil
end

function M.notify_popup(text)
if float_wins == nil then
float_wins = {}
end

local buf = vim.api.nvim_create_buf(false, true)
if buf == 0 then
vim.api.nvim_err_writeln("details_popup: could not create details buffer")
return
end
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete')
vim.api.nvim_buf_set_option(buf, 'syntax', 'yaml')

local lines = {text}
local width = 20
local line_width = vim.fn.strdisplaywidth(text)
if line_width > width then
width = line_width
end

vim.api.nvim_buf_set_option(buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines)
vim.api.nvim_buf_set_option(buf, 'modifiable', false)
local popup_conf = {
relative = "win",
anchor = "SE",
width = width,
height = 1,
focusable = false,
zindex = 99,
style = "minimal",
border = "rounded",
bufpos = {999999999, -1}
}
table.insert(float_wins, vim.api.nvim_open_win(buf, false, popup_conf))
end

return M

0 comments on commit 5cfe069

Please sign in to comment.