|
83 | 83 | ---@param bbufnr integer
|
84 | 84 | ---@param handler Handler
|
85 | 85 | local function render_handler(bufnr, winid, bbufnr, handler)
|
86 |
| - local name = handler.name |
87 |
| - |
88 | 86 | if not handler:enabled() then
|
89 | 87 | return
|
90 | 88 | end
|
91 | 89 |
|
| 90 | + if not api.nvim_buf_is_loaded(bbufnr) then |
| 91 | + return |
| 92 | + end |
| 93 | + |
| 94 | + local max_pos = api.nvim_buf_line_count(bbufnr) - 1 |
| 95 | + local name = handler.name |
92 | 96 | local handler_config = user_config.handlers[name] or {}
|
93 | 97 |
|
94 | 98 | api.nvim_buf_clear_namespace(bbufnr, handler.ns, 0, -1)
|
95 | 99 | for _, m in ipairs(handler.update(bufnr, winid)) do
|
96 | 100 | local pos, symbol = m.pos, m.symbol
|
97 | 101 |
|
98 |
| - local opts = { |
99 |
| - id = not m.unique and pos + 1 or nil, |
100 |
| - priority = handler_config.priority, |
101 |
| - } |
102 |
| - |
103 |
| - if handler_config.overlap ~= false then |
104 |
| - opts.virt_text = { { symbol, m.highlight } } |
105 |
| - opts.virt_text_pos = 'overlay' |
106 |
| - opts.hl_mode = 'combine' |
107 |
| - else |
108 |
| - -- Signs are 2 chars so fill the first char with whitespace |
109 |
| - opts.sign_text = ' ' .. symbol |
110 |
| - opts.sign_hl_group = m.highlight |
111 |
| - end |
| 102 | + if pos <= max_pos then |
| 103 | + local opts = { |
| 104 | + id = not m.unique and pos + 1 or nil, |
| 105 | + priority = handler_config.priority, |
| 106 | + } |
| 107 | + |
| 108 | + if handler_config.overlap ~= false then |
| 109 | + opts.virt_text = { { symbol, m.highlight } } |
| 110 | + opts.virt_text_pos = 'overlay' |
| 111 | + opts.hl_mode = 'combine' |
| 112 | + else |
| 113 | + -- Signs are 2 chars so fill the first char with whitespace |
| 114 | + opts.sign_text = ' ' .. symbol |
| 115 | + opts.sign_hl_group = m.highlight |
| 116 | + end |
112 | 117 |
|
113 |
| - local ok, err = pcall(api.nvim_buf_set_extmark, bbufnr, handler.ns, pos, 0, opts) |
114 |
| - if not ok then |
115 |
| - print( |
116 |
| - string.format( |
117 |
| - 'error(satellite.nvim): handler=%s buf=%d row=%d opts=%s, err="%s"', |
118 |
| - handler.name, |
119 |
| - bbufnr, |
120 |
| - pos, |
121 |
| - vim.inspect(opts, { newline = ' ', indent = '' }), |
122 |
| - err |
| 118 | + local ok, err = pcall(api.nvim_buf_set_extmark, bbufnr, handler.ns, pos, 0, opts) |
| 119 | + if not ok then |
| 120 | + print( |
| 121 | + string.format( |
| 122 | + 'error(satellite.nvim): handler=%s buf=%d row=%d opts=%s, err="%s"', |
| 123 | + handler.name, |
| 124 | + bbufnr, |
| 125 | + pos, |
| 126 | + vim.inspect(opts, { newline = ' ', indent = '' }), |
| 127 | + err |
| 128 | + ) |
123 | 129 | )
|
124 |
| - ) |
| 130 | + end |
125 | 131 | end
|
126 | 132 | end
|
127 | 133 | end
|
128 | 134 |
|
129 |
| ----@param winid integer |
130 |
| ----@param bar_winid integer |
131 |
| ----@param toprow integer |
132 |
| -local function reposition_bar(winid, bar_winid, toprow) |
133 |
| - local winwidth = api.nvim_win_get_width(winid) |
134 |
| - local wininfo = vim.fn.getwininfo(bar_winid)[1] |
135 |
| - |
136 |
| - --- @type integer |
137 |
| - local signwidth = wininfo.textoff |
138 |
| - |
139 |
| - local cfg = { |
140 |
| - relative = 'win', |
141 |
| - win = winid, |
142 |
| - row = 0, |
143 |
| - col = winwidth - signwidth - 1, |
144 |
| - width = 1 + signwidth, |
145 |
| - } |
146 |
| - |
147 |
| - api.nvim_win_set_config(bar_winid, cfg) |
148 |
| - |
149 |
| - vim.w[bar_winid].col = cfg.col |
150 |
| - vim.w[bar_winid].width = cfg.width |
151 |
| - vim.w[bar_winid].row = toprow |
152 |
| -end |
| 135 | +-----@param winid integer |
| 136 | +-----@param bar_winid integer |
| 137 | +-----@param toprow integer |
| 138 | +--local function reposition_bar(winid, bar_winid, toprow) |
| 139 | +-- local winwidth = api.nvim_win_get_width(winid) |
| 140 | +-- local wininfo = vim.fn.getwininfo(bar_winid)[1] |
| 141 | + |
| 142 | +-- --- @type integer |
| 143 | +-- local signwidth = wininfo.textoff |
| 144 | + |
| 145 | +-- local cfg = { |
| 146 | +-- relative = 'win', |
| 147 | +-- win = winid, |
| 148 | +-- row = 0, |
| 149 | +-- col = winwidth - signwidth - 1, |
| 150 | +-- width = 1 + signwidth, |
| 151 | +-- } |
| 152 | + |
| 153 | +-- api.nvim_win_set_config(bar_winid, cfg) |
| 154 | + |
| 155 | +-- vim.w[bar_winid].col = cfg.col |
| 156 | +-- vim.w[bar_winid].width = cfg.width |
| 157 | +-- vim.w[bar_winid].row = toprow |
| 158 | +--end |
153 | 159 |
|
154 | 160 | ---@param bbufnr integer
|
155 | 161 | ---@param winid integer
|
|
0 commit comments