From e9b391686286489765ebc606afb591fe14e7b7e7 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 13 Jan 2014 10:00:05 -0800 Subject: [PATCH] More unicode conversions on the client --- python/ycm/utils.py | 10 ++++++---- python/ycm/vimsupport.py | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/python/ycm/utils.py b/python/ycm/utils.py index a36493b0..7bd0660f 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -39,10 +39,12 @@ def SanitizeQuery( query ): return query.strip() -def ToUtf8IfNeeded( string_or_unicode ): - if isinstance( string_or_unicode, unicode ): - return string_or_unicode.encode( 'utf8' ) - return string_or_unicode +def ToUtf8IfNeeded( value ): + if isinstance( value, unicode ): + return value.encode( 'utf8' ) + if isinstance( value, str ): + return value + return str( value ) def PathToTempDir(): diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 5aad020b..1d25f2e3 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -20,6 +20,7 @@ import vim import os import json +from ycm.utils import ToUtf8IfNeeded def CurrentLineAndColumn(): """Returns the 0-based current line and 0-based current column.""" @@ -190,7 +191,7 @@ def ConvertDiagnosticsToQfList( diagnostics ): 'bufnr' : GetBufferNumberForFilename( location[ 'filepath' ] ), 'lnum' : location[ 'line_num' ] + 1, 'col' : location[ 'column_num' ] + 1, - 'text' : diagnostic[ 'text' ], + 'text' : ToUtf8IfNeeded( diagnostic[ 'text' ] ), 'type' : diagnostic[ 'kind' ], 'valid' : 1 } @@ -311,7 +312,7 @@ def EchoText( text, log_as_message = True ): # Echos text but truncates it so that it all fits on one line def EchoTextVimWidth( text ): vim_width = GetIntValue( '&columns' ) - truncated_text = text.encode('utf-8')[ : int( vim_width * 0.9 ) ] + truncated_text = ToUtf8IfNeeded( text )[ : int( vim_width * 0.9 ) ] truncated_text.replace( '\n', ' ' ) old_ruler = GetIntValue( '&ruler' )