diff --git a/cpp/ycm/Completer.cpp b/cpp/ycm/Completer.cpp index e5727396..ca9ecf82 100644 --- a/cpp/ycm/Completer.cpp +++ b/cpp/ycm/Completer.cpp @@ -88,24 +88,6 @@ void Completer::EnableThreading() } -void Completer::AddCandidatesToDatabase( const Pylist &new_candidates, - const std::string &filetype, - const std::string &filepath, - bool clear_database ) -{ - int num_candidates = len( new_candidates ); - std::vector< std::string > candidates; - candidates.reserve( num_candidates ); - - for (int i = 0; i < num_candidates; ++i) - { - candidates.push_back( extract< std::string >( new_candidates[ i ] ) ); - } - - AddCandidatesToDatabase( candidates, filetype, filepath, clear_database ); -} - - void Completer::AddCandidatesToDatabase( const std::vector< std::string > &new_candidates, const std::string &filetype, diff --git a/cpp/ycm/Completer.h b/cpp/ycm/Completer.h index 349af31f..63dc42ab 100644 --- a/cpp/ycm/Completer.h +++ b/cpp/ycm/Completer.h @@ -72,11 +72,6 @@ public: const std::string &filepath, bool clear_database ); - void AddCandidatesToDatabase( const Pylist &new_candidates, - const std::string &filetype, - const std::string &filepath, - bool clear_database ); - // Only provided for tests! std::vector< std::string > CandidatesForQuery( const std::string &query ) const; diff --git a/cpp/ycm/Future.cpp b/cpp/ycm/Future.cpp index ea6e989e..6b8cbeb9 100644 --- a/cpp/ycm/Future.cpp +++ b/cpp/ycm/Future.cpp @@ -32,8 +32,9 @@ bool Future::ResultsReady() return future_.is_ready(); } -void Future::GetResults( Pylist &candidates ) +Pylist Future::GetResults() { + Pylist candidates; AsyncResults results; try @@ -43,13 +44,15 @@ void Future::GetResults( Pylist &candidates ) catch ( boost::future_uninitialized & ) { - return; + return candidates; } foreach ( const Result& result, *results ) { candidates.append( *result.Text() ); } + + return candidates; } } // namespace YouCompleteMe diff --git a/cpp/ycm/Future.h b/cpp/ycm/Future.h index cecfa1c4..26679c7b 100644 --- a/cpp/ycm/Future.h +++ b/cpp/ycm/Future.h @@ -36,7 +36,7 @@ public: Future() {} Future( boost::shared_future< AsyncResults > future ); bool ResultsReady(); - void GetResults( Pylist &candidates ); + Pylist GetResults(); private: boost::shared_future< AsyncResults > future_; diff --git a/cpp/ycm/indexer.cpp b/cpp/ycm/indexer.cpp index e4711c08..d045173c 100644 --- a/cpp/ycm/indexer.cpp +++ b/cpp/ycm/indexer.cpp @@ -20,6 +20,7 @@ #include #include +#include BOOST_PYTHON_MODULE(indexer) { @@ -30,15 +31,13 @@ BOOST_PYTHON_MODULE(indexer) .def( "ResultsReady", &Future::ResultsReady ) .def( "GetResults", &Future::GetResults ); - void (Completer::*actd) (const Pylist&, - const std::string&, - const std::string&, - bool) = - &Completer::AddCandidatesToDatabase; - class_< Completer, boost::noncopyable >( "Completer" ) .def( "EnableThreading", &Completer::EnableThreading ) - .def( "AddCandidatesToDatabase", actd ) + // .def( "AddCandidatesToDatabase", actd ) + .def( "AddCandidatesToDatabase", &Completer::AddCandidatesToDatabase ) .def( "CandidatesForQueryAndTypeAsync", &Completer::CandidatesForQueryAndTypeAsync ); + + class_< std::vector< std::string > >( "StringVec" ) + .def( vector_indexing_suite< std::vector< std::string > >() ); } diff --git a/cpp/ycm/tests/Completer_test.cpp b/cpp/ycm/tests/Completer_test.cpp index 3938dc22..73d0c080 100644 --- a/cpp/ycm/tests/Completer_test.cpp +++ b/cpp/ycm/tests/Completer_test.cpp @@ -19,7 +19,6 @@ #include #include "Completer.h" #include "Utils.h" -#include using ::testing::ElementsAre; using ::testing::WhenSorted; diff --git a/python/ycm.py b/python/ycm.py index 1ac4902d..364dc12c 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -47,20 +47,19 @@ class CompletionSystem( object ): if not self.future: return [] - results = [] - self.future.GetResults( results ) - return results + return self.future.GetResults() def AddIdentifier( self, identifier ): - # print identifier filetype = vim.eval( "&filetype" ) filepath = vim.eval( "expand('%:p')" ) if not filetype or not filepath or not identifier: return - self.completer.AddCandidatesToDatabase( [ identifier ], + vector = indexer.StringVec() + vector.append( identifier ) + self.completer.AddCandidatesToDatabase( vector, filetype, filepath, False ) @@ -81,7 +80,9 @@ class CompletionSystem( object ): if not filetype or not filepath: return - self.completer.AddCandidatesToDatabase( idents, + vector = indexer.StringVec() + vector.extend( idents ) + self.completer.AddCandidatesToDatabase( vector, filetype, filepath, True )