More unicode conversions on the client

This commit is contained in:
Strahinja Val Markovic 2014-01-13 10:00:05 -08:00
parent b3a77e9464
commit e9b3916862
2 changed files with 9 additions and 6 deletions

View File

@ -39,10 +39,12 @@ def SanitizeQuery( query ):
return query.strip() return query.strip()
def ToUtf8IfNeeded( string_or_unicode ): def ToUtf8IfNeeded( value ):
if isinstance( string_or_unicode, unicode ): if isinstance( value, unicode ):
return string_or_unicode.encode( 'utf8' ) return value.encode( 'utf8' )
return string_or_unicode if isinstance( value, str ):
return value
return str( value )
def PathToTempDir(): def PathToTempDir():

View File

@ -20,6 +20,7 @@
import vim import vim
import os import os
import json import json
from ycm.utils import ToUtf8IfNeeded
def CurrentLineAndColumn(): def CurrentLineAndColumn():
"""Returns the 0-based current line and 0-based current column.""" """Returns the 0-based current line and 0-based current column."""
@ -190,7 +191,7 @@ def ConvertDiagnosticsToQfList( diagnostics ):
'bufnr' : GetBufferNumberForFilename( location[ 'filepath' ] ), 'bufnr' : GetBufferNumberForFilename( location[ 'filepath' ] ),
'lnum' : location[ 'line_num' ] + 1, 'lnum' : location[ 'line_num' ] + 1,
'col' : location[ 'column_num' ] + 1, 'col' : location[ 'column_num' ] + 1,
'text' : diagnostic[ 'text' ], 'text' : ToUtf8IfNeeded( diagnostic[ 'text' ] ),
'type' : diagnostic[ 'kind' ], 'type' : diagnostic[ 'kind' ],
'valid' : 1 '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 # Echos text but truncates it so that it all fits on one line
def EchoTextVimWidth( text ): def EchoTextVimWidth( text ):
vim_width = GetIntValue( '&columns' ) 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', ' ' ) truncated_text.replace( '\n', ' ' )
old_ruler = GetIntValue( '&ruler' ) old_ruler = GetIntValue( '&ruler' )