diff --git a/src/source_clang.cpp b/src/source_clang.cpp index f71deb0..9550ae1 100644 --- a/src/source_clang.cpp +++ b/src/source_clang.cpp @@ -2003,36 +2003,6 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file return std::tuple(Source::Offset(), "", 0); } }; - - get_coverage = [this]() { - auto build = Project::Build::create(this->file_path); - if(build->project_path.empty()) { - Info::get().print(this->file_path.filename().string() + ": could not find a supported build system"); - return std::vector{}; - } - build->update_default(); - CompileCommands commands(build->get_default_path()); - boost::filesystem::path object_file; - for(const auto &command : commands.commands) { - if(command.file == this->file_path) { - auto values = command.parameter_values("-o"); - if(!values.empty()) { - object_file = command.directory / values.front(); - break; - } - } - } - if(object_file.empty()) { - Info::get().print(this->file_path.filename().string() + ": could not find the C/C++ object file"); - return std::vector{}; - } - - auto result = Coverage::analyze(Coverage::FileInfo{this->file_path, object_file, build->get_default_path(), this->language_id}); - if(result.empty()) { - Info::get().print(this->file_path.filename().string() + ": no supported coverage information found"); - } - return result; - }; } Source::ClangViewRefactor::Identifier Source::ClangViewRefactor::get_identifier() { diff --git a/src/source_coverage.cpp b/src/source_coverage.cpp index 1eb2975..9c2afd7 100644 --- a/src/source_coverage.cpp +++ b/src/source_coverage.cpp @@ -1,4 +1,5 @@ #include "source_coverage.hpp" +#include "info.hpp" #include #include @@ -6,7 +7,22 @@ Source::CoverageView::Renderer::Renderer() : Gsv::GutterRendererText() { set_padding(4, 0); } -Source::CoverageView::CoverageView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), renderer(new Renderer()) {} +Source::CoverageView::CoverageView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), renderer(new Renderer()) { + get_coverage = [this]() { + auto build = Project::Build::create(this->file_path); + if(build->project_path.empty()) { + Info::get().print(this->file_path.filename().string() + ": could not find a supported build system"); + return std::vector{}; + } + build->update_default(); + + auto result = Coverage::analyze(*build, this->file_path, this->language_id); + if(result.empty()) { + Info::get().print(this->file_path.filename().string() + ": no supported coverage information found"); + } + return result; + }; +} Source::CoverageView::~CoverageView() { get_gutter(Gtk::TextWindowType::TEXT_WINDOW_LEFT)->remove(renderer.get());