Skip to content

Commit

Permalink
WIP: Truncate the extra_menu_info if using preview popup
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Apr 10, 2020
1 parent 97150c0 commit 5928760
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 3 additions & 1 deletion autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ function! s:SetUpCompleteopt()
" Also, having this option set breaks the plugin.
set completeopt-=longest

if g:ycm_add_preview_to_completeopt
if g:ycm_add_preview_to_completeopt ==# 'popup' && exists( '*popup_open' )
set completeopt+=popup
elseif g:ycm_add_preview_to_completeopt
set completeopt+=preview
endif
endfunction
Expand Down
18 changes: 16 additions & 2 deletions python/ycm/client/completion_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,25 @@ def _GetCompletionInfoField( completion_data ):

def _ConvertCompletionDataToVimData( completion_data ):
# See :h complete-items for a description of the dictionary fields.
extra_menu_info = completion_data.get( 'extra_menu_info', '' )
preview_info = _GetCompletionInfoField( completion_data )

# When we are using a popup for the preview_info, it needs to fit on the
# screen alongside the extra_menu_info. Let's use some heuristics. If the
# length of the extra_menu_info is more than, say 50% of screen, truncate it
# and stick it in the preview_info.
if vimsupport.UsingPreviewPopup():
max_width = max( int( vimsupport.DisplayWidth() / 3 ), 3 )
extra_menu_info_width = vimsupport.DisplayWidthOfString( extra_menu_info )
if extra_menu_info_width > max_width:
preview_info = extra_menu_info + '\n\n' + preview_info
extra_menu_info = extra_menu_info[ : ( max_width - 3 ) ] + '...'

return {
'word' : completion_data[ 'insertion_text' ],
'abbr' : completion_data.get( 'menu_text', '' ),
'menu' : completion_data.get( 'extra_menu_info', '' ),
'info' : _GetCompletionInfoField( completion_data ),
'menu' : extra_menu_info,
'info' : preview_info,
'kind' : ToUnicode( completion_data.get( 'kind', '' ) )[ :1 ].lower(),
# Disable Vim filtering.
'equal' : 1,
Expand Down
12 changes: 12 additions & 0 deletions python/ycm/vimsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,15 @@ def ScreenPositionForLineColumnInWindow( window, line, column ):
WinIDForWindow( window ),
line,
column ) )


def UsingPreviewPopup():
return 'popup' in ToUnicode( vim.options[ 'completeopt' ] ).split( ',' )


def DisplayWidth():
return GetIntValue( '&columns' )


def DisplayWidthOfString( s ):
return GetIntValue( "strdisplaywidth( '{}' )".format( EscapeForVim( s ) ) )

0 comments on commit 5928760

Please sign in to comment.