std::vector< FixIt > TranslationUnit::GetFixItsForLocationInFile( int line, int column, const std::vector< UnsavedFile > &unsaved_files, bool reparse ) { if ( reparse ) Reparse( unsaved_files ); std::vector< FixIt > fixits; { unique_lock< mutex > lock( diagnostics_mutex_ ); for ( const Diagnostic& diagnostic : latest_diagnostics_ ) { // Find all diagnostics for the supplied line which have FixIts attached if ( diagnostic.location_.line_number_ == static_cast< size_t >( line ) ) { fixits.insert( fixits.end(), diagnostic.fixits_.begin(), diagnostic.fixits_.end() ); } } } // Sort them by the distance to the supplied column std::sort( fixits.begin(), fixits.end(), sort_by_location( column ) ); return fixits; }
static void sort_by_location(std::multimap<std::string, Species> location_map, std::vector<Species>& species, const std::string location="") { std::multimap<std::string, Species>::iterator itr; while ((itr = location_map.find(location)) != location_map.end()) { const Species sp((*itr).second); species.push_back(sp); sort_by_location(location_map, species, sp.serial()); location_map.erase(itr); } }
std::vector< FixIt > TranslationUnit::GetFixItsForLocationInFile( const std::string &filename, int line, int column, const std::vector< UnsavedFile > &unsaved_files, bool reparse ) { if ( reparse ) { Reparse( unsaved_files ); } std::vector< FixIt > fixits; auto canonical_filename = boost::filesystem::canonical( filename ); { unique_lock< mutex > lock( diagnostics_mutex_ ); for ( const Diagnostic& diagnostic : latest_diagnostics_ ) { auto this_filename = boost::filesystem::canonical( diagnostic.location_.filename_ ); if ( canonical_filename != this_filename ) { continue; } // Find all diagnostics for the supplied line which have FixIts attached if ( diagnostic.location_.line_number_ != static_cast< size_t >( line ) ) { continue; } fixits.insert( fixits.end(), diagnostic.fixits_.begin(), diagnostic.fixits_.end() ); } } // Sort them by the distance to the supplied column std::sort( fixits.begin(), fixits.end(), sort_by_location( column ) ); return fixits; }