diff --git a/cpp/ycm/PythonSupport.cpp b/cpp/ycm/PythonSupport.cpp index 635ae5ed..7b94a7a3 100644 --- a/cpp/ycm/PythonSupport.cpp +++ b/cpp/ycm/PythonSupport.cpp @@ -27,6 +27,7 @@ using boost::algorithm::any_of; using boost::algorithm::is_upper; using boost::python::len; +using boost::python::str; using boost::python::extract; using boost::python::object; typedef boost::python::list pylist; @@ -35,6 +36,13 @@ namespace YouCompleteMe { namespace { +std::string GetUtf8String( const boost::python::object &string_or_unicode ) { + extract< std::string > to_string( string_or_unicode ); + if ( to_string.check() ) + return to_string(); + return extract< std::string >( str( string_or_unicode ).encode( "utf8" ) ); +} + std::vector< const Candidate * > CandidatesFromObjectList( const pylist &candidates, const std::string &candidate_property ) { @@ -44,10 +52,10 @@ std::vector< const Candidate * > CandidatesFromObjectList( for ( int i = 0; i < num_candidates; ++i ) { if ( candidate_property.empty() ) { - candidate_strings.push_back( extract< std::string >( candidates[ i ] ) ); + candidate_strings.push_back( GetUtf8String( candidates[ i ] ) ); } else { object holder = extract< object >( candidates[ i ] ); - candidate_strings.push_back( extract< std::string >( + candidate_strings.push_back( GetUtf8String( holder[ candidate_property.c_str() ] ) ); } } diff --git a/python/ycm/completers/completer.py b/python/ycm/completers/completer.py index 6e2f1486..ec5732e5 100644 --- a/python/ycm/completers/completer.py +++ b/python/ycm/completers/completer.py @@ -178,7 +178,7 @@ class Completer( object ): self.completions_cache.filtered_completions = ( self.FilterAndSortCandidates( self.completions_cache.raw_completions, - ToUtf8IfNeeded( request_data[ 'query' ] ) ) ) + request_data[ 'query' ] ) ) else: self.completions_cache = None self.CandidatesForQueryAsyncInner( request_data ) @@ -216,7 +216,7 @@ class Completer( object ): matches = ycm_core.FilterAndSortCandidates( candidates, sort_property, - query ) + ToUtf8IfNeeded( query ) ) return matches