Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions autoload/lsp/ui/vim/output.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
" Enable closing the preview with esc, but map only in the scratch buffer
nmap <buffer><silent> <esc> :pclose<cr>
else
let s:winid = popup_atcursor('...', {
\ 'moved': 'any',
\ 'border': [1, 1, 1, 1],
\})
let l:options = {
\ 'moved': 'any',
\ 'border': [1, 1, 1, 1],
\ }

if g:lsp_preview_max_width > 0
let l:options['maxwidth'] = g:lsp_preview_max_width
endif

let s:winid = popup_atcursor('...', l:options)
endif
return s:winid
endfunction
Expand All @@ -139,6 +145,13 @@ function! s:setcontent(lines, ft) abort
else
" nvim floating
call setline(1, a:lines)

" Set maximum width of floating window, if specified
if g:lsp_preview_max_width > 0
let &l:textwidth = g:lsp_preview_max_width
normal! gggqGgg
endif

setlocal readonly nomodifiable
let &l:filetype = a:ft . '.lsp-hover'
endif
Expand Down
12 changes: 11 additions & 1 deletion doc/vim-lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONTENTS *vim-lsp-contents*
g:lsp_highlight_references_enabled |g:lsp_highlight_references_enabled|
g:lsp_get_vim_completion_item |g:lsp_get_vim_completion_item|
g:lsp_get_supported_capabilities |g:lsp_get_supported_capabilities|
g:lsp_preview_max_width |g:lsp_preview_max_width|
Functions |vim-lsp-functions|
enable |vim-lsp-enable|
disable |vim-lsp-disable|
Expand Down Expand Up @@ -382,6 +383,15 @@ g:lsp_get_supported_capabilities *g:lsp_get_supported_capabilities*
calling `lsp#omni#default_get_supported_capabilities` from within your
function.

g:lsp_preview_max_width *g:lsp_preview_max_width*
Type: |Number|
Default: `-1`

If positive, determines the maximum width of the preview window in
characters. Lines longer than `g:lsp_preview_max_width` will be wrapped to
fit in the preview window. Use a value of `-1` to disable setting a
maximum width.

===============================================================================
FUNCTIONS *vim-lsp-functions*

Expand Down Expand Up @@ -750,7 +760,7 @@ Closes an opened preview window
Transfers focus to an opened preview window or back to the previous window if
focus is already on the preview window.


===============================================================================
Autocomplete *vim-lsp-autocomplete*

Expand Down
1 change: 1 addition & 0 deletions plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let g:lsp_highlight_references_enabled = get(g:, 'lsp_highlight_references_enabl
let g:lsp_preview_float = get(g:, 'lsp_preview_float', 1)
let g:lsp_preview_autoclose = get(g:, 'lsp_preview_autoclose', 1)
let g:lsp_preview_doubletap = get(g:, 'lsp_preview_doubletap', [function('lsp#ui#vim#output#focuspreview')])
let g:lsp_preview_max_width = get(g:, 'lsp_preview_max_width', -1)

let g:lsp_get_vim_completion_item = get(g:, 'lsp_get_vim_completion_item', [function('lsp#omni#default_get_vim_completion_item')])
let g:lsp_get_supported_capabilities = get(g:, 'lsp_get_supported_capabilities', [function('lsp#default_get_supported_capabilities')])
Expand Down