Using the vector indexing suite from Boost.Python
This removes the need for a special overload for AddCandidatesToDatabase. Also, the GetFuture function now provides a more sensible API with the list being returned instead of accepted as an out parameter.
This commit is contained in:
parent
9a82319c77
commit
30c9637992
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
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 > >() );
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include "Completer.h"
|
||||
#include "Utils.h"
|
||||
#include <boost/python.hpp>
|
||||
|
||||
using ::testing::ElementsAre;
|
||||
using ::testing::WhenSorted;
|
||||
|
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user