ncm2 / float-preview.nvim

Less annoying completion preview window based on neovim's floating window
MIT License
236 stars 3 forks source link

Truncated text in floating preview #8

Open jswny opened 5 years ago

jswny commented 5 years ago

I have the plugin installed, but the text is very truncated for some reason, and in addition, there is a ~ character at the bottom of the preview window for some reason. I'm using the plugin with Deoplete and LanguageClient-NeoVim.

Here is my config:

" Don't dock the preview window to the bottom of the window
let g:float_preview#docked = 0
Screen Shot 2019-10-31 at 2 29 28 PM
jswny commented 5 years ago

I've done some more digging and it looks like the completion source is adding those truncations. However, the question still remains about the ~ character at the end of the floating window. Any idea what I can do to fix that?

jalvesaq commented 4 years ago

I've written the following function while adapting Nvim-R's omnicompletion to avoid truncated text in the non docked float window created by float-preview.nvim:

function FormatTxt(text, splt, jn, maxl)
    let wlist = split(a:text, a:splt)
    let txt = ['']
    let ii = 0
    let maxlen = a:maxl - len(a:jn)
    for wrd in wlist
        if len(txt[ii] . a:splt . wrd) < maxlen
            let txt[ii] .= a:splt . wrd
        else
            let ii += 1
            let txt += [wrd]
        endif
    endfor
    let txt[0] = substitute(txt[0], '^' . a:splt, '', '')
    return join(txt, a:jn)
endfunction

The arguments received by FormatTxt are:

In the above example, the text in the float window would be more readable if modified by FormatTxt as:

FormatTxt(text, ', ', ",\n  ", g:float_preview#max_width)

The two spaces after the line break would indent the output.

Python documentation is complex to format because it mix function calls with normal text which require different split and join patterns. Perhaps float-preview.nvim could have an option to define the format function for each filetype (or none in the case of R), and apply a generic format function if no format function is defined to a filetype. The basic format function could at least strip the lines from leading and trailing spaces and add line breaks at the last blank space of lines before the window width is reached.