From d3105fdc63ea1e520fe99a0a17ebfe38f17d01de Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 17 Jul 2020 18:59:57 +0200 Subject: [PATCH] No longer shows info message when cancelling finding usages --- src/source_clang.cpp | 9 +++++++-- src/usages_clang.cpp | 6 +++--- src/usages_clang.hpp | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/source_clang.cpp b/src/source_clang.cpp index 01302b7..f5138fd 100644 --- a/src/source_clang.cpp +++ b/src/source_clang.cpp @@ -1102,10 +1102,12 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file auto build = Project::Build::create(this->file_path); auto usages = Usages::Clang::get_usages(build->project_path, build->get_default_path(), build->get_debug_path(), identifier.spelling, identifier.cursor, translation_units); + if(!usages) + return; std::vector renamed_views; std::vector usages_renamed; - for(auto &usage : usages) { + for(auto &usage : *usages) { size_t line_c = usage.lines.size() - 1; auto view_it = views.end(); for(auto it = views.begin(); it != views.end(); ++it) { @@ -1569,7 +1571,10 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file auto build = Project::Build::create(this->file_path); auto usages_clang = Usages::Clang::get_usages(build->project_path, build->get_default_path(), build->get_debug_path(), {identifier.spelling}, {identifier.cursor}, translation_units); - for(auto &usage : usages_clang) { + if(!usages_clang) + return usages; + + for(auto &usage : *usages_clang) { for(size_t c = 0; c < usage.offsets.size(); ++c) { std::string line = Glib::Markup::escape_text(usage.lines[c]); embolden_token(line, usage.offsets[c].first.index - 1, usage.offsets[c].second.index - 1); diff --git a/src/usages_clang.cpp b/src/usages_clang.cpp index baf0f6e..762034e 100644 --- a/src/usages_clang.cpp +++ b/src/usages_clang.cpp @@ -115,12 +115,12 @@ std::vector> Usages::Clang::Cache::g return offsets; } -std::vector Usages::Clang::get_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path, - const std::string &spelling, const clangmm::Cursor &cursor, const std::vector &translation_units) { +boost::optional> Usages::Clang::get_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path, + const std::string &spelling, const clangmm::Cursor &cursor, const std::vector &translation_units) { std::vector usages; if(spelling.empty()) - return usages; + return {}; PathSet visited; diff --git a/src/usages_clang.hpp b/src/usages_clang.hpp index 4cd67fb..6010d23 100644 --- a/src/usages_clang.hpp +++ b/src/usages_clang.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -108,8 +109,8 @@ namespace Usages { static std::atomic cache_in_progress_count; public: - static std::vector get_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path, - const std::string &spelling, const clangmm::Cursor &cursor, const std::vector &translation_units); + static boost::optional> get_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path, + const std::string &spelling, const clangmm::Cursor &cursor, const std::vector &translation_units); static void cache(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path, std::time_t before_parse_time, const PathSet &project_paths_in_use, clangmm::TranslationUnit *translation_unit, clangmm::Tokens *tokens);