Format Hover Pop-up Window (#1257)

* Format Hover Pop-up Window

1) Applies Vim's gq command to each individual line of content returned by
   language server.

2) Fixes scrolling to last line of popup window

* minor

* Add help entry for popup formatting
This commit is contained in:
Eric Larson
2022-01-05 17:25:48 -08:00
committed by GitHub
parent 40b155512b
commit 453042d7e4
3 changed files with 19 additions and 2 deletions
@@ -89,7 +89,7 @@ function! s:show_hover(ui, server_name, request, response) abort
call s:show_floating_window(a:server_name, a:request, a:response)
else
call s:show_preview_window(a:server_name, a:request, a:response)
endif
endif
endfunction
function! s:show_preview_window(server_name, request, response) abort
@@ -161,6 +161,14 @@ function! s:show_floating_window(server_name, request, response) abort
\ 'border': v:true,
\ })
call s:Window.do(l:doc_win.get_winid(), { -> s:Markdown.apply() })
" Format contents to fit window
call setbufvar(l:doc_win.get_bufnr(), '&textwidth', l:size.width)
call s:Window.do(l:doc_win.get_winid(), { -> s:format_window() })
endfunction
function! s:format_window() abort
global/^/normal! gqgq
endfunction
function! s:get_contents(contents) abort
+1 -1
View File
@@ -106,7 +106,7 @@ function! s:scroll(winid, topline) abort
function! l:ctx.callback(winid, topline) abort
let l:wininfo = s:info(a:winid)
let l:topline = a:topline
let l:topline = min([l:topline, line('$') - l:wininfo.height + 1])
let l:topline = min([l:topline, line('$') - l:wininfo.height + 3])
let l:topline = max([l:topline, 1])
if l:topline == l:wininfo.topline
+9
View File
@@ -155,6 +155,7 @@ CONTENTS *vim-lsp-contents*
Snippets |vim-lsp-snippets|
Folding |vim-lsp-folding|
Semantic highlighting |vim-lsp-semantic|
Popup Formatting |vim-lsp-popup-format|
License |vim-lsp-license|
Maintainers |vim-lsp-maintainers|
@@ -1998,6 +1999,14 @@ want function calls to still use the |Label| group, but use |Identifier| for
\ }
\ })
<
==============================================================================
Popup Formatting *vim-lsp-popup-format*
Popup windows use the |gq| operator for formatting content to the window.
For customization, see
|formatprg|.
==============================================================================
License *vim-lsp-license*