Browse Source

Faster clang processing on open file, adds a slight delay first time the next reparse is performed. This is more clean with respect to using precompiled header files in the future.

merge-requests/365/head
eidheim 10 years ago
parent
commit
d66edc824d
  1. 24
      src/source_clang.cc

24
src/source_clang.cc

@ -113,24 +113,6 @@ void Source::ClangViewParse::init_parse() {
parse_thread_mapped=false;
parse_thread_stop=false;
auto buffer_map=get_buffer_map();
//Remove includes for first parse for initial syntax highlighting
auto& str=buffer_map[file_path.string()];
std::size_t pos=0;
while((pos=str.find("#include", pos))!=std::string::npos) {
auto start_pos=pos;
pos=str.find('\n', pos+8);
if(pos==std::string::npos)
break;
if(start_pos==0 || str[start_pos-1]=='\n') {
str.replace(start_pos, pos-start_pos, pos-start_pos, ' ');
}
pos++;
}
clang_tu = std::unique_ptr<clang::TranslationUnit>(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...");
if(parse_thread.joinable())
parse_thread.join();
@ -145,7 +127,11 @@ void Source::ClangViewParse::init_parse() {
parse_start();
}
else if (parse_thread_mapped && parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) {
int status=clang_tu->ReparseTranslationUnit(parse_thread_buffer_map);
int status=0;
if(!clang_tu)
clang_tu = std::unique_ptr<clang::TranslationUnit>(new clang::TranslationUnit(clang_index, file_path.string(), get_compilation_commands(), parse_thread_buffer_map));
else
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

Loading…
Cancel
Save