@@ -31,32 +31,45 @@ function! s:show_documentation(event) abort
3131
3232
3333 " Neovim
34- if s: use_nvim_float
34+ if s: use_nvim_float
3535 let l: event = a: event
3636 let l: event .row = float2nr (l: event .row)
3737 let l: event .col = float2nr (l: event .col )
3838
3939 let l: buffer = nvim_create_buf (v: false , v: true )
40- let l: curpos = win_screenpos ( nvim_get_current_win ())[ 0 ] + winline () - 1
40+ let l: curpos = screenrow ()
4141 let g: lsp_documentation_float_docked = get (g: , ' lsp_documentation_float_docked' , 0 )
4242
43+ call setbufvar (l: buffer , ' lsp_syntax_highlights' , l: syntax_lines )
44+ call setbufvar (l: buffer , ' lsp_do_conceal' , 1 )
45+ call nvim_buf_set_lines (l: buffer , 0 , -1 , v: false , l: lines )
46+ call nvim_buf_set_option (l: buffer , ' readonly' , v: true )
47+ call nvim_buf_set_option (l: buffer , ' modifiable' , v: false )
48+ call nvim_buf_set_option (l: buffer , ' filetype' , l: ft .' .lsp-hover' )
49+
50+
4351 if g: lsp_documentation_float_docked
44- let g: lsp_documentation_float_docked_maxheight = get (g: , ' : lsp_documentation_float_docked_maxheight' , &previewheight )
45- let l: dock_downwards = max ([ screenrow (), l: curpos] ) < (&lines / 2 )
52+ let g: lsp_documentation_float_docked_maxheight = get (g: , ' lsp_documentation_float_docked_maxheight' , &previewheight )
53+ let l: dock_downwards = ( l: curpos + l: event .height ) < (&lines / 2 )
4654 let l: height = min ([len (l: data ), g: lsp_documentation_float_docked_maxheight ])
4755 let l: width = &columns
4856 let l: col = 0
4957 if l: dock_downwards
5058 let l: anchor = ' SW'
5159 let l: row = &lines - &cmdheight - 1
52- let l: height = min ([l: height , &lines - &cmdheight - l: event .row - l: event .height])
60+ let l: height = min ([l: height , &lines - &cmdheight - l: event .row - l: event .height - 1 ]) - 1
61+ " Extra -1 of height to distinguish between completion popup
62+ " and documentation popup
5363 else " dock upwards
5464 let l: anchor = ' NW'
5565 let l: row = 0
5666 let l: height = min ([l: height , l: event .row - 1 ])
5767 endif
5868
5969 else " not docked
70+ let l: bufferlines = nvim_buf_line_count (l: buffer )
71+ let l: maxwidth = max (map (getbufline (l: buffer , 1 , ' $' ), ' strdisplaywidth(v:val)' ))
72+
6073 let l: row = l: event [' row' ]
6174 let l: height = max ([&lines - &cmdheight - l: row , &previewheight ])
6275
@@ -72,36 +85,40 @@ function! s:show_documentation(event) abort
7285 let l: width = l: left_area
7386 let l: col = l: event .col - 1 " 1 due to padding of completion popup
7487 endif
88+ if l: width < 0.75 * l: maxwidth
89+ let l: col = &columns
90+ let l: width = l: maxwidth
91+ let l: above = l: event .row > &lines - &cmdheight - l: event .row - l: event .height
92+ if l: above
93+ let l: anchor = ' SE'
94+ let l: row = l: event .row
95+ let l: height = l: row
96+ else
97+ let l: anchor = ' NE'
98+ let l: row = l: event .row + l: event .height
99+ let l: height = &lines - &cmdheight - l: row
100+ endif
101+ endif
75102 endif
76103
77- call setbufvar (l: buffer , ' lsp_syntax_highlights' , l: syntax_lines )
78- call setbufvar (l: buffer , ' lsp_do_conceal' , 1 )
79-
80104 " add padding on both sides of lines containing text
81105 for l: index in range (len (l: lines ))
82106 if len (l: lines [l: index ]) > 0
83107 let l: lines [l: index ] = ' ' . l: lines [l: index ] . ' '
84108 endif
85109 endfor
86110
87- call nvim_buf_set_lines (l: buffer , 0 , -1 , v: false , l: lines )
88- call nvim_buf_set_option (l: buffer , ' readonly' , v: true )
89- call nvim_buf_set_option (l: buffer , ' modifiable' , v: false )
90- call nvim_buf_set_option (l: buffer , ' filetype' , l: ft .' .lsp-hover' )
91-
92111 if ! g: lsp_documentation_float_docked
93- let l: bufferlines = nvim_buf_line_count (l: buffer )
94- let l: maxwidth = max (map (getbufline (l: buffer , 1 , ' $' ), ' strdisplaywidth(v:val)' ))
95- if g: lsp_preview_max_width > 0
96- let l: maxwidth = min ([g: lsp_preview_max_width , l: maxwidth ])
97- endif
98112 let l: width = min ([float2nr (l: width ), l: maxwidth ])
99113 let l: height = min ([float2nr (l: height ), l: bufferlines ])
100114 endif
101115 if g: lsp_preview_max_height > 0
102116 let l: maxheight = g: lsp_preview_max_height
103117 let l: height = min ([l: height , l: maxheight ])
104118 endif
119+ if g: lsp_preview_max_width > 0
120+ let l: maxwidth = min ([g: lsp_preview_max_width , l: width ])
121+ endif
105122
106123 " Height and width must be atleast 1, otherwise error
107124 let l: height = (l: height < 1 ? 1 : l: height )
0 commit comments