diff --git a/python/ycm/completers/completer.py b/python/ycm/completers/completer.py index 60dcd6ec..6e2f1486 100644 --- a/python/ycm/completers/completer.py +++ b/python/ycm/completers/completer.py @@ -19,6 +19,7 @@ import abc import ycm_core +from ycm.utils import ToUtf8IfNeeded from ycm.completers.completer_utils import TriggersForFiletype NO_USER_COMMANDS = 'This completer does not define any commands.' @@ -177,7 +178,7 @@ class Completer( object ): self.completions_cache.filtered_completions = ( self.FilterAndSortCandidates( self.completions_cache.raw_completions, - request_data[ 'query' ] ) ) + ToUtf8IfNeeded( request_data[ 'query' ] ) ) ) else: self.completions_cache = None self.CandidatesForQueryAsyncInner( request_data ) diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index fc976ab1..73e90eef 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -22,6 +22,7 @@ import ycm_core import logging from ycm import server_responses from ycm import extra_conf_store +from ycm.utils import ToUtf8IfNeeded from ycm.completers.completer import Completer from ycm.completers.cpp.flags import Flags @@ -109,8 +110,8 @@ class ClangCompleter( Completer ): column = request_data[ 'start_column' ] + 1 self.completions_future = ( self.completer.CandidatesForQueryAndLocationInFileAsync( - query, - filename, + ToUtf8IfNeeded( query ), + ToUtf8IfNeeded( filename ), line, column, files, @@ -369,3 +370,5 @@ def ClangAvailableForFiletypes( filetypes ): def InCFamilyFile( filetypes ): return ClangAvailableForFiletypes( filetypes ) + + diff --git a/python/ycm/utils.py b/python/ycm/utils.py index d1fe5035..81e4bd77 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -24,3 +24,8 @@ def IsIdentifierChar( char ): 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