@@ -17,11 +17,7 @@ function M.check_hover_support(bufnr)
17
17
18
18
-- Check if there are any available LSP clients that support hovering
19
19
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 )
25
21
end
26
22
27
23
function M .update_hover_content ()
@@ -33,11 +29,12 @@ function M.update_hover_content()
33
29
local bufnr = vim .api .nvim_get_current_buf ()
34
30
local win = vim .api .nvim_get_current_win ()
35
31
local cursor_pos = vim .api .nvim_win_get_cursor (win )
32
+ local row , col = cursor_pos [1 ], cursor_pos [2 ]
36
33
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 " "
38
35
39
36
-- 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
41
38
vim .notify (" Invalid cursor position detected. Skipping hover content update." , vim .log .levels .WARN )
42
39
return
43
40
end
@@ -78,7 +75,7 @@ function M.create_hover_split(vertical, remain_focused)
78
75
group = augroup ,
79
76
callback = function (ev )
80
77
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 , {
82
79
noremap = true ,
83
80
silent = true ,
84
81
buffer = ev .buf ,
@@ -122,14 +119,17 @@ function M.create_hover_split(vertical, remain_focused)
122
119
vim .api .nvim_create_autocmd ({ " CursorMoved" , " CursorMovedI" }, {
123
120
group = augroup ,
124
121
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
130
126
end
131
127
end ,
132
128
})
129
+
130
+ if vim .api .nvim_get_current_win () ~= M .hover_winid then
131
+ M .update_hover_content ()
132
+ end
133
133
end
134
134
135
135
function M .split ()
158
158
159
159
function M .setup (options )
160
160
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 )
162
162
163
163
if config .options .key_bindings_disabled then
164
164
return
@@ -168,28 +168,28 @@ function M.setup(options)
168
168
" n" ,
169
169
config .options .key_bindings .split_remain_focused ,
170
170
M .split_remain_focused ,
171
- { noremap = true , silent = true , desc = ' HoverSplit split (Remain Focused)' }
171
+ { noremap = true , silent = true , desc = " HoverSplit split (Remain Focused)" }
172
172
)
173
173
174
174
vim .keymap .set (
175
175
" n" ,
176
176
config .options .key_bindings .vsplit_remain_focused ,
177
177
M .vsplit_remain_focused ,
178
- { noremap = true , silent = true , desc = ' HoverSplit vsplit (Remain Focused)' }
178
+ { noremap = true , silent = true , desc = " HoverSplit vsplit (Remain Focused)" }
179
179
)
180
180
181
181
vim .keymap .set (
182
182
" n" ,
183
183
config .options .key_bindings .split ,
184
184
M .split ,
185
- { noremap = true , silent = true , desc = ' HoverSplit split' }
185
+ { noremap = true , silent = true , desc = " HoverSplit split" }
186
186
)
187
187
188
188
vim .keymap .set (
189
189
" n" ,
190
190
config .options .key_bindings .vsplit ,
191
191
M .vsplit ,
192
- { noremap = true , silent = true , desc = ' HoverSplit vsplit' }
192
+ { noremap = true , silent = true , desc = " HoverSplit vsplit" }
193
193
)
194
194
end
195
195
0 commit comments