diff options
| author | William Boman <william@redwill.se> | 2021-09-11 01:20:04 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2021-09-11 01:26:12 +0200 |
| commit | 5723a1e6995b6fa54ff7ebbd4054e36059cbfd54 (patch) | |
| tree | 2a2eb701ca6fde37e6958b3789e2c5b7e61583da /lua/nvim-lsp-installer/ui/display.lua | |
| parent | add dotls (#88) (diff) | |
| download | mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar.gz mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar.bz2 mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar.lz mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar.xz mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.tar.zst mason-5723a1e6995b6fa54ff7ebbd4054e36059cbfd54.zip | |
ui/display: more robust rendering
Diffstat (limited to 'lua/nvim-lsp-installer/ui/display.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/ui/display.lua | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lua/nvim-lsp-installer/ui/display.lua b/lua/nvim-lsp-installer/ui/display.lua index b47f0455..beeb3277 100644 --- a/lua/nvim-lsp-installer/ui/display.lua +++ b/lua/nvim-lsp-installer/ui/display.lua @@ -88,8 +88,8 @@ local function render_node(context, node, _render_context, _output) -- apply indentation full_line = (" "):rep(active_styles.indentation) .. full_line - for i = 1, #line_highlights do - local highlight = line_highlights[i] + for j = 1, #line_highlights do + local highlight = line_highlights[j] highlight.col_start = highlight.col_start + active_styles.indentation highlight.col_end = highlight.col_end + active_styles.indentation output.highlights[#output.highlights + 1] = highlight @@ -114,7 +114,7 @@ end function M.new_view_only_win(name) local namespace = vim.api.nvim_create_namespace(("lsp_installer_%s"):format(name)) - local win, buf, renderer, mutate_state, get_state, unsubscribe + local buf, renderer, mutate_state, get_state, unsubscribe local has_initiated = false local function open(opts) @@ -127,7 +127,7 @@ function M.new_view_only_win(name) vim.cmd [[vnew]] end - win = vim.api.nvim_get_current_win() + local win = vim.api.nvim_get_current_win() buf = vim.api.nvim_get_current_buf() vim.api.nvim_buf_set_option(buf, "modifiable", false) @@ -157,13 +157,16 @@ function M.new_view_only_win(name) vim.cmd(highlight_groups[i]) end end + + return win end local draw = debounced(function(view) - if not win or not vim.api.nvim_win_is_valid(win) then - -- the window has been closed, e.g, by the user + local win = vim.fn.win_findbuf(buf)[1] + if not win or not vim.api.nvim_buf_is_valid(buf) then + -- the window has been closed or the buffer is somehow no longer valid unsubscribe(true) - return log.debug { "Window is no longer valid", name, win } + return log.debug { "Buffer or window is no longer valid", name, win, buf } end local win_width = vim.api.nvim_win_get_width(win) @@ -213,13 +216,14 @@ function M.new_view_only_win(name) open = vim.schedule_wrap(function(opts) log.debug { "opening window" } assert(has_initiated, "Display has not been initiated, cannot open.") + local win = vim.fn.win_findbuf(buf)[1] if win and vim.api.nvim_win_is_valid(win) then return end unsubscribe(false) - open(opts) + local opened_win = open(opts) draw(renderer(get_state())) - redraw_by_winnr[win] = function() + redraw_by_winnr[opened_win] = function() draw(renderer(get_state())) end end), |
