@@ -17,7 +17,9 @@ function docs.setup()
17
17
autocomplete .listen_on_position_update (function ()
18
18
if autocomplete .win :get_win () then docs .update_position () end
19
19
end )
20
- autocomplete .listen_on_select (function (item ) docs .show_item (item ) end )
20
+ if config .windows .documentation .auto_show then
21
+ autocomplete .listen_on_select (function (item ) docs .show_item (item ) end )
22
+ end
21
23
autocomplete .listen_on_close (function () docs .win :close () end )
22
24
23
25
return docs
@@ -66,12 +68,15 @@ function docs.update_position()
66
68
local autocomplete_winnr = autocomplete .win :get_win ()
67
69
if not autocomplete_winnr then return end
68
70
local autocomplete_win_config = vim .api .nvim_win_get_config (autocomplete_winnr )
69
- local function set_config (opts )
70
- vim .api .nvim_win_set_config (winnr , { relative = ' win' , win = autocomplete_winnr , row = opts .row , col = opts .col })
71
- end
72
71
73
72
local screen_width = vim .api .nvim_win_get_width (0 )
74
73
local screen_height = vim .api .nvim_win_get_height (0 )
74
+ local cursor_screen_row = vim .fn .screenrow ()
75
+
76
+ local autocomplete_win_is_up = autocomplete_win_config .row - cursor_screen_row < 0
77
+ local direction_priority = autocomplete_win_is_up
78
+ and config .windows .documentation .direction_priority .autocomplete_north
79
+ or config .windows .documentation .direction_priority .autocomplete_south
75
80
76
81
local height = vim .api .nvim_win_get_height (winnr )
77
82
local width = vim .api .nvim_win_get_width (winnr )
@@ -81,22 +86,29 @@ function docs.update_position()
81
86
local space_left = autocomplete_win_config .col > width
82
87
local space_right = screen_width - autocomplete_win_config .width - autocomplete_win_config .col > width
83
88
84
- for _ , direction in ipairs (config .windows .documentation .direction_priority ) do
89
+ local function set_config (opts )
90
+ vim .api .nvim_win_set_config (winnr , { relative = ' win' , win = autocomplete_winnr , row = opts .row , col = opts .col })
91
+ end
92
+ for _ , direction in ipairs (direction_priority ) do
85
93
if direction == ' n' and space_above then
86
- if autocomplete_win_config . row >= 0 then
94
+ if autocomplete_win_is_up then
87
95
set_config ({ row = - height , col = 0 })
88
96
else
89
97
set_config ({ row = - 1 - height , col = 0 })
90
98
end
91
99
return
92
100
elseif direction == ' s' and space_below then
93
- set_config ({ row = autocomplete_win_config .height , col = 0 })
101
+ if autocomplete_win_is_up then
102
+ set_config ({ row = 1 + autocomplete_win_config .height , col = 0 })
103
+ else
104
+ set_config ({ row = autocomplete_win_config .height , col = 0 })
105
+ end
94
106
return
95
107
elseif direction == ' e' and space_right then
96
108
set_config ({ row = 0 , col = autocomplete_win_config .width })
97
109
return
98
110
elseif direction == ' w' and space_left then
99
- set_config ({ row = 0 , col = - width })
111
+ set_config ({ row = 0 , col = - 1 - width })
100
112
return
101
113
end
102
114
end
0 commit comments