diff --git a/cpp/ycm/ClangCompleter.cpp b/cpp/ycm/ClangCompleter.cpp index bb6269a9..6f746f4f 100644 --- a/cpp/ycm/ClangCompleter.cpp +++ b/cpp/ycm/ClangCompleter.cpp @@ -39,6 +39,7 @@ using boost::bind; using boost::thread; using boost::lock_guard; using boost::mutex; +using boost::unordered_map; namespace YouCompleteMe { @@ -206,6 +207,8 @@ std::vector< CompletionData > ToCompletionDataVector( std::vector< CompletionData > completions; completions.reserve( results->NumResults ); + unordered_map< std::string, uint > seen_data; + for ( uint i = 0; i < results->NumResults; ++i ) { CXCompletionResult completion_result = results->Results[ i ]; @@ -213,8 +216,22 @@ std::vector< CompletionData > ToCompletionDataVector( if ( !CompletionStringAvailable( completion_result.CompletionString ) ) continue; - completions.push_back( - CompletionResultToCompletionData( completion_result ) ); + CompletionData data = CompletionResultToCompletionData( completion_result ); + uint index = GetValueElseInsert( seen_data, + data.original_string_, + completions.size() ); + + if ( index == completions.size() ) + { + completions.push_back( data ); + } + + else + { + completions[ index ].detailed_info_ + .append( "\n" ) + .append( data.extra_menu_info_ ); + } } return completions; diff --git a/cpp/ycm/Utils.h b/cpp/ycm/Utils.h index 2c135336..18f51b76 100644 --- a/cpp/ycm/Utils.h +++ b/cpp/ycm/Utils.h @@ -39,8 +39,8 @@ void WriteUtf8File( const fs::path &filepath, const std::string &contents ); template typename Container::mapped_type & GetValueElseInsert( Container &container, - Key const& key, - typename Container::mapped_type const& value ) + const Key &key, + const typename Container::mapped_type &value ) { return container.insert( typename Container::value_type( key, value ) ) .first->second; @@ -48,11 +48,22 @@ GetValueElseInsert( Container &container, template -bool ContainsKey( Container &container, Key const& key) +bool ContainsKey( Container &container, const Key &key ) { return container.find( key ) != container.end(); } + +template +const typename Container::mapped_type & +FindWithDefault( Container &container, + const Key &key, + const typename Container::mapped_type &value ) +{ + auto it = container.find( key ); + return it != container.end() ? *it : value; +} + } // namespace YouCompleteMe #endif /* end of include guard: UTILS_H_KEPMRPBH */