From 545792c055345abd1bbd263e631d811a4219c850 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 10 Jul 2012 23:13:12 -0700 Subject: [PATCH] Renaming Completer to IdentifierCompleter --- cpp/ycm/ClangComplete.h | 1 - ...{Completer.cpp => IdentifierCompleter.cpp} | 39 ++++++------ .../{Completer.h => IdentifierCompleter.h} | 10 ++-- cpp/ycm/indexer.cpp | 11 ++-- ..._test.cpp => IdentifierCompleter_test.cpp} | 60 +++++++++---------- python/ycm.py | 4 +- 6 files changed, 64 insertions(+), 61 deletions(-) rename cpp/ycm/{Completer.cpp => IdentifierCompleter.cpp} (83%) rename cpp/ycm/{Completer.h => IdentifierCompleter.h} (93%) rename cpp/ycm/tests/{Completer_test.cpp => IdentifierCompleter_test.cpp} (79%) diff --git a/cpp/ycm/ClangComplete.h b/cpp/ycm/ClangComplete.h index 4696837a..506f0869 100644 --- a/cpp/ycm/ClangComplete.h +++ b/cpp/ycm/ClangComplete.h @@ -58,7 +58,6 @@ class ClangComplete : boost::noncopyable { public: ClangComplete(); - ~ClangComplete(); void SetGlobalCompileFlags( const std::vector< std::string > &flags ); diff --git a/cpp/ycm/Completer.cpp b/cpp/ycm/IdentifierCompleter.cpp similarity index 83% rename from cpp/ycm/Completer.cpp rename to cpp/ycm/IdentifierCompleter.cpp index ca9ecf82..faf1ebb0 100644 --- a/cpp/ycm/Completer.cpp +++ b/cpp/ycm/IdentifierCompleter.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with YouCompleteMe. If not, see . -#include "Completer.h" +#include "IdentifierCompleter.h" #include "standard.h" #include "Utils.h" @@ -53,23 +53,25 @@ void ThreadMain( LatestTask &latest_task ) } // unnamed namespace -Completer::Completer( const std::vector< std::string > &candidates ) +IdentifierCompleter::IdentifierCompleter( + const std::vector< std::string > &candidates ) : threading_enabled_( false ) { AddCandidatesToDatabase( candidates, "", "", true ); } -Completer::Completer( const std::vector< std::string > &candidates, - const std::string &filetype, - const std::string &filepath ) +IdentifierCompleter::IdentifierCompleter( + const std::vector< std::string > &candidates, + const std::string &filetype, + const std::string &filepath ) : threading_enabled_( false ) { AddCandidatesToDatabase( candidates, filetype, filepath, true ); } -Completer::~Completer() +IdentifierCompleter::~IdentifierCompleter() { foreach ( const CandidateRepository::value_type &pair, candidate_repository_ ) @@ -81,14 +83,14 @@ Completer::~Completer() // We need this mostly so that we can not use it in tests. Apparently the // GoogleTest framework goes apeshit on us if we enable threads by default. -void Completer::EnableThreading() +void IdentifierCompleter::EnableThreading() { threading_enabled_ = true; InitThreads(); } -void Completer::AddCandidatesToDatabase( +void IdentifierCompleter::AddCandidatesToDatabase( const std::vector< std::string > &new_candidates, const std::string &filetype, const std::string &filepath, @@ -112,14 +114,14 @@ void Completer::AddCandidatesToDatabase( } -std::vector< std::string > Completer::CandidatesForQuery( +std::vector< std::string > IdentifierCompleter::CandidatesForQuery( const std::string &query ) const { return CandidatesForQueryAndType( query, "" ); } -std::vector< std::string > Completer::CandidatesForQueryAndType( +std::vector< std::string > IdentifierCompleter::CandidatesForQueryAndType( const std::string &query, const std::string &filetype ) const { @@ -135,7 +137,7 @@ std::vector< std::string > Completer::CandidatesForQueryAndType( } -Future Completer::CandidatesForQueryAndTypeAsync( +Future IdentifierCompleter::CandidatesForQueryAndTypeAsync( const std::string &query, const std::string &filetype ) const { @@ -146,7 +148,7 @@ Future Completer::CandidatesForQueryAndTypeAsync( // Try not to look at this too hard, it may burn your eyes. shared_ptr< packaged_task< AsyncResults > > task = make_shared< packaged_task< AsyncResults > >( - bind( &Completer::ResultsForQueryAndType, + bind( &IdentifierCompleter::ResultsForQueryAndType, boost::cref( *this ), query, filetype ) ); @@ -158,7 +160,7 @@ Future Completer::CandidatesForQueryAndTypeAsync( } -AsyncResults Completer::ResultsForQueryAndType( +AsyncResults IdentifierCompleter::ResultsForQueryAndType( const std::string &query, const std::string &filetype ) const { @@ -168,9 +170,10 @@ AsyncResults Completer::ResultsForQueryAndType( } -void Completer::ResultsForQueryAndType( const std::string &query, - const std::string &filetype, - std::vector< Result > &results ) const +void IdentifierCompleter::ResultsForQueryAndType( + const std::string &query, + const std::string &filetype, + std::vector< Result > &results ) const { FiletypeMap::const_iterator it = filetype_map_.find( filetype ); if ( it == filetype_map_.end() ) @@ -196,7 +199,7 @@ void Completer::ResultsForQueryAndType( const std::string &query, } -std::list< const Candidate* >& Completer::GetCandidateList( +std::list< const Candidate* >& IdentifierCompleter::GetCandidateList( const std::string &filetype, const std::string &filepath ) { @@ -216,7 +219,7 @@ std::list< const Candidate* >& Completer::GetCandidateList( } -void Completer::InitThreads() +void IdentifierCompleter::InitThreads() { int threads_to_create = std::max( MIN_ASYNC_THREADS, diff --git a/cpp/ycm/Completer.h b/cpp/ycm/IdentifierCompleter.h similarity index 93% rename from cpp/ycm/Completer.h rename to cpp/ycm/IdentifierCompleter.h index 63dc42ab..b9e4e7df 100644 --- a/cpp/ycm/Completer.h +++ b/cpp/ycm/IdentifierCompleter.h @@ -54,15 +54,15 @@ typedef ConcurrentLatestValue< boost::packaged_task< AsyncResults > > > LatestTask; -class Completer : boost::noncopyable +class IdentifierCompleter : boost::noncopyable { public: - Completer() {} - Completer( const std::vector< std::string > &candidates ); - Completer( const std::vector< std::string > &candidates, + IdentifierCompleter() {} + IdentifierCompleter( const std::vector< std::string > &candidates ); + IdentifierCompleter( const std::vector< std::string > &candidates, const std::string &filetype, const std::string &filepath ); - ~Completer(); + ~IdentifierCompleter(); void EnableThreading(); diff --git a/cpp/ycm/indexer.cpp b/cpp/ycm/indexer.cpp index 06be3b33..869a045f 100644 --- a/cpp/ycm/indexer.cpp +++ b/cpp/ycm/indexer.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with YouCompleteMe. If not, see . -#include "Completer.h" +#include "IdentifierCompleter.h" #include "ClangComplete.h" #include "Future.h" @@ -35,11 +35,12 @@ BOOST_PYTHON_MODULE(indexer) .def( "ResultsReady", &Future::ResultsReady ) .def( "GetResults", &Future::GetResults ); - class_< Completer, boost::noncopyable >( "Completer" ) - .def( "EnableThreading", &Completer::EnableThreading ) - .def( "AddCandidatesToDatabase", &Completer::AddCandidatesToDatabase ) + class_< IdentifierCompleter, boost::noncopyable >( "IdentifierCompleter" ) + .def( "EnableThreading", &IdentifierCompleter::EnableThreading ) + .def( "AddCandidatesToDatabase", + &IdentifierCompleter::AddCandidatesToDatabase ) .def( "CandidatesForQueryAndTypeAsync", - &Completer::CandidatesForQueryAndTypeAsync ); + &IdentifierCompleter::CandidatesForQueryAndTypeAsync ); // CAREFUL HERE! For filename and contents we are referring directly to // Python-allocated and -managed memory since we are accepting pointers to diff --git a/cpp/ycm/tests/Completer_test.cpp b/cpp/ycm/tests/IdentifierCompleter_test.cpp similarity index 79% rename from cpp/ycm/tests/Completer_test.cpp rename to cpp/ycm/tests/IdentifierCompleter_test.cpp index 73d0c080..efdfad89 100644 --- a/cpp/ycm/tests/Completer_test.cpp +++ b/cpp/ycm/tests/IdentifierCompleter_test.cpp @@ -17,7 +17,7 @@ #include #include -#include "Completer.h" +#include "IdentifierCompleter.h" #include "Utils.h" using ::testing::ElementsAre; @@ -64,16 +64,16 @@ std::vector< std::string > Candidates( const std::string &a, } // unnamed namespace -TEST( CompleterTest, OneCandidate ) +TEST( IdentifierCompleterTest, OneCandidate ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "foobar" ) ).CandidatesForQuery( "fbr" ), ElementsAre( "foobar" ) ); } -TEST( CompleterTest, ManyCandidateSimple ) +TEST( IdentifierCompleterTest, ManyCandidateSimple ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "foobar", "foobartest", "Foobartest" ) ).CandidatesForQuery( "fbr" ), @@ -82,131 +82,131 @@ TEST( CompleterTest, ManyCandidateSimple ) "foobartest" ) ) ); } -TEST( CompleterTest, FirstCharSameAsQueryWins ) +TEST( IdentifierCompleterTest, FirstCharSameAsQueryWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "foobar", "afoobar" ) ).CandidatesForQuery( "fbr" ), ElementsAre( "foobar", "afoobar" ) ); } -TEST( CompleterTest, CompleteMatchForWordBoundaryCharsWins ) +TEST( IdentifierCompleterTest, CompleteMatchForWordBoundaryCharsWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "FooBarQux", "FBaqux" ) ).CandidatesForQuery( "fbq" ), ElementsAre( "FooBarQux", "FBaqux" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "CompleterTest", "CompleteMatchForWordBoundaryCharsWins" ) ) .CandidatesForQuery( "ct" ), ElementsAre( "CompleterTest", "CompleteMatchForWordBoundaryCharsWins" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "FooBar", "FooBarRux" ) ).CandidatesForQuery( "fbr" ), ElementsAre( "FooBarRux", "FooBar" ) ); } -TEST( CompleterTest, RatioUtilizationTieBreak ) +TEST( IdentifierCompleterTest, RatioUtilizationTieBreak ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "aGaaFooBarQux", "aBaafbq" ) ).CandidatesForQuery( "fbq" ), ElementsAre( "aGaaFooBarQux", "aBaafbq" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "aFooBarQux", "afbq" ) ).CandidatesForQuery( "fbq" ), ElementsAre( "aFooBarQux", "afbq" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "acaaCaaFooGxx", "aCaafoog" ) ).CandidatesForQuery( "caafoo" ), ElementsAre( "acaaCaaFooGxx", "aCaafoog" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "acaaCaaFooGxx", "aCaafoog" ) ).CandidatesForQuery( "caaFoo" ), ElementsAre( "acaaCaaFooGxx", "aCaafoog" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "FooBarQux", "FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ), ElementsAre( "FooBarQux", "FooBarQuxZaa" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "FooBar", "FooBarRux" ) ).CandidatesForQuery( "fba" ), ElementsAre( "FooBar", "FooBarRux" ) ); } -TEST( CompleterTest, QueryPrefixOfCandidateWins ) +TEST( IdentifierCompleterTest, QueryPrefixOfCandidateWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "foobar", "fbaroo" ) ).CandidatesForQuery( "foo" ), ElementsAre( "foobar", "fbaroo" ) ); } -TEST( CompleterTest, LowerMatchCharIndexSumWins ) +TEST( IdentifierCompleterTest, LowerMatchCharIndexSumWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "ratio_of_word_boundary_chars_in_query_", "first_char_same_in_query_and_text_") ) .CandidatesForQuery( "charinq" ), ElementsAre( "first_char_same_in_query_and_text_", "ratio_of_word_boundary_chars_in_query_") ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "barfooq", "barquxfoo" ) ).CandidatesForQuery( "foo" ), ElementsAre( "barfooq", "barquxfoo") ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "xxxxxxabc", "xxabcxxxx" ) ).CandidatesForQuery( "abc" ), ElementsAre( "xxabcxxxx", "xxxxxxabc") ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "FooBarQux", "FaBarQux" ) ).CandidatesForQuery( "fbq" ), ElementsAre( "FaBarQux", "FooBarQux" ) ); } -TEST( CompleterTest, ShorterCandidateWins ) +TEST( IdentifierCompleterTest, ShorterCandidateWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "CompleterT", "CompleterTest" ) ).CandidatesForQuery( "co" ), ElementsAre( "CompleterT", "CompleterTest" ) ); - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "CompleterT", "CompleterTest" ) ).CandidatesForQuery( "plet" ), ElementsAre( "CompleterT", "CompleterTest" ) ); } -TEST( CompleterTest, SameLowercaseCandidateWins ) +TEST( IdentifierCompleterTest, SameLowercaseCandidateWins ) { - EXPECT_THAT( Completer( Candidates( + EXPECT_THAT( IdentifierCompleter( Candidates( "foobar", "Foobar" ) ).CandidatesForQuery( "foo" ), ElementsAre( "foobar", diff --git a/python/ycm.py b/python/ycm.py index a4c304ad..294ecacc 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -22,12 +22,12 @@ import vim import indexer min_num_chars = int( vim.eval( "g:ycm_min_num_of_chars_for_completion" ) ) - clang_filetypes = set( [ 'c', 'cpp', 'objc', 'objcpp' ] ) + class CompletionSystem( object ): def __init__( self ): - self.completer = indexer.Completer() + self.completer = indexer.IdentifierCompleter() self.completer.EnableThreading() self.pattern = re.compile( r"[_a-zA-Z]\w*" ) self.future = None