Browse Source

Language protocol: made flow coverage asynchronous to speed up saving javascript files

merge-requests/393/head
eidheim 7 years ago
parent
commit
6934fb0790
  1. 53
      src/source_language_protocol.cc
  2. 4
      src/source_language_protocol.h

53
src/source_language_protocol.cc

@ -409,7 +409,7 @@ void Source::LanguageProtocolView::initialize(bool setup) {
initialize_thread = std::thread([this, setup] { initialize_thread = std::thread([this, setup] {
if(!flow_coverage_executable.empty()) if(!flow_coverage_executable.empty())
add_flow_coverage_tooltips(true); update_flow_coverage();
auto capabilities = client->initialize(this); auto capabilities = client->initialize(this);
@ -441,6 +441,9 @@ void Source::LanguageProtocolView::close() {
if(initialize_thread.joinable()) if(initialize_thread.joinable())
initialize_thread.join(); initialize_thread.join();
if(flow_coverage_thread.joinable())
flow_coverage_thread.join();
autocomplete.state = Autocomplete::State::IDLE; autocomplete.state = Autocomplete::State::IDLE;
if(autocomplete.thread.joinable()) if(autocomplete.thread.joinable())
autocomplete.thread.join(); autocomplete.thread.join();
@ -465,8 +468,19 @@ bool Source::LanguageProtocolView::save() {
if(!Source::View::save()) if(!Source::View::save())
return false; return false;
if(!flow_coverage_executable.empty()) if(!flow_coverage_executable.empty()) {
add_flow_coverage_tooltips(false); if(flow_coverage_thread.joinable())
flow_coverage_thread.join();
flow_coverage_cleared_diagnostic_tooltips = false;
for(auto &mark : flow_coverage_marks) {
get_buffer()->delete_mark(mark.first);
get_buffer()->delete_mark(mark.second);
}
flow_coverage_marks.clear();
flow_coverage_thread = std::thread([this] {
update_flow_coverage();
});
}
return true; return true;
} }
@ -917,8 +931,13 @@ void Source::LanguageProtocolView::escape_text(std::string &text) {
} }
void Source::LanguageProtocolView::update_diagnostics(std::vector<LanguageProtocol::Diagnostic> &&diagnostics) { void Source::LanguageProtocolView::update_diagnostics(std::vector<LanguageProtocol::Diagnostic> &&diagnostics) {
dispatcher.post([this, diagnostics = std::move(diagnostics)]() mutable { dispatcher.post([this, diagnostics = std::move(diagnostics)]() {
clear_diagnostic_tooltips(); diagnostic_offsets.clear();
diagnostic_tooltips.clear();
if(flow_coverage_executable.empty())
get_buffer()->remove_tag_by_name("def:warning_underline", get_buffer()->begin(), get_buffer()->end());
get_buffer()->remove_tag_by_name("def:error_underline", get_buffer()->begin(), get_buffer()->end());
flow_coverage_cleared_diagnostic_tooltips = true;
num_warnings = 0; num_warnings = 0;
num_errors = 0; num_errors = 0;
num_fix_its = 0; num_fix_its = 0;
@ -1476,18 +1495,20 @@ bool Source::LanguageProtocolView::has_named_parameters() {
return false; return false;
} }
void Source::LanguageProtocolView::add_flow_coverage_tooltips(bool called_in_thread) { void Source::LanguageProtocolView::update_flow_coverage() {
std::stringstream stdin_stream, stderr_stream; std::stringstream stdin_stream, stderr_stream;
auto stdout_stream = std::make_shared<std::stringstream>(); auto stdout_stream = std::make_shared<std::stringstream>();
auto exit_status = Terminal::get().process(stdin_stream, *stdout_stream, flow_coverage_executable.string() + " coverage --json " + file_path.string(), "", &stderr_stream); auto exit_status = Terminal::get().process(stdin_stream, *stdout_stream, flow_coverage_executable.string() + " coverage --json " + file_path.string(), "", &stderr_stream);
auto f = [this, exit_status, stdout_stream] {
clear_diagnostic_tooltips(); dispatcher.post([this, exit_status, stdout_stream] {
num_flow_coverage_warnings = 0; if(!flow_coverage_cleared_diagnostic_tooltips) {
for(auto &mark : flow_coverage_marks) { diagnostic_offsets.clear();
get_buffer()->delete_mark(mark.first); diagnostic_tooltips.clear();
get_buffer()->delete_mark(mark.second); get_buffer()->remove_tag_by_name("def:warning_underline", get_buffer()->begin(), get_buffer()->end());
flow_coverage_cleared_diagnostic_tooltips = true;
} }
flow_coverage_marks.clear();
num_flow_coverage_warnings = 0;
if(exit_status == 0) { if(exit_status == 0) {
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
@ -1514,9 +1535,5 @@ void Source::LanguageProtocolView::add_flow_coverage_tooltips(bool called_in_thr
status_diagnostics = std::make_tuple(num_warnings + num_flow_coverage_warnings, num_errors, num_fix_its); status_diagnostics = std::make_tuple(num_warnings + num_flow_coverage_warnings, num_errors, num_fix_its);
if(update_status_diagnostics) if(update_status_diagnostics)
update_status_diagnostics(this); update_status_diagnostics(this);
}; });
if(called_in_thread)
dispatcher.post(std::move(f));
else
f();
} }

4
src/source_language_protocol.h

@ -170,8 +170,10 @@ namespace Source {
bool has_named_parameters(); bool has_named_parameters();
boost::filesystem::path flow_coverage_executable; boost::filesystem::path flow_coverage_executable;
std::thread flow_coverage_thread;
bool flow_coverage_cleared_diagnostic_tooltips = false;
std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark>>> flow_coverage_marks; std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark>>> flow_coverage_marks;
size_t num_warnings = 0, num_errors = 0, num_fix_its = 0, num_flow_coverage_warnings = 0; size_t num_warnings = 0, num_errors = 0, num_fix_its = 0, num_flow_coverage_warnings = 0;
void add_flow_coverage_tooltips(bool called_in_thread); void update_flow_coverage();
}; };
} // namespace Source } // namespace Source

Loading…
Cancel
Save