diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim index 7b52f4c11..c6203426e 100644 --- a/autoload/lsp/ui/vim/output.vim +++ b/autoload/lsp/ui/vim/output.vim @@ -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 :pclose 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 @@ -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 diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index 6a5a09e27..0a31f6e0c 100644 --- a/doc/vim-lsp.txt +++ b/doc/vim-lsp.txt @@ -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| @@ -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* @@ -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* diff --git a/plugin/lsp.vim b/plugin/lsp.vim index f3c746ae2..9344b0bf5 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -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')])