1
- let s: supports_floating = exists (' *nvim_open_win' )
1
+ let s: supports_floating = exists (' *nvim_open_win' ) || has ( ' patch-8.1.1517 ' )
2
2
let s: win = v: false
3
3
4
4
function ! lsp#ui#vim#output#closepreview () abort
@@ -63,6 +63,7 @@ function! s:get_float_positioning(height, width) abort
63
63
endfunction
64
64
65
65
function ! lsp#ui#vim#output#floatingpreview (data) abort
66
+ if has (" nvim" )
66
67
let l: buf = nvim_create_buf (v: false , v: true )
67
68
call setbufvar (l: buf , ' &signcolumn' , ' no' )
68
69
@@ -83,6 +84,43 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
83
84
" Enable closing the preview with esc, but map only in the scratch buffer
84
85
nmap <buffer> <silent> <esc> :pclose<cr>
85
86
return s: win
87
+ else
88
+ return popup_atcursor (' ...' , {
89
+ \ ' moved' : ' any' ,
90
+ \ ' border' : [1 , 1 , 1 , 1 ],
91
+ \} )
92
+ endif
93
+ endfunction
94
+
95
+ function ! s: setcontent (lines , ft ) abort
96
+ if s: supports_floating && g: lsp_preview_float && ! has (" nvim" )
97
+ " vim popup
98
+ echom " Vimp Popup SetContent"
99
+ call setbufline (winbufnr (s: win ), 1 , a: lines )
100
+ call win_execute (s: win , ' setlocal filetype=' . a: ft . ' .lsp-hover' )
101
+ else
102
+ " nvim floating
103
+ call setline (1 , a: lines )
104
+ setlocal readonly nomodifiable
105
+ let &l: filetype = a: ft . ' .lsp-hover'
106
+ endif
107
+ endfunction
108
+
109
+ function ! s: adjust_float_placement (bufferlines, maxwidth) abort
110
+ if has (" nvim" )
111
+ let l: win_config = {}
112
+ let l: height = min ([winheight (s: win ), a: bufferlines ])
113
+ let l: width = min ([winwidth (s: win ), a: maxwidth ])
114
+ let l: win_config = s: get_float_positioning (l: height , l: width )
115
+ call nvim_win_set_config (s: win , l: win_config )
116
+ endif
117
+ endfunction
118
+
119
+ function ! s: add_float_closing_hooks () abort
120
+ augroup lsp_float_preview_close
121
+ autocmd ! lsp_float_preview_close CursorMoved ,CursorMovedI ,VimResized *
122
+ autocmd CursorMoved ,CursorMovedI ,VimResized * call lsp#ui#vim#output#closepreview ()
123
+ augroup END
86
124
endfunction
87
125
88
126
function ! lsp#ui#vim#output#preview (data) abort
@@ -92,19 +130,16 @@ function! lsp#ui#vim#output#preview(data) abort
92
130
let l: current_window_id = win_getid ()
93
131
94
132
if s: supports_floating && g: lsp_preview_float
95
- call lsp#ui#vim#output#floatingpreview (a: data )
133
+ let s: win = lsp#ui#vim#output#floatingpreview (a: data )
96
134
else
97
135
execute &previewheight .' new'
136
+ let s: win = win_getid ()
98
137
endif
99
- let s: win = win_getid ()
100
-
101
- let l: ft = s: append (a: data )
102
- " Delete first empty line
103
- 0 delete _
104
138
105
- setlocal readonly nomodifiable
139
+ let l: lines = []
140
+ let l: ft = s: append (a: data , l: lines )
141
+ call s: setcontent (l: lines , l: ft )
106
142
107
- let &l: filetype = l: ft . ' .lsp-hover'
108
143
" Get size information while still having the buffer active
109
144
let l: bufferlines = line (' $' )
110
145
let l: maxwidth = max (map (getline (1 , ' $' ), ' strdisplaywidth(v:val)' ))
@@ -116,39 +151,32 @@ function! lsp#ui#vim#output#preview(data) abort
116
151
117
152
echo ' '
118
153
119
- if s: supports_floating && s: win && g: lsp_preview_float
120
- let l: win_config = {}
121
- let l: height = min ([winheight (s: win ), l: bufferlines ])
122
- let l: width = min ([winwidth (s: win ), l: maxwidth ])
123
- let l: win_config = s: get_float_positioning (l: height , l: width )
124
- call nvim_win_set_config (s: win , l: win_config )
125
- augroup lsp_float_preview_close
126
- autocmd ! lsp_float_preview_close CursorMoved ,CursorMovedI ,VimResized *
127
- autocmd CursorMoved ,CursorMovedI ,VimResized * call lsp#ui#vim#output#closepreview ()
128
- augroup END
154
+ if s: supports_floating && s: win && g: lsp_preview_float && has (" nvim" )
155
+ call s: adjust_float_placement (l: bufferlines , l: maxwidth )
156
+ call s: add_float_closing_hooks ()
129
157
endif
130
158
return ' '
131
159
endfunction
132
160
133
- function ! s: append (data) abort
161
+ function ! s: append (data, lines ) abort
134
162
if type (a: data ) == type ([])
135
163
for l: entry in a: data
136
- call s: append (entry)
164
+ call s: append (entry, a: lines )
137
165
endfor
138
166
139
167
return ' markdown'
140
168
elseif type (a: data ) == type (' ' )
141
- silent put = a: data
169
+ call extend ( a: lines , split ( a: data, " \n " ))
142
170
143
171
return ' markdown'
144
172
elseif type (a: data ) == type ({}) && has_key (a: data , ' language' )
145
- silent put = ' ```' .a: data .language
146
- silent put = a: data .value
147
- silent put = ' ```'
173
+ call add ( a: lines , ' ```' .a: data .language )
174
+ call extend ( a: lines , split ( a: data .value, ' \n ' ))
175
+ call add ( a: lines , ' ```' )
148
176
149
177
return ' markdown'
150
178
elseif type (a: data ) == type ({}) && has_key (a: data , ' kind' )
151
- silent put = a: data .value
179
+ call add ( a: lines , a: data .value)
152
180
153
181
return a: data .kind == ? ' plaintext' ? ' text' : a: data .kind
154
182
endif
0 commit comments