Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 23 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_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
Expand Down Expand Up @@ -198,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just give the maxwidth in line 233 call s:adjust_float_placement(l:bufferlines, l:maxwidth) and enable soft wrap?
Imo turning it modifiable, format and unmodifiable again feels kind of hackish.

If the current solution has any benefit, it should be done in s:setcontent, as it effects the content itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerdna-regeiz
If you mean something like this:

diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim
index 7b52f4c..718b01d 100644
--- a/autoload/lsp/ui/vim/output.vim
+++ b/autoload/lsp/ui/vim/output.vim
@@ -211,7 +211,7 @@ function! lsp#ui#vim#output#preview(data) abort
 
     if s:supports_floating && s:winid && g:lsp_preview_float
       if has('nvim')
-        call s:adjust_float_placement(l:bufferlines, l:maxwidth)
+        call s:adjust_float_placement(l:bufferlines, 10)
         call s:add_float_closing_hooks()
       endif
       doautocmd User lsp_float_opened

then that doesn't work: it only displays the first line of the popup. Moving it to s:setcontent would indeed be better.

Copy link
Contributor

@jerdna-regeiz jerdna-regeiz Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, then it depends on the source or some other settings, as it wraps each row nicely for me.
But in setcontent it looks great and a lot less hacky =)

Actually this does now apply to normal preview as well (which is nice in my opinion!). Maybe we should just call the option g:lsp_preview_max_width as it now applies to every flavor of it.


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)'))
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_popup_max_width |g:lsp_popup_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_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*

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_popup_max_width = get(g:, 'lsp_popup_max_width', -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either call both float or popup (meaning g:lsp_preview_float and g:lsp_popup_max_width).


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