Formatting the a part of the source with astyle
This commit is contained in:
parent
00db8fd8b1
commit
013a56c25c
@ -48,23 +48,19 @@ using boost::unique_future;
|
||||
using boost::unique_lock;
|
||||
using boost::unordered_map;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
extern const unsigned int MAX_ASYNC_THREADS;
|
||||
extern const unsigned int MIN_ASYNC_THREADS;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
struct CompletionDataAndResult
|
||||
{
|
||||
struct CompletionDataAndResult {
|
||||
CompletionDataAndResult( const CompletionData *completion_data,
|
||||
const Result &result )
|
||||
: completion_data_( completion_data ), result_( result ) {}
|
||||
|
||||
bool operator< ( const CompletionDataAndResult &other ) const
|
||||
{
|
||||
bool operator< ( const CompletionDataAndResult &other ) const {
|
||||
return result_ < other.result_;
|
||||
}
|
||||
|
||||
@ -80,14 +76,12 @@ ClangCompleter::ClangCompleter()
|
||||
: candidate_repository_( CandidateRepository::Instance() ),
|
||||
threading_enabled_( false ),
|
||||
time_to_die_( false ),
|
||||
clang_data_ready_( false )
|
||||
{
|
||||
clang_data_ready_( false ) {
|
||||
clang_index_ = clang_createIndex( 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
ClangCompleter::~ClangCompleter()
|
||||
{
|
||||
ClangCompleter::~ClangCompleter() {
|
||||
// We need to clear this before calling clang_disposeIndex because the
|
||||
// translation units need to be destroyed before the index is destroyed.
|
||||
filename_to_translation_unit_.clear();
|
||||
@ -109,16 +103,14 @@ ClangCompleter::~ClangCompleter()
|
||||
// We need this mostly so that we can not use it in tests. Apparently the
|
||||
// GoogleTest framework goes apeshit on us (on some platforms, in some
|
||||
// occasions) if we enable threads by default.
|
||||
void ClangCompleter::EnableThreading()
|
||||
{
|
||||
void ClangCompleter::EnableThreading() {
|
||||
threading_enabled_ = true;
|
||||
InitThreads();
|
||||
}
|
||||
|
||||
|
||||
std::vector< Diagnostic > ClangCompleter::DiagnosticsForFile(
|
||||
const std::string &filename )
|
||||
{
|
||||
const std::string &filename ) {
|
||||
shared_ptr< TranslationUnit > unit;
|
||||
{
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
@ -135,8 +127,7 @@ std::vector< Diagnostic > ClangCompleter::DiagnosticsForFile(
|
||||
}
|
||||
|
||||
|
||||
bool ClangCompleter::UpdatingTranslationUnit( const std::string &filename )
|
||||
{
|
||||
bool ClangCompleter::UpdatingTranslationUnit( const std::string &filename ) {
|
||||
shared_ptr< TranslationUnit > unit;
|
||||
{
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
@ -156,8 +147,7 @@ bool ClangCompleter::UpdatingTranslationUnit( const std::string &filename )
|
||||
void ClangCompleter::UpdateTranslationUnit(
|
||||
const std::string &filename,
|
||||
const std::vector< UnsavedFile > &unsaved_files,
|
||||
const std::vector< std::string > &flags )
|
||||
{
|
||||
const std::vector< std::string > &flags ) {
|
||||
bool translation_unit_created;
|
||||
shared_ptr< TranslationUnit > unit = GetTranslationUnitForFile(
|
||||
filename,
|
||||
@ -168,16 +158,14 @@ void ClangCompleter::UpdateTranslationUnit(
|
||||
if ( !unit )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// There's no point in reparsing a TU that was just created, it was just
|
||||
// parsed in the TU constructor
|
||||
if ( !translation_unit_created )
|
||||
unit->Reparse( unsaved_files );
|
||||
}
|
||||
|
||||
catch ( ClangParseError& )
|
||||
{
|
||||
catch ( ClangParseError & ) {
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
|
||||
// If unit->Reparse fails, then the underlying TranslationUnit object is not
|
||||
@ -191,8 +179,7 @@ void ClangCompleter::UpdateTranslationUnit(
|
||||
Future< void > ClangCompleter::UpdateTranslationUnitAsync(
|
||||
std::string filename,
|
||||
std::vector< UnsavedFile > unsaved_files,
|
||||
std::vector< std::string > flags )
|
||||
{
|
||||
std::vector< std::string > flags ) {
|
||||
function< void() > functor =
|
||||
bind( &ClangCompleter::UpdateTranslationUnit,
|
||||
boost::ref( *this ),
|
||||
@ -218,11 +205,11 @@ ClangCompleter::CandidatesForLocationInFile(
|
||||
int line,
|
||||
int column,
|
||||
const std::vector< UnsavedFile > &unsaved_files,
|
||||
const std::vector< std::string > &flags )
|
||||
{
|
||||
const std::vector< std::string > &flags ) {
|
||||
shared_ptr< TranslationUnit > unit = GetTranslationUnitForFile( filename,
|
||||
unsaved_files,
|
||||
flags );
|
||||
|
||||
if ( !unit )
|
||||
return std::vector< CompletionData >();
|
||||
|
||||
@ -239,8 +226,7 @@ ClangCompleter::CandidatesForQueryAndLocationInFileAsync(
|
||||
int line,
|
||||
int column,
|
||||
const std::vector< UnsavedFile > &unsaved_files,
|
||||
const std::vector< std::string > &flags )
|
||||
{
|
||||
const std::vector< std::string > &flags ) {
|
||||
// TODO: throw exception when threading is not enabled and this is called
|
||||
if ( !threading_enabled_ )
|
||||
return Future< AsyncCompletions >();
|
||||
@ -248,8 +234,8 @@ ClangCompleter::CandidatesForQueryAndLocationInFileAsync(
|
||||
bool skip_clang_result_cache = ShouldSkipClangResultCache( query,
|
||||
line,
|
||||
column );
|
||||
if ( skip_clang_result_cache )
|
||||
{
|
||||
|
||||
if ( skip_clang_result_cache ) {
|
||||
// The clang thread is busy, return nothing
|
||||
if ( UpdatingTranslationUnit( filename ) )
|
||||
return Future< AsyncCompletions >();
|
||||
@ -271,8 +257,7 @@ ClangCompleter::CandidatesForQueryAndLocationInFileAsync(
|
||||
unique_future< AsyncCompletions > future;
|
||||
CreateSortingTask( query, future );
|
||||
|
||||
if ( skip_clang_result_cache )
|
||||
{
|
||||
if ( skip_clang_result_cache ) {
|
||||
CreateClangTask( filename, line, column, unsaved_files, flags );
|
||||
}
|
||||
|
||||
@ -282,8 +267,7 @@ ClangCompleter::CandidatesForQueryAndLocationInFileAsync(
|
||||
|
||||
bool ClangCompleter::ShouldSkipClangResultCache( const std::string &query,
|
||||
int line,
|
||||
int column )
|
||||
{
|
||||
int column ) {
|
||||
// We need query.empty() in addition to the second check because if we don't
|
||||
// have it, then we have a problem in the following situation:
|
||||
// The user has a variable 'foo' of type 'A' and a variable 'bar' of type 'B'.
|
||||
@ -300,8 +284,7 @@ bool ClangCompleter::ShouldSkipClangResultCache( const std::string &query,
|
||||
// an out param
|
||||
void ClangCompleter::CreateSortingTask(
|
||||
const std::string &query,
|
||||
unique_future< AsyncCompletions > &future )
|
||||
{
|
||||
unique_future< AsyncCompletions > &future ) {
|
||||
// Careful! The code in this function may burn your eyes.
|
||||
|
||||
function< CompletionDatas( const CompletionDatas & ) >
|
||||
@ -331,8 +314,7 @@ void ClangCompleter::CreateClangTask(
|
||||
int line,
|
||||
int column,
|
||||
std::vector< UnsavedFile > unsaved_files,
|
||||
std::vector< std::string > flags )
|
||||
{
|
||||
std::vector< std::string > flags ) {
|
||||
latest_clang_results_.ResetWithNewLineAndColumn( line, column );
|
||||
|
||||
function< CompletionDatas() > candidates_for_location_functor =
|
||||
@ -347,7 +329,8 @@ void ClangCompleter::CreateClangTask(
|
||||
shared_ptr< ClangPackagedTask > clang_packaged_task =
|
||||
make_shared< ClangPackagedTask >();
|
||||
|
||||
clang_packaged_task->completions_task_ = packaged_task< AsyncCompletions >(
|
||||
clang_packaged_task->completions_task_ =
|
||||
packaged_task< AsyncCompletions >(
|
||||
bind( ReturnValueAsShared< std::vector< CompletionData > >,
|
||||
candidates_for_location_functor ) );
|
||||
|
||||
@ -358,8 +341,7 @@ void ClangCompleter::CreateClangTask(
|
||||
boost::shared_ptr< TranslationUnit > ClangCompleter::GetTranslationUnitForFile(
|
||||
const std::string &filename,
|
||||
const std::vector< UnsavedFile > &unsaved_files,
|
||||
const std::vector< std::string > &flags )
|
||||
{
|
||||
const std::vector< std::string > &flags ) {
|
||||
bool dont_care;
|
||||
return GetTranslationUnitForFile( filename, unsaved_files, flags, dont_care );
|
||||
}
|
||||
@ -374,15 +356,13 @@ shared_ptr< TranslationUnit > ClangCompleter::GetTranslationUnitForFile(
|
||||
const std::string &filename,
|
||||
const std::vector< UnsavedFile > &unsaved_files,
|
||||
const std::vector< std::string > &flags,
|
||||
bool &translation_unit_created )
|
||||
{
|
||||
bool &translation_unit_created ) {
|
||||
{
|
||||
lock_guard< mutex > lock( filename_to_translation_unit_mutex_ );
|
||||
TranslationUnitForFilename::iterator it =
|
||||
filename_to_translation_unit_.find( filename );
|
||||
|
||||
if ( it != filename_to_translation_unit_.end() )
|
||||
{
|
||||
if ( it != filename_to_translation_unit_.end() ) {
|
||||
translation_unit_created = false;
|
||||
return it->second;
|
||||
}
|
||||
@ -390,14 +370,12 @@ shared_ptr< TranslationUnit > ClangCompleter::GetTranslationUnitForFile(
|
||||
|
||||
shared_ptr< TranslationUnit > unit;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
unit = make_shared< TranslationUnit >(
|
||||
filename, unsaved_files, flags, clang_index_ );
|
||||
}
|
||||
|
||||
catch ( ClangParseError& )
|
||||
{
|
||||
catch ( ClangParseError & ) {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@ -413,8 +391,7 @@ shared_ptr< TranslationUnit > ClangCompleter::GetTranslationUnitForFile(
|
||||
|
||||
std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
||||
const std::string &query,
|
||||
const std::vector< CompletionData > &completion_datas )
|
||||
{
|
||||
const std::vector< CompletionData > &completion_datas ) {
|
||||
Bitset query_bitset = LetterBitsetFromString( query );
|
||||
|
||||
std::vector< const Candidate * > repository_candidates =
|
||||
@ -422,15 +399,15 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
||||
|
||||
std::vector< CompletionDataAndResult > data_and_results;
|
||||
|
||||
for ( uint i = 0; i < repository_candidates.size(); ++i )
|
||||
{
|
||||
for ( uint i = 0; i < repository_candidates.size(); ++i ) {
|
||||
const Candidate *candidate = repository_candidates[ i ];
|
||||
|
||||
if ( !candidate->MatchesQueryBitset( query_bitset ) )
|
||||
continue;
|
||||
|
||||
Result result = candidate->QueryMatchResult( query );
|
||||
if ( result.IsSubsequence() )
|
||||
{
|
||||
|
||||
if ( result.IsSubsequence() ) {
|
||||
CompletionDataAndResult data_and_result( &completion_datas[ i ], result );
|
||||
data_and_results.push_back( data_and_result );
|
||||
}
|
||||
@ -441,8 +418,7 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
||||
std::vector< CompletionData > sorted_completion_datas;
|
||||
sorted_completion_datas.reserve( data_and_results.size() );
|
||||
|
||||
foreach ( const CompletionDataAndResult& data_and_result, data_and_results )
|
||||
{
|
||||
foreach ( const CompletionDataAndResult & data_and_result, data_and_results ) {
|
||||
sorted_completion_datas.push_back( *data_and_result.completion_data_ );
|
||||
}
|
||||
|
||||
@ -450,14 +426,12 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
||||
}
|
||||
|
||||
|
||||
void ClangCompleter::InitThreads()
|
||||
{
|
||||
void ClangCompleter::InitThreads() {
|
||||
int threads_to_create =
|
||||
std::max( MIN_ASYNC_THREADS,
|
||||
std::min( MAX_ASYNC_THREADS, thread::hardware_concurrency() ) );
|
||||
|
||||
for ( int i = 0; i < threads_to_create; ++i )
|
||||
{
|
||||
for ( int i = 0; i < threads_to_create; ++i ) {
|
||||
sorting_threads_.create_thread( bind( &ClangCompleter::SortingThreadMain,
|
||||
boost::ref( *this ) ) );
|
||||
}
|
||||
@ -467,15 +441,13 @@ void ClangCompleter::InitThreads()
|
||||
}
|
||||
|
||||
|
||||
void ClangCompleter::ClangThreadMain()
|
||||
{
|
||||
while ( true )
|
||||
{
|
||||
try
|
||||
{
|
||||
void ClangCompleter::ClangThreadMain() {
|
||||
while ( true ) {
|
||||
try {
|
||||
shared_ptr< ClangPackagedTask > task = clang_task_.Get();
|
||||
|
||||
bool has_completions_task = task->completions_task_.valid();
|
||||
|
||||
if ( has_completions_task )
|
||||
task->completions_task_();
|
||||
else
|
||||
@ -496,28 +468,25 @@ void ClangCompleter::ClangThreadMain()
|
||||
clang_data_ready_condition_variable_.notify_all();
|
||||
}
|
||||
|
||||
catch ( thread_interrupted& )
|
||||
{
|
||||
catch ( thread_interrupted & ) {
|
||||
shared_lock< shared_mutex > lock( time_to_die_mutex_ );
|
||||
|
||||
if ( time_to_die_ )
|
||||
return;
|
||||
|
||||
// else do nothing and re-enter the loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ClangCompleter::SortingThreadMain()
|
||||
{
|
||||
while ( true )
|
||||
{
|
||||
try
|
||||
{
|
||||
void ClangCompleter::SortingThreadMain() {
|
||||
while ( true ) {
|
||||
try {
|
||||
{
|
||||
unique_lock< mutex > lock( clang_data_ready_mutex_ );
|
||||
|
||||
while ( !clang_data_ready_ )
|
||||
{
|
||||
while ( !clang_data_ready_ ) {
|
||||
clang_data_ready_condition_variable_.wait( lock );
|
||||
}
|
||||
}
|
||||
@ -528,11 +497,12 @@ void ClangCompleter::SortingThreadMain()
|
||||
( *task )();
|
||||
}
|
||||
|
||||
catch ( thread_interrupted& )
|
||||
{
|
||||
catch ( thread_interrupted & ) {
|
||||
shared_lock< shared_mutex > lock( time_to_die_mutex_ );
|
||||
|
||||
if ( time_to_die_ )
|
||||
return;
|
||||
|
||||
// else do nothing and re-enter the loop
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,7 @@
|
||||
typedef void *CXIndex;
|
||||
typedef struct CXTranslationUnitImpl *CXTranslationUnit;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
class CandidateRepository;
|
||||
class TranslationUnit;
|
||||
@ -53,8 +52,7 @@ typedef boost::unordered_map< std::string,
|
||||
|
||||
|
||||
// TODO: document that all filename parameters must be absolute paths
|
||||
class ClangCompleter : boost::noncopyable
|
||||
{
|
||||
class ClangCompleter : boost::noncopyable {
|
||||
public:
|
||||
ClangCompleter();
|
||||
~ClangCompleter();
|
||||
@ -98,8 +96,7 @@ private:
|
||||
|
||||
// This is basically a union. Only one of the two tasks is set to something
|
||||
// valid, the other task is invalid. Which one is valid depends on the caller.
|
||||
struct ClangPackagedTask
|
||||
{
|
||||
struct ClangPackagedTask {
|
||||
boost::packaged_task< AsyncCompletions > completions_task_;
|
||||
boost::packaged_task< void > parsing_task_;
|
||||
};
|
||||
|
@ -22,19 +22,17 @@ using boost::shared_mutex;
|
||||
using boost::shared_lock;
|
||||
using boost::unique_lock;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
bool ClangResultsCache::NewPositionDifferentFromStoredPosition( int new_line,
|
||||
int new_colum )
|
||||
const
|
||||
{
|
||||
const {
|
||||
shared_lock< shared_mutex > reader_lock( access_mutex_ );
|
||||
return line_ != new_line || column_ != new_colum;
|
||||
}
|
||||
|
||||
void ClangResultsCache::ResetWithNewLineAndColumn( int new_line, int new_colum )
|
||||
{
|
||||
void ClangResultsCache::ResetWithNewLineAndColumn( int new_line,
|
||||
int new_colum ) {
|
||||
unique_lock< shared_mutex > reader_lock( access_mutex_ );
|
||||
|
||||
line_ = new_line;
|
||||
|
@ -27,13 +27,11 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
struct CompletionData;
|
||||
|
||||
class ClangResultsCache : boost::noncopyable
|
||||
{
|
||||
class ClangResultsCache : boost::noncopyable {
|
||||
public:
|
||||
|
||||
ClangResultsCache() : line_( -1 ), column_( -1 ) {}
|
||||
@ -43,8 +41,8 @@ public:
|
||||
|
||||
void ResetWithNewLineAndColumn( int new_line, int new_colum );
|
||||
|
||||
void SetCompletionDatas( const std::vector< CompletionData > new_completions )
|
||||
{
|
||||
void SetCompletionDatas(
|
||||
const std::vector< CompletionData > new_completions ) {
|
||||
completion_datas_ = new_completions;
|
||||
}
|
||||
|
||||
@ -54,8 +52,7 @@ public:
|
||||
# pragma clang diagnostic ignored "-Wc++98-compat"
|
||||
# endif //#ifdef __clang__
|
||||
|
||||
void SetCompletionDatas( std::vector< CompletionData >&& new_completions )
|
||||
{
|
||||
void SetCompletionDatas( std::vector< CompletionData > && new_completions ) {
|
||||
completion_datas_ = new_completions;
|
||||
}
|
||||
|
||||
@ -67,8 +64,7 @@ public:
|
||||
template< typename T >
|
||||
T OperateOnCompletionDatas(
|
||||
boost::function< T( const std::vector< CompletionData >& ) > operation )
|
||||
const
|
||||
{
|
||||
const {
|
||||
boost::shared_lock< boost::shared_mutex > reader_lock( access_mutex_ );
|
||||
return operation( completion_datas_ );
|
||||
}
|
||||
|
@ -26,12 +26,11 @@
|
||||
#include <boost/unordered_map.hpp>
|
||||
using boost::unordered_map;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
std::string CXStringToString( CXString text )
|
||||
{
|
||||
std::string CXStringToString( CXString text ) {
|
||||
std::string final_string;
|
||||
|
||||
if ( !text.data )
|
||||
return final_string;
|
||||
|
||||
@ -40,13 +39,12 @@ std::string CXStringToString( CXString text )
|
||||
return final_string;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
// NOTE: The passed in pointer should never be NULL!
|
||||
std::string FullDiagnosticText( CXDiagnostic cxdiagnostic )
|
||||
{
|
||||
std::string full_text = CXStringToString( clang_formatDiagnostic(
|
||||
std::string FullDiagnosticText( CXDiagnostic cxdiagnostic ) {
|
||||
std::string full_text = CXStringToString(
|
||||
clang_formatDiagnostic(
|
||||
cxdiagnostic,
|
||||
clang_defaultDiagnosticDisplayOptions() ) );
|
||||
|
||||
@ -54,16 +52,18 @@ std::string FullDiagnosticText( CXDiagnostic cxdiagnostic )
|
||||
// clang_getChildDiagnostics do NOT need to be released with
|
||||
// clang_diposeDiagnosticSet
|
||||
CXDiagnosticSet diag_set = clang_getChildDiagnostics( cxdiagnostic );
|
||||
|
||||
if ( !diag_set )
|
||||
return full_text;
|
||||
|
||||
uint num_child_diagnostics = clang_getNumDiagnosticsInSet( diag_set );
|
||||
|
||||
if ( !num_child_diagnostics )
|
||||
return full_text;
|
||||
|
||||
for ( uint i = 0; i < num_child_diagnostics; ++i )
|
||||
{
|
||||
for ( uint i = 0; i < num_child_diagnostics; ++i ) {
|
||||
CXDiagnostic diagnostic = clang_getDiagnosticInSet( diag_set, i );
|
||||
|
||||
if ( !diagnostic )
|
||||
continue;
|
||||
|
||||
@ -74,10 +74,8 @@ std::string FullDiagnosticText( CXDiagnostic cxdiagnostic )
|
||||
}
|
||||
|
||||
|
||||
char DiagnosticSeverityToType( CXDiagnosticSeverity severity )
|
||||
{
|
||||
switch ( severity )
|
||||
{
|
||||
char DiagnosticSeverityToType( CXDiagnosticSeverity severity ) {
|
||||
switch ( severity ) {
|
||||
case CXDiagnostic_Ignored:
|
||||
case CXDiagnostic_Note:
|
||||
return 'I';
|
||||
@ -98,10 +96,10 @@ char DiagnosticSeverityToType( CXDiagnosticSeverity severity )
|
||||
// Returns true when the provided completion string is available to the user;
|
||||
// unavailable completion strings refer to entities that are private/protected,
|
||||
// deprecated etc.
|
||||
bool CompletionStringAvailable( CXCompletionString completion_string )
|
||||
{
|
||||
bool CompletionStringAvailable( CXCompletionString completion_string ) {
|
||||
if ( !completion_string )
|
||||
return false;
|
||||
|
||||
return clang_getCompletionAvailability( completion_string ) ==
|
||||
CXAvailability_Available;
|
||||
}
|
||||
@ -110,11 +108,10 @@ bool CompletionStringAvailable( CXCompletionString completion_string )
|
||||
|
||||
|
||||
std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
const std::vector< UnsavedFile > &unsaved_files )
|
||||
{
|
||||
const std::vector< UnsavedFile > &unsaved_files ) {
|
||||
std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() );
|
||||
for ( uint i = 0; i < unsaved_files.size(); ++i )
|
||||
{
|
||||
|
||||
for ( uint i = 0; i < unsaved_files.size(); ++i ) {
|
||||
X_VERIFY( unsaved_files[ i ].filename_ );
|
||||
X_VERIFY( unsaved_files[ i ].contents_ );
|
||||
X_VERIFY( unsaved_files[ i ].length_ );
|
||||
@ -128,17 +125,16 @@ std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
|
||||
|
||||
std::vector< CompletionData > ToCompletionDataVector(
|
||||
CXCodeCompleteResults *results )
|
||||
{
|
||||
CXCodeCompleteResults *results ) {
|
||||
std::vector< CompletionData > completions;
|
||||
|
||||
if ( !results || !results->Results )
|
||||
return completions;
|
||||
|
||||
completions.reserve( results->NumResults );
|
||||
unordered_map< std::string, uint > seen_data;
|
||||
|
||||
for ( uint i = 0; i < results->NumResults; ++i )
|
||||
{
|
||||
for ( uint i = 0; i < results->NumResults; ++i ) {
|
||||
CXCompletionResult completion_result = results->Results[ i ];
|
||||
|
||||
if ( !CompletionStringAvailable( completion_result.CompletionString ) )
|
||||
@ -149,13 +145,11 @@ std::vector< CompletionData > ToCompletionDataVector(
|
||||
data.original_string_,
|
||||
completions.size() );
|
||||
|
||||
if ( index == completions.size() )
|
||||
{
|
||||
if ( index == completions.size() ) {
|
||||
completions.push_back( boost::move( data ) );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
// If we have already seen this completion, then this is an overload of a
|
||||
// function we have seen. We add the signature of the overload to the
|
||||
// detailed information.
|
||||
@ -171,9 +165,9 @@ std::vector< CompletionData > ToCompletionDataVector(
|
||||
}
|
||||
|
||||
|
||||
Diagnostic CXDiagnosticToDiagnostic( CXDiagnostic cxdiagnostic )
|
||||
{
|
||||
Diagnostic CXDiagnosticToDiagnostic( CXDiagnostic cxdiagnostic ) {
|
||||
Diagnostic diagnostic;
|
||||
|
||||
if ( !cxdiagnostic )
|
||||
return diagnostic;
|
||||
|
||||
|
@ -25,8 +25,7 @@
|
||||
#include <vector>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
std::string CXStringToString( CXString text );
|
||||
|
||||
|
@ -19,13 +19,11 @@
|
||||
#include "ClangUtils.h"
|
||||
#include "standard.h"
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
CompilationDatabase::CompilationDatabase(
|
||||
const std::string &path_to_directory )
|
||||
: is_loaded_( false )
|
||||
{
|
||||
: is_loaded_( false ) {
|
||||
CXCompilationDatabase_Error status;
|
||||
compilation_database_ = clang_CompilationDatabase_fromDirectory(
|
||||
path_to_directory.c_str(),
|
||||
@ -34,22 +32,20 @@ CompilationDatabase::CompilationDatabase(
|
||||
}
|
||||
|
||||
|
||||
CompilationDatabase::~CompilationDatabase()
|
||||
{
|
||||
CompilationDatabase::~CompilationDatabase() {
|
||||
clang_CompilationDatabase_dispose( compilation_database_ );
|
||||
}
|
||||
|
||||
|
||||
bool CompilationDatabase::DatabaseSuccessfullyLoaded()
|
||||
{
|
||||
bool CompilationDatabase::DatabaseSuccessfullyLoaded() {
|
||||
return is_loaded_;
|
||||
}
|
||||
|
||||
|
||||
std::vector< std::string > CompilationDatabase::FlagsForFile(
|
||||
const std::string &path_to_file )
|
||||
{
|
||||
const std::string &path_to_file ) {
|
||||
std::vector< std::string > flags;
|
||||
|
||||
if ( !is_loaded_ )
|
||||
return flags;
|
||||
|
||||
@ -59,6 +55,7 @@ std::vector< std::string > CompilationDatabase::FlagsForFile(
|
||||
path_to_file.c_str() );
|
||||
|
||||
uint num_commands = clang_CompileCommands_getSize( commands );
|
||||
|
||||
if ( num_commands < 1 ) {
|
||||
clang_CompileCommands_dispose( commands );
|
||||
return flags;
|
||||
@ -71,8 +68,8 @@ std::vector< std::string > CompilationDatabase::FlagsForFile(
|
||||
|
||||
uint num_flags = clang_CompileCommand_getNumArgs( command );
|
||||
flags.reserve( num_flags );
|
||||
for ( uint i = 0; i < num_flags; ++i )
|
||||
{
|
||||
|
||||
for ( uint i = 0; i < num_flags; ++i ) {
|
||||
flags.push_back( CXStringToString(
|
||||
clang_CompileCommand_getArg( command, i ) ) );
|
||||
}
|
||||
@ -83,9 +80,9 @@ std::vector< std::string > CompilationDatabase::FlagsForFile(
|
||||
|
||||
|
||||
std::string CompilationDatabase::CompileCommandWorkingDirectoryForFile(
|
||||
const std::string &path_to_file )
|
||||
{
|
||||
const std::string &path_to_file ) {
|
||||
std::string path_to_directory;
|
||||
|
||||
if ( !is_loaded_ )
|
||||
return path_to_directory;
|
||||
|
||||
@ -95,6 +92,7 @@ std::string CompilationDatabase::CompileCommandWorkingDirectoryForFile(
|
||||
path_to_file.c_str() );
|
||||
|
||||
uint num_commands = clang_CompileCommands_getSize( commands );
|
||||
|
||||
if ( num_commands < 1 ) {
|
||||
clang_CompileCommands_dispose( commands );
|
||||
return path_to_directory;
|
||||
|
@ -23,11 +23,9 @@
|
||||
#include <boost/utility.hpp>
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
class CompilationDatabase : boost::noncopyable
|
||||
{
|
||||
class CompilationDatabase : boost::noncopyable {
|
||||
public:
|
||||
CompilationDatabase( const std::string &path_to_directory );
|
||||
~CompilationDatabase();
|
||||
|
@ -21,15 +21,12 @@
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
char CursorKindToVimKind( CXCursorKind kind )
|
||||
{
|
||||
char CursorKindToVimKind( CXCursorKind kind ) {
|
||||
// TODO: actually it appears that Vim will show returned kinds even when they
|
||||
// do not match the "approved" list, so let's use that
|
||||
switch ( kind )
|
||||
{
|
||||
switch ( kind ) {
|
||||
case CXCursor_UnexposedDecl:
|
||||
case CXCursor_StructDecl:
|
||||
case CXCursor_UnionDecl:
|
||||
@ -58,8 +55,7 @@ char CursorKindToVimKind( CXCursorKind kind )
|
||||
}
|
||||
|
||||
|
||||
bool IsMainCompletionTextInfo( CXCompletionChunkKind kind )
|
||||
{
|
||||
bool IsMainCompletionTextInfo( CXCompletionChunkKind kind ) {
|
||||
return
|
||||
kind == CXCompletionChunk_Optional ||
|
||||
kind == CXCompletionChunk_TypedText ||
|
||||
@ -83,19 +79,19 @@ bool IsMainCompletionTextInfo( CXCompletionChunkKind kind )
|
||||
|
||||
|
||||
std::string ChunkToString( CXCompletionString completion_string,
|
||||
uint chunk_num )
|
||||
{
|
||||
uint chunk_num ) {
|
||||
if ( !completion_string )
|
||||
return std::string();
|
||||
|
||||
return YouCompleteMe::CXStringToString(
|
||||
clang_getCompletionChunkText( completion_string, chunk_num ) );
|
||||
}
|
||||
|
||||
|
||||
std::string OptionalChunkToString( CXCompletionString completion_string,
|
||||
uint chunk_num )
|
||||
{
|
||||
uint chunk_num ) {
|
||||
std::string final_string;
|
||||
|
||||
if ( !completion_string )
|
||||
return final_string;
|
||||
|
||||
@ -108,19 +104,16 @@ std::string OptionalChunkToString( CXCompletionString completion_string,
|
||||
uint optional_num_chunks = clang_getNumCompletionChunks(
|
||||
optional_completion_string );
|
||||
|
||||
for ( uint j = 0; j < optional_num_chunks; ++j )
|
||||
{
|
||||
for ( uint j = 0; j < optional_num_chunks; ++j ) {
|
||||
CXCompletionChunkKind kind = clang_getCompletionChunkKind(
|
||||
optional_completion_string, j );
|
||||
|
||||
if ( kind == CXCompletionChunk_Optional )
|
||||
{
|
||||
if ( kind == CXCompletionChunk_Optional ) {
|
||||
final_string.append( OptionalChunkToString( optional_completion_string,
|
||||
j ) );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
final_string.append( ChunkToString( optional_completion_string, j ) );
|
||||
}
|
||||
}
|
||||
@ -134,8 +127,7 @@ std::string OptionalChunkToString( CXCompletionString completion_string,
|
||||
// the parameter BUT if this code is compiled in C++11 mode a move constructor
|
||||
// can be called on the passed-in value. This is not possible if we accept the
|
||||
// param by const ref.
|
||||
std::string RemoveTwoConsecutiveUnderscores( std::string text )
|
||||
{
|
||||
std::string RemoveTwoConsecutiveUnderscores( std::string text ) {
|
||||
boost::erase_all( text, "__" );
|
||||
return text;
|
||||
}
|
||||
@ -143,11 +135,9 @@ std::string RemoveTwoConsecutiveUnderscores( std::string text )
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
CompletionData::CompletionData( const CXCompletionResult &completion_result )
|
||||
{
|
||||
CompletionData::CompletionData( const CXCompletionResult &completion_result ) {
|
||||
CXCompletionString completion_string = completion_result.CompletionString;
|
||||
|
||||
if ( !completion_string )
|
||||
@ -157,8 +147,7 @@ CompletionData::CompletionData( const CXCompletionResult &completion_result )
|
||||
bool saw_left_paren = false;
|
||||
bool saw_function_params = false;
|
||||
|
||||
for ( uint j = 0; j < num_chunks; ++j )
|
||||
{
|
||||
for ( uint j = 0; j < num_chunks; ++j ) {
|
||||
ExtractDataFromChunk( completion_string,
|
||||
j,
|
||||
saw_left_paren,
|
||||
@ -187,40 +176,33 @@ CompletionData::CompletionData( const CXCompletionResult &completion_result )
|
||||
void CompletionData::ExtractDataFromChunk( CXCompletionString completion_string,
|
||||
uint chunk_num,
|
||||
bool &saw_left_paren,
|
||||
bool &saw_function_params )
|
||||
{
|
||||
bool &saw_function_params ) {
|
||||
CXCompletionChunkKind kind = clang_getCompletionChunkKind(
|
||||
completion_string, chunk_num );
|
||||
|
||||
if ( IsMainCompletionTextInfo( kind ) )
|
||||
{
|
||||
if ( kind == CXCompletionChunk_LeftParen )
|
||||
{
|
||||
if ( IsMainCompletionTextInfo( kind ) ) {
|
||||
if ( kind == CXCompletionChunk_LeftParen ) {
|
||||
saw_left_paren = true;
|
||||
}
|
||||
|
||||
else if ( saw_left_paren &&
|
||||
!saw_function_params &&
|
||||
kind != CXCompletionChunk_RightParen &&
|
||||
kind != CXCompletionChunk_Informative )
|
||||
{
|
||||
kind != CXCompletionChunk_Informative ) {
|
||||
saw_function_params = true;
|
||||
everything_except_return_type_.append( " " );
|
||||
}
|
||||
|
||||
else if ( saw_function_params && kind == CXCompletionChunk_RightParen )
|
||||
{
|
||||
else if ( saw_function_params && kind == CXCompletionChunk_RightParen ) {
|
||||
everything_except_return_type_.append( " " );
|
||||
}
|
||||
|
||||
if ( kind == CXCompletionChunk_Optional )
|
||||
{
|
||||
if ( kind == CXCompletionChunk_Optional ) {
|
||||
everything_except_return_type_.append(
|
||||
OptionalChunkToString( completion_string, chunk_num ) );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
everything_except_return_type_.append(
|
||||
ChunkToString( completion_string, chunk_num ) );
|
||||
}
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include <string>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
// This class holds pieces of information about a single completion coming from
|
||||
// clang. These pieces are shown in Vim's UI in different ways.
|
||||
@ -37,16 +36,14 @@ namespace YouCompleteMe
|
||||
//
|
||||
// The user can also enable a "preview" window that will show extra information
|
||||
// about a completion at the top of the buffer.
|
||||
struct CompletionData
|
||||
{
|
||||
struct CompletionData {
|
||||
CompletionData() {}
|
||||
CompletionData( const CXCompletionResult &completion_result );
|
||||
|
||||
// What should actually be inserted into the buffer. For a function like
|
||||
// "int foo(int x)", this is just "foo". Same for a data member like "foo_":
|
||||
// we insert just "foo_".
|
||||
std::string TextToInsertInBuffer()
|
||||
{
|
||||
std::string TextToInsertInBuffer() {
|
||||
return original_string_;
|
||||
}
|
||||
|
||||
@ -55,29 +52,25 @@ struct CompletionData
|
||||
// the completion is, say, a data member. So for a function like "int foo(int
|
||||
// x)", this would be "foo(int x)". For a data member like "count_", it would
|
||||
// be just "count_".
|
||||
std::string MainCompletionText()
|
||||
{
|
||||
std::string MainCompletionText() {
|
||||
return everything_except_return_type_;
|
||||
}
|
||||
|
||||
// This is extra info shown in the pop-up completion menu, after the
|
||||
// completion text and the kind. Currently we put the return type of the
|
||||
// function here, if any.
|
||||
std::string ExtraMenuInfo()
|
||||
{
|
||||
std::string ExtraMenuInfo() {
|
||||
return return_type_;
|
||||
}
|
||||
|
||||
// This is used to show extra information in vim's preview window. This is the
|
||||
// window that vim usually shows at the top of the buffer. This should be used
|
||||
// for extra information about the completion.
|
||||
std::string DetailedInfoForPreviewWindow()
|
||||
{
|
||||
std::string DetailedInfoForPreviewWindow() {
|
||||
return detailed_info_;
|
||||
}
|
||||
|
||||
bool operator== ( const CompletionData &other ) const
|
||||
{
|
||||
bool operator== ( const CompletionData &other ) const {
|
||||
return
|
||||
kind_ == other.kind_ &&
|
||||
everything_except_return_type_ == other.everything_except_return_type_ &&
|
||||
|
@ -21,13 +21,10 @@
|
||||
#include "standard.h"
|
||||
#include <string>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
struct Diagnostic
|
||||
{
|
||||
bool operator== ( const Diagnostic &other ) const
|
||||
{
|
||||
struct Diagnostic {
|
||||
bool operator== ( const Diagnostic &other ) const {
|
||||
return
|
||||
line_number_ == other.line_number_ &&
|
||||
column_number_ == other.column_number_ &&
|
||||
|
@ -28,8 +28,7 @@ using boost::unique_lock;
|
||||
using boost::mutex;
|
||||
using boost::try_to_lock_t;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
TranslationUnit::TranslationUnit(
|
||||
const std::string &filename,
|
||||
@ -37,18 +36,16 @@ TranslationUnit::TranslationUnit(
|
||||
const std::vector< std::string > &flags,
|
||||
CXIndex clang_index )
|
||||
: filename_( filename ),
|
||||
clang_translation_unit_( NULL )
|
||||
{
|
||||
clang_translation_unit_( NULL ) {
|
||||
std::vector< const char * > pointer_flags;
|
||||
pointer_flags.reserve( flags.size() );
|
||||
|
||||
foreach ( const std::string &flag, flags )
|
||||
{
|
||||
foreach ( const std::string & flag, flags ) {
|
||||
pointer_flags.push_back( flag.c_str() );
|
||||
}
|
||||
|
||||
std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles(
|
||||
unsaved_files );
|
||||
std::vector< CXUnsavedFile > cxunsaved_files =
|
||||
ToCXUnsavedFiles( unsaved_files );
|
||||
|
||||
clang_translation_unit_ = clang_parseTranslationUnit(
|
||||
clang_index,
|
||||
@ -68,15 +65,13 @@ TranslationUnit::TranslationUnit(
|
||||
}
|
||||
|
||||
|
||||
TranslationUnit::~TranslationUnit()
|
||||
{
|
||||
TranslationUnit::~TranslationUnit() {
|
||||
if ( clang_translation_unit_ )
|
||||
clang_disposeTranslationUnit( clang_translation_unit_ );
|
||||
}
|
||||
|
||||
|
||||
std::vector< Diagnostic > TranslationUnit::LatestDiagnostics()
|
||||
{
|
||||
std::vector< Diagnostic > TranslationUnit::LatestDiagnostics() {
|
||||
std::vector< Diagnostic > diagnostics;
|
||||
unique_lock< mutex > lock( diagnostics_mutex_ );
|
||||
|
||||
@ -95,17 +90,16 @@ std::vector< Diagnostic > TranslationUnit::LatestDiagnostics()
|
||||
}
|
||||
|
||||
|
||||
bool TranslationUnit::IsCurrentlyUpdating() const
|
||||
{
|
||||
bool TranslationUnit::IsCurrentlyUpdating() const {
|
||||
unique_lock< mutex > lock( clang_access_mutex_, try_to_lock_t() );
|
||||
return !lock.owns_lock();
|
||||
}
|
||||
|
||||
|
||||
void TranslationUnit::Reparse( const std::vector< UnsavedFile > &unsaved_files )
|
||||
{
|
||||
std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles(
|
||||
unsaved_files );
|
||||
void TranslationUnit::Reparse(
|
||||
const std::vector< UnsavedFile > &unsaved_files ) {
|
||||
std::vector< CXUnsavedFile > cxunsaved_files =
|
||||
ToCXUnsavedFiles( unsaved_files );
|
||||
|
||||
Reparse( cxunsaved_files );
|
||||
}
|
||||
@ -114,15 +108,14 @@ void TranslationUnit::Reparse( const std::vector< UnsavedFile > &unsaved_files )
|
||||
std::vector< CompletionData > TranslationUnit::CandidatesForLocation(
|
||||
int line,
|
||||
int column,
|
||||
const std::vector< UnsavedFile > &unsaved_files )
|
||||
{
|
||||
const std::vector< UnsavedFile > &unsaved_files ) {
|
||||
unique_lock< mutex > lock( clang_access_mutex_ );
|
||||
|
||||
if ( !clang_translation_unit_ )
|
||||
return std::vector< CompletionData >();
|
||||
|
||||
std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles(
|
||||
unsaved_files );
|
||||
std::vector< CXUnsavedFile > cxunsaved_files =
|
||||
ToCXUnsavedFiles( unsaved_files );
|
||||
|
||||
// codeCompleteAt reparses the TU if the underlying source file has changed on
|
||||
// disk since the last time the TU was updated and there are no unsaved files.
|
||||
@ -153,8 +146,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation(
|
||||
// non-const pointer to clang. This function (and clang too) will not modify the
|
||||
// param though.
|
||||
void TranslationUnit::Reparse(
|
||||
std::vector< CXUnsavedFile > &unsaved_files )
|
||||
{
|
||||
std::vector< CXUnsavedFile > &unsaved_files ) {
|
||||
unique_lock< mutex > lock( clang_access_mutex_ );
|
||||
|
||||
if ( !clang_translation_unit_ )
|
||||
@ -166,8 +158,7 @@ void TranslationUnit::Reparse(
|
||||
&unsaved_files[ 0 ],
|
||||
clang_defaultEditingTranslationUnitOptions() );
|
||||
|
||||
if ( failure )
|
||||
{
|
||||
if ( failure ) {
|
||||
clang_disposeTranslationUnit( clang_translation_unit_ );
|
||||
clang_translation_unit_ = NULL;
|
||||
boost_throw( ClangParseError() );
|
||||
@ -178,17 +169,16 @@ void TranslationUnit::Reparse(
|
||||
|
||||
|
||||
// Should only be called while holding the clang_access_mutex_
|
||||
void TranslationUnit::UpdateLatestDiagnostics()
|
||||
{
|
||||
void TranslationUnit::UpdateLatestDiagnostics() {
|
||||
unique_lock< mutex > lock( diagnostics_mutex_ );
|
||||
|
||||
latest_diagnostics_.clear();
|
||||
uint num_diagnostics = clang_getNumDiagnostics( clang_translation_unit_ );
|
||||
latest_diagnostics_.reserve( num_diagnostics );
|
||||
|
||||
for ( uint i = 0; i < num_diagnostics; ++i )
|
||||
{
|
||||
Diagnostic diagnostic = CXDiagnosticToDiagnostic(
|
||||
for ( uint i = 0; i < num_diagnostics; ++i ) {
|
||||
Diagnostic diagnostic =
|
||||
CXDiagnosticToDiagnostic(
|
||||
clang_getDiagnostic( clang_translation_unit_, i ) );
|
||||
|
||||
if ( diagnostic.kind_ != 'I' )
|
||||
|
@ -33,14 +33,12 @@ typedef void *CXIndex;
|
||||
typedef struct CXTranslationUnitImpl *CXTranslationUnit;
|
||||
struct CXUnsavedFile;
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
namespace YouCompleteMe {
|
||||
|
||||
struct CompletionData;
|
||||
typedef boost::shared_ptr< std::vector< CompletionData > > AsyncCompletions;
|
||||
|
||||
class TranslationUnit : boost::noncopyable
|
||||
{
|
||||
class TranslationUnit : boost::noncopyable {
|
||||
public:
|
||||
|
||||
TranslationUnit(
|
||||
|
@ -20,8 +20,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
struct UnsavedFile
|
||||
{
|
||||
struct UnsavedFile {
|
||||
UnsavedFile() : filename_( NULL ), contents_( NULL ), length_( 0 ) {}
|
||||
|
||||
const char *filename_;
|
||||
@ -32,8 +31,7 @@ struct UnsavedFile
|
||||
// methods. I have no clue why, but it won't compile without it.
|
||||
// TODO: report this problem on the Boost bug tracker, the default equality
|
||||
// operator should be more than adequate here
|
||||
bool operator== ( const UnsavedFile &other ) const
|
||||
{
|
||||
bool operator== ( const UnsavedFile &other ) const {
|
||||
return
|
||||
filename_ == other.filename_ &&
|
||||
contents_ == other.contents_ &&
|
||||
|
Loading…
Reference in New Issue
Block a user