Skip to content

Conversation

thomasfaingnaert
Copy link
Collaborator

In response to #416 (comment).

I decided to try a different approach. Rather than hard wrapping the text using gq and 'textwidth', I softwrap by setting the maxwidth.
The only problem with this, is that we need to explicitly calculate the height of the floating window (as far as I can tell, anyway; if someone know a way where we can avoid this, let me know).

To accomplish this, I iterate over all lines and sum ceil(line_width / max_width) (i.e. the number of "virtual" lines needed to show this line).

@clason
Copy link
Contributor

clason commented Jul 23, 2019

Yes, this works nicely, thank you! (Arguably, adjusting the height of the floating window would be the right thing to do even if max_width isn't set.)

@clason
Copy link
Contributor

clason commented Jul 23, 2019

One nitpick: max_width seems also to be taken as min_width, i.e., shorter hover texts are padded to max_width.

Something like

    let l:maxwidth = max(map(getline(1, '$'), 'strdisplaywidth(v:val)'))  
    if g:lsp_preview_max_width > 0
      let l:bufferlines = 0
      let l:maxwidth = min([g:lsp_preview_max_width,l:maxwidth])

      " Determine, for each line, how many "virtual" lines it spans, and add
      " these together for all lines in the buffer
      for l:line in getline(1, '$')
        let l:num_lines = str2nr(string(ceil(strdisplaywidth(l:line) * 1.0 / g:lsp_preview_max_width)))
        let l:bufferlines += max([l:num_lines, 1])
      endfor
    else
      let l:bufferlines = line('$')
    endif

should do the trick.

@thomasfaingnaert
Copy link
Collaborator Author

@clason
Fixed, thanks.

@thomasfaingnaert
Copy link
Collaborator Author

@clason Can I merge this in or does it still not work perfectly?

@clason
Copy link
Contributor

clason commented Jul 24, 2019

Yes, please! (Adjusting the height without max_width is a separate issue; this is a working fix for the issue I raised in my comment.)

@thomasfaingnaert thomasfaingnaert merged commit 79d47fe into prabirshrestha:master Jul 24, 2019
@thomasfaingnaert thomasfaingnaert deleted the fix-max-width branch July 24, 2019 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants