Skip to content

Commit 9175167

Browse files
thomasfaingnaertprabirshrestha
authored andcommitted
Allow setting popup max width (#416)
* Allow setting max width of popup window in Vim * Allow setting max width of popup window in Neovim * Add documentation * Uses spaces instead of tabs for indent in help * Move Neovim logic to s:setcontent * Rename setting to g:lsp_preview_max_width * Replace 'popup' with 'preview'
1 parent 4006768 commit 9175167

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

autoload/lsp/ui/vim/output.vim

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
113113
" Enable closing the preview with esc, but map only in the scratch buffer
114114
nmap <buffer><silent> <esc> :pclose<cr>
115115
else
116-
let s:winid = popup_atcursor('...', {
117-
\ 'moved': 'any',
118-
\ 'border': [1, 1, 1, 1],
119-
\})
116+
let l:options = {
117+
\ 'moved': 'any',
118+
\ 'border': [1, 1, 1, 1],
119+
\ }
120+
121+
if g:lsp_preview_max_width > 0
122+
let l:options['maxwidth'] = g:lsp_preview_max_width
123+
endif
124+
125+
let s:winid = popup_atcursor('...', l:options)
120126
endif
121127
return s:winid
122128
endfunction
@@ -139,6 +145,13 @@ function! s:setcontent(lines, ft) abort
139145
else
140146
" nvim floating
141147
call setline(1, a:lines)
148+
149+
" Set maximum width of floating window, if specified
150+
if g:lsp_preview_max_width > 0
151+
let &l:textwidth = g:lsp_preview_max_width
152+
normal! gggqGgg
153+
endif
154+
142155
setlocal readonly nomodifiable
143156
let &l:filetype = a:ft . '.lsp-hover'
144157
endif

doc/vim-lsp.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CONTENTS *vim-lsp-contents*
2727
g:lsp_highlight_references_enabled |g:lsp_highlight_references_enabled|
2828
g:lsp_get_vim_completion_item |g:lsp_get_vim_completion_item|
2929
g:lsp_get_supported_capabilities |g:lsp_get_supported_capabilities|
30+
g:lsp_preview_max_width |g:lsp_preview_max_width|
3031
Functions |vim-lsp-functions|
3132
enable |vim-lsp-enable|
3233
disable |vim-lsp-disable|
@@ -408,6 +409,15 @@ g:lsp_get_supported_capabilities *g:lsp_get_supported_capabilities*
408409
calling `lsp#omni#default_get_supported_capabilities` from within your
409410
function.
410411

412+
g:lsp_preview_max_width *g:lsp_preview_max_width*
413+
Type: |Number|
414+
Default: `-1`
415+
416+
If positive, determines the maximum width of the preview window in
417+
characters. Lines longer than `g:lsp_preview_max_width` will be wrapped to
418+
fit in the preview window. Use a value of `-1` to disable setting a
419+
maximum width.
420+
411421
===============================================================================
412422
FUNCTIONS *vim-lsp-functions*
413423

plugin/lsp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ let g:lsp_highlight_references_enabled = get(g:, 'lsp_highlight_references_enabl
2828
let g:lsp_preview_float = get(g:, 'lsp_preview_float', 1)
2929
let g:lsp_preview_autoclose = get(g:, 'lsp_preview_autoclose', 1)
3030
let g:lsp_preview_doubletap = get(g:, 'lsp_preview_doubletap', [function('lsp#ui#vim#output#focuspreview')])
31+
let g:lsp_preview_max_width = get(g:, 'lsp_preview_max_width', -1)
3132

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

0 commit comments

Comments
 (0)