Skip to content

Commit 989d86d

Browse files
committed
fix: run update hook on win creation, other fixes
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent 7642402 commit 989d86d

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

lua/hoversplit/init.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ function M.check_hover_support(bufnr)
1717

1818
-- Check if there are any available LSP clients that support hovering
1919
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = "textDocument/hover" })
20-
if vim.tbl_isempty(clients) then
21-
return false
22-
end
23-
24-
return true
20+
return not vim.tbl_isempty(clients)
2521
end
2622

2723
function M.update_hover_content()
@@ -33,11 +29,12 @@ function M.update_hover_content()
3329
local bufnr = vim.api.nvim_get_current_buf()
3430
local win = vim.api.nvim_get_current_win()
3531
local cursor_pos = vim.api.nvim_win_get_cursor(win)
32+
local row, col = cursor_pos[1], cursor_pos[2]
3633
local line_count = vim.api.nvim_buf_line_count(bufnr)
37-
local current_line = vim.api.nvim_buf_get_lines(bufnr, cursor_pos[1] - 1, cursor_pos[1], false)[1] or ""
34+
local current_line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1] or ""
3835

3936
-- Validate the cursor position
40-
if cursor_pos[1] < 1 or cursor_pos[1] > line_count or cursor_pos[2] < 0 or cursor_pos[2] > current_line:len() then
37+
if row < 1 or row > line_count or col < 0 or col > current_line:len() then
4138
vim.notify("Invalid cursor position detected. Skipping hover content update.", vim.log.levels.WARN)
4239
return
4340
end
@@ -78,7 +75,7 @@ function M.create_hover_split(vertical, remain_focused)
7875
group = augroup,
7976
callback = function(ev)
8077
if ev.buf == M.hover_bufnr then
81-
vim.keymap.set('n', 'q', M.close_hover_split, {
78+
vim.keymap.set("n", "q", M.close_hover_split, {
8279
noremap = true,
8380
silent = true,
8481
buffer = ev.buf,
@@ -122,14 +119,17 @@ function M.create_hover_split(vertical, remain_focused)
122119
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
123120
group = augroup,
124121
callback = function(args)
125-
if args.buf == M.hover_bufnr then
126-
return
127-
end
128-
if M.check_hover_support(args.buf) then
129-
M.update_hover_content()
122+
if args.buf ~= M.hover_bufnr then
123+
if M.check_hover_support(args.buf) then
124+
M.update_hover_content()
125+
end
130126
end
131127
end,
132128
})
129+
130+
if vim.api.nvim_get_current_win() ~= M.hover_winid then
131+
M.update_hover_content()
132+
end
133133
end
134134

135135
function M.split()
@@ -158,7 +158,7 @@ end
158158

159159
function M.setup(options)
160160
options = options or {}
161-
config.options = vim.tbl_deep_extend('force', config.options, options)
161+
config.options = vim.tbl_deep_extend("force", config.options, options)
162162

163163
if config.options.key_bindings_disabled then
164164
return
@@ -168,28 +168,28 @@ function M.setup(options)
168168
"n",
169169
config.options.key_bindings.split_remain_focused,
170170
M.split_remain_focused,
171-
{ noremap = true, silent = true, desc = 'HoverSplit split (Remain Focused)' }
171+
{ noremap = true, silent = true, desc = "HoverSplit split (Remain Focused)" }
172172
)
173173

174174
vim.keymap.set(
175175
"n",
176176
config.options.key_bindings.vsplit_remain_focused,
177177
M.vsplit_remain_focused,
178-
{ noremap = true, silent = true, desc = 'HoverSplit vsplit (Remain Focused)' }
178+
{ noremap = true, silent = true, desc = "HoverSplit vsplit (Remain Focused)" }
179179
)
180180

181181
vim.keymap.set(
182182
"n",
183183
config.options.key_bindings.split,
184184
M.split,
185-
{ noremap = true, silent = true, desc = 'HoverSplit split' }
185+
{ noremap = true, silent = true, desc = "HoverSplit split" }
186186
)
187187

188188
vim.keymap.set(
189189
"n",
190190
config.options.key_bindings.vsplit,
191191
M.vsplit,
192-
{ noremap = true, silent = true, desc = 'HoverSplit vsplit' }
192+
{ noremap = true, silent = true, desc = "HoverSplit vsplit" }
193193
)
194194
end
195195

setup.lua.example

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)