From b6a0d9de78dfdae0c0f90eb5885958807cbe01b2 Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 12:25:42 +0200 Subject: [PATCH 1/7] Allow setting max width of popup window in Vim --- autoload/lsp/ui/vim/output.vim | 14 ++++++++++---- plugin/lsp.vim | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim index 7b52f4c11..cd5e6e913 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_popup_max_width > 0 + let l:options['maxwidth'] = g:lsp_popup_max_width + endif + + let s:winid = popup_atcursor('...', l:options) endif return s:winid endfunction diff --git a/plugin/lsp.vim b/plugin/lsp.vim index f3c746ae2..e2b09e1de 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_popup_max_width = get(g:, 'lsp_popup_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')]) From 02a60e711ac24e754350db41ce7de4dab2259b0c Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 13:11:11 +0200 Subject: [PATCH 2/7] Allow setting max width of popup window in Neovim --- autoload/lsp/ui/vim/output.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim index cd5e6e913..d170e66e1 100644 --- a/autoload/lsp/ui/vim/output.vim +++ b/autoload/lsp/ui/vim/output.vim @@ -204,6 +204,19 @@ function! lsp#ui#vim#output#preview(data) abort let l:ft = s:append(a:data, l:lines) call s:setcontent(l:lines, l:ft) + " Set maximum width of floating window, if specified + if g:lsp_popup_max_width > 0 && s:supports_floating && s:winid && g:lsp_preview_float && has('nvim') + let &l:textwidth = g:lsp_popup_max_width + + let &l:readonly = 0 + let &l:modifiable = 1 + + normal! gggqGgg + + let &l:readonly = 1 + let &l:modifiable = 0 + endif + " Get size information while still having the buffer active let l:bufferlines = line('$') let l:maxwidth = max(map(getline(1, '$'), 'strdisplaywidth(v:val)')) From d03f49a77e106813173c11fd52d740fec07849ce Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 13:16:14 +0200 Subject: [PATCH 3/7] Add documentation --- doc/vim-lsp.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index 6a5a09e27..8fedf3e61 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_popup_max_width |g:lsp_popup_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_popup_max_width *g:lsp_popup_max_width* + Type: |Number| + Default: `-1` + + If positive, determines the maximum width of the popup window in + characters. Lines longer than `g:lsp_popup_max_width` will be wrapped to + fit in the popup 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* From a7bb093367851d8455b701590897a3e6c57e0236 Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 13:36:04 +0200 Subject: [PATCH 4/7] Uses spaces instead of tabs for indent in help --- doc/vim-lsp.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index 8fedf3e61..3c4b7c011 100644 --- a/doc/vim-lsp.txt +++ b/doc/vim-lsp.txt @@ -27,7 +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_popup_max_width |g:lsp_popup_max_width| + g:lsp_popup_max_width |g:lsp_popup_max_width| Functions |vim-lsp-functions| enable |vim-lsp-enable| disable |vim-lsp-disable| From 73e4aea1c2767c779d6899841316d00b7705717e Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 21:23:10 +0200 Subject: [PATCH 5/7] Move Neovim logic to s:setcontent --- autoload/lsp/ui/vim/output.vim | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim index d170e66e1..f5eda6481 100644 --- a/autoload/lsp/ui/vim/output.vim +++ b/autoload/lsp/ui/vim/output.vim @@ -145,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_popup_max_width > 0 + let &l:textwidth = g:lsp_popup_max_width + normal! gggqGgg + endif + setlocal readonly nomodifiable let &l:filetype = a:ft . '.lsp-hover' endif @@ -204,19 +211,6 @@ function! lsp#ui#vim#output#preview(data) abort let l:ft = s:append(a:data, l:lines) call s:setcontent(l:lines, l:ft) - " Set maximum width of floating window, if specified - if g:lsp_popup_max_width > 0 && s:supports_floating && s:winid && g:lsp_preview_float && has('nvim') - let &l:textwidth = g:lsp_popup_max_width - - let &l:readonly = 0 - let &l:modifiable = 1 - - normal! gggqGgg - - let &l:readonly = 1 - let &l:modifiable = 0 - endif - " Get size information while still having the buffer active let l:bufferlines = line('$') let l:maxwidth = max(map(getline(1, '$'), 'strdisplaywidth(v:val)')) From 338d1098041e5eff7683a245b227e71b0e9e5d34 Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 21:59:48 +0200 Subject: [PATCH 6/7] Rename setting to g:lsp_preview_max_width --- autoload/lsp/ui/vim/output.vim | 8 ++++---- doc/vim-lsp.txt | 6 +++--- plugin/lsp.vim | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim index f5eda6481..c6203426e 100644 --- a/autoload/lsp/ui/vim/output.vim +++ b/autoload/lsp/ui/vim/output.vim @@ -118,8 +118,8 @@ function! lsp#ui#vim#output#floatingpreview(data) abort \ 'border': [1, 1, 1, 1], \ } - if g:lsp_popup_max_width > 0 - let l:options['maxwidth'] = g:lsp_popup_max_width + if g:lsp_preview_max_width > 0 + let l:options['maxwidth'] = g:lsp_preview_max_width endif let s:winid = popup_atcursor('...', l:options) @@ -147,8 +147,8 @@ function! s:setcontent(lines, ft) abort call setline(1, a:lines) " Set maximum width of floating window, if specified - if g:lsp_popup_max_width > 0 - let &l:textwidth = g:lsp_popup_max_width + if g:lsp_preview_max_width > 0 + let &l:textwidth = g:lsp_preview_max_width normal! gggqGgg endif diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index 3c4b7c011..935c5c39e 100644 --- a/doc/vim-lsp.txt +++ b/doc/vim-lsp.txt @@ -27,7 +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_popup_max_width |g:lsp_popup_max_width| + g:lsp_preview_max_width |g:lsp_preview_max_width| Functions |vim-lsp-functions| enable |vim-lsp-enable| disable |vim-lsp-disable| @@ -383,12 +383,12 @@ g:lsp_get_supported_capabilities *g:lsp_get_supported_capabilities* calling `lsp#omni#default_get_supported_capabilities` from within your function. -g:lsp_popup_max_width *g:lsp_popup_max_width* +g:lsp_preview_max_width *g:lsp_preview_max_width* Type: |Number| Default: `-1` If positive, determines the maximum width of the popup window in - characters. Lines longer than `g:lsp_popup_max_width` will be wrapped to + characters. Lines longer than `g:lsp_preview_max_width` will be wrapped to fit in the popup window. Use a value of `-1` to disable setting a maximum width. diff --git a/plugin/lsp.vim b/plugin/lsp.vim index e2b09e1de..9344b0bf5 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -28,7 +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_popup_max_width = get(g:, 'lsp_popup_max_width', -1) +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')]) From 6b9a4ee844052b1485d93abd220c9579fb1f8b1f Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Wed, 26 Jun 2019 22:37:56 +0200 Subject: [PATCH 7/7] Replace 'popup' with 'preview' --- doc/vim-lsp.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index 935c5c39e..0a31f6e0c 100644 --- a/doc/vim-lsp.txt +++ b/doc/vim-lsp.txt @@ -387,10 +387,10 @@ g:lsp_preview_max_width *g:lsp_preview_max_width* Type: |Number| Default: `-1` - If positive, determines the maximum width of the popup window in + 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 popup window. Use a value of `-1` to disable setting a maximum - width. + fit in the preview window. Use a value of `-1` to disable setting a + maximum width. =============================================================================== FUNCTIONS *vim-lsp-functions*