diff --git a/src/source.cc b/src/source.cc index 8e14d87..56304b3 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1025,7 +1025,8 @@ void Source::ClangViewParse::init_parse() { } pos++; } - init_syntax_highlighting(buffer_map); + clang_tu = std::unique_ptr(new clang::TranslationUnit(clang_index, file_path.string(), get_compilation_commands(), buffer_map)); + clang_tokens=clang_tu->get_tokens(0, buffer_map.find(file_path.string())->second.size()-1); update_syntax(); set_status("parsing..."); @@ -1042,11 +1043,15 @@ void Source::ClangViewParse::init_parse() { parse_start(); } else if (parse_thread_mapped && parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) { - reparse(parse_thread_buffer_map); + int status=clang_tu->ReparseTranslationUnit(parse_thread_buffer_map); + if(status==0) + clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path.string())->second.size()-1); + else + parse_error=true; parse_thread_go=false; parsing_mutex.unlock(); parse_thread_buffer_map_mutex.unlock(); - if(parse_error) { + if(status!=0) { parse_fail(); parse_thread_stop=true; } @@ -1057,15 +1062,6 @@ void Source::ClangViewParse::init_parse() { }); } -void Source::ClangViewParse::init_syntax_highlighting(const std::map &buffers) { - std::vector arguments = get_compilation_commands(); - clang_tu = std::unique_ptr(new clang::TranslationUnit(clang_index, - file_path.string(), - arguments, - buffers)); - clang_tokens=clang_tu->get_tokens(0, buffers.find(file_path.string())->second.size()-1); -} - std::map Source::ClangViewParse::get_buffer_map() const { std::map buffer_map; buffer_map[file_path.string()]=get_source_buffer()->get_text(); @@ -1084,16 +1080,6 @@ void Source::ClangViewParse::start_reparse() { }, 1000); } -int Source::ClangViewParse::reparse(const std::map &buffer) { - int status = clang_tu->ReparseTranslationUnit(buffer); - if(status!=0) { - parse_error=true; - return status; - } - clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path.string())->second.size()-1); - return status; -} - std::vector Source::ClangViewParse::get_compilation_commands() { clang::CompilationDatabase db(project_path.string()); clang::CompileCommands commands(file_path.string(), db); diff --git a/src/source.h b/src/source.h index 4f46c54..6fb4a18 100644 --- a/src/source.h +++ b/src/source.h @@ -157,9 +157,6 @@ namespace Source { std::regex no_bracket_no_para_statement_regex; private: std::map get_buffer_map() const; - // inits the syntax highligthing on file open - void init_syntax_highlighting(const std::map &buffers); - int reparse(const std::map &buffers); void update_syntax(); std::set last_syntax_tags; void update_diagnostics();