Browse Source

Fixes #55 somehow. Stops clang-parse and autocomplete when error is detected.

merge-requests/365/head
eidheim 10 years ago
parent
commit
6d8fb734f6
  1. 2
      src/notebook.cc
  2. 21
      src/source.cc
  3. 1
      src/source.h

2
src/notebook.cc

@ -145,7 +145,7 @@ bool Notebook::save(int page, bool reparse_needed) {
if(source_clang_view->restart_parse()) if(source_clang_view->restart_parse())
Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n");
else else
Singleton::terminal()->async_print("Already reparsing "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); Singleton::terminal()->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n");
} }
} }
} }

21
src/source.cc

@ -980,6 +980,10 @@ Source::View(file_path), project_path(project_path) {
parse_thread_go=true; parse_thread_go=true;
} }
}); });
parse_fail.connect([this](){
Singleton::terminal()->print("Error: failed to reparse "+this->file_path.string()+".\n");
set_status("");
});
init_parse(); init_parse();
get_buffer()->signal_changed().connect([this]() { get_buffer()->signal_changed().connect([this]() {
@ -1006,7 +1010,6 @@ void Source::ClangViewParse::init_parse() {
parse_thread_mapped=false; parse_thread_mapped=false;
parse_thread_stop=false; parse_thread_stop=false;
auto buffer_map=get_buffer_map(); auto buffer_map=get_buffer_map();
//Remove includes for first parse for initial syntax highlighting //Remove includes for first parse for initial syntax highlighting
auto& str=buffer_map[file_path.string()]; auto& str=buffer_map[file_path.string()];
@ -1038,10 +1041,16 @@ void Source::ClangViewParse::init_parse() {
parse_start(); parse_start();
} }
else if (parse_thread_mapped && parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) { else if (parse_thread_mapped && parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) {
reparse(parse_thread_buffer_map); int status=reparse(parse_thread_buffer_map);
parse_thread_go=false; parse_thread_go=false;
if(status!=0)
parse_thread_stop=true;
parsing_mutex.unlock(); parsing_mutex.unlock();
parse_thread_buffer_map_mutex.unlock(); parse_thread_buffer_map_mutex.unlock();
if(status!=0) {
parse_fail();
return;
}
parse_done(); parse_done();
} }
} }
@ -1067,6 +1076,7 @@ void Source::ClangViewParse::start_reparse() {
parse_thread_mapped=false; parse_thread_mapped=false;
source_readable=false; source_readable=false;
delayed_reparse_connection.disconnect(); delayed_reparse_connection.disconnect();
if(!parse_thread_stop) {
delayed_reparse_connection=Glib::signal_timeout().connect([this]() { delayed_reparse_connection=Glib::signal_timeout().connect([this]() {
source_readable=false; source_readable=false;
parse_thread_go=true; parse_thread_go=true;
@ -1074,9 +1084,13 @@ void Source::ClangViewParse::start_reparse() {
return false; return false;
}, 1000); }, 1000);
} }
}
int Source::ClangViewParse::reparse(const std::map<std::string, std::string> &buffer) { int Source::ClangViewParse::reparse(const std::map<std::string, std::string> &buffer) {
int status = clang_tu->ReparseTranslationUnit(buffer); int status = clang_tu->ReparseTranslationUnit(buffer);
if(status!=0) {
return status;
}
clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path.string())->second.size()-1); clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path.string())->second.size()-1);
return status; return status;
} }
@ -1564,6 +1578,7 @@ void Source::ClangViewAutocomplete::autocomplete() {
autocomplete_thread.join(); autocomplete_thread.join();
autocomplete_thread=std::thread([this, ac_data, line_nr, column_nr, buffer_map](){ autocomplete_thread=std::thread([this, ac_data, line_nr, column_nr, buffer_map](){
parsing_mutex.lock(); parsing_mutex.lock();
if(!parse_thread_stop)
*ac_data=move(get_autocomplete_suggestions(line_nr, column_nr, *buffer_map)); *ac_data=move(get_autocomplete_suggestions(line_nr, column_nr, *buffer_map));
autocomplete_done(); autocomplete_done();
parsing_mutex.unlock(); parsing_mutex.unlock();
@ -1784,7 +1799,7 @@ void Source::ClangView::async_delete() {
} }
bool Source::ClangView::restart_parse() { bool Source::ClangView::restart_parse() {
if(!restart_parse_running) { if(!restart_parse_running && !parse_thread_stop) {
reparse_needed=false; reparse_needed=false;
restart_parse_running=true; restart_parse_running=true;
parse_thread_stop=true; parse_thread_stop=true;

1
src/source.h

@ -169,6 +169,7 @@ namespace Source {
Glib::Dispatcher parse_done; Glib::Dispatcher parse_done;
Glib::Dispatcher parse_start; Glib::Dispatcher parse_start;
Glib::Dispatcher parse_fail;
std::map<std::string, std::string> parse_thread_buffer_map; std::map<std::string, std::string> parse_thread_buffer_map;
std::mutex parse_thread_buffer_map_mutex; std::mutex parse_thread_buffer_map_mutex;
std::atomic<bool> parse_thread_go; std::atomic<bool> parse_thread_go;

Loading…
Cancel
Save