浏览代码

More unicode conversions on the client

Strahinja Val Markovic 11 年之前
父节点
当前提交
e9b3916862
共有 2 个文件被更改,包括 9 次插入6 次删除
  1. 6 4
      python/ycm/utils.py
  2. 3 2
      python/ycm/vimsupport.py

+ 6 - 4
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():

+ 3 - 2
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' )