Skip to content

Commit 6098f39

Browse files
committed
fix(diagnostic): check window validity. Fixes #55
1 parent ef3b9a0 commit 6098f39

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ end
105105
---@param opts DiagnosticConfig
106106
---@param event table
107107
local function apply_virtual_texts(opts, event)
108+
local current_win = vim.api.nvim_get_current_win()
109+
if not vim.api.nvim_win_is_valid(current_win) then
110+
return
111+
end
112+
108113
if not (M.enabled and vim.diagnostic.is_enabled() and vim.api.nvim_buf_is_valid(event.buf)) then
109114
extmarks.clear(event.buf)
110115
return
@@ -238,9 +243,6 @@ local function setup_buffer_autocmds(autocmd_ns, opts, event, throttled_apply)
238243
group = autocmd_ns,
239244
buffer = event.buf,
240245
callback = function()
241-
if not vim.api.nvim_buf_is_valid(event.buf) then
242-
detach_buffer(event.buf)
243-
end
244246
detach_buffer(event.buf)
245247
end,
246248
})

lua/tiny-inline-diagnostic/extmarks.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ end
2828

2929
---@return {row: number, col: number}
3030
local function get_window_position()
31+
local ok_winline, result_winline = pcall(vim.fn.winline)
32+
local ok_virtcol, result_virtcol = pcall(vim.fn.virtcol, "$")
33+
local ok_winsaveview, result_winsaveview = pcall(vim.fn.winsaveview)
34+
35+
if not ok_winline or not ok_virtcol or not ok_winsaveview then
36+
return { row = 0, col = 0 }
37+
end
38+
3139
return {
32-
row = vim.fn.winline() - 1,
33-
col = vim.fn.virtcol("$") - vim.fn.winsaveview().leftcol,
40+
row = result_winline - 1,
41+
col = result_virtcol - result_winsaveview.leftcol,
3442
}
3543
end
3644

0 commit comments

Comments
 (0)