diff --git a/src/source_clang.cc b/src/source_clang.cc index 95581ed..d625696 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -540,34 +540,17 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa show_parameters = false; - std::string line = " " + get_line_before(); - const static std::regex dot_or_arrow(R"(^.*[a-zA-Z0-9_\)\]\>](\.|->)([a-zA-Z0-9_]*)$)"); - const static std::regex colon_colon(R"(^.*::([a-zA-Z0-9_]*)$)"); - const static std::regex part_of_symbol(R"(^.*[^a-zA-Z0-9_]+([a-zA-Z0-9_]{3,})$)"); + auto line = ' ' + get_line_before(); + const static std::regex regex("^.*([a-zA-Z_\\)\\]\\>]|[^a-zA-Z0-9_][a-zA-Z_][a-zA-Z0-9_]*)(\\.|->)([a-zA-Z0-9_]*)$|" // . or -> + "^.*(::)([a-zA-Z0-9_]*)$|" // :: + "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$"); // part of symbol std::smatch sm; - if(std::regex_match(line, sm, dot_or_arrow)) { + if(std::regex_match(line, sm, regex)) { { std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[2].str(); + autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str(); } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; - } - else if(std::regex_match(line, sm, colon_colon)) { - { - std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[1].str(); - } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; - } - else if(std::regex_match(line, sm, part_of_symbol)) { - { - std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[1].str(); - } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; + return true; } else if(is_possible_argument()) { show_parameters = true; diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index dcfbd05..5d0e497 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -1250,34 +1250,17 @@ void Source::LanguageProtocolView::setup_autocomplete() { autocomplete_show_parameters = false; - std::string line = " " + get_line_before(); - const static std::regex dot_or_arrow(R"(^.*[a-zA-Z0-9_\)\]\>"'](\.)([a-zA-Z0-9_]*)$)"); - const static std::regex colon_colon(R"(^.*::([a-zA-Z0-9_]*)$)"); - const static std::regex part_of_symbol(R"(^.*[^a-zA-Z0-9_]+([a-zA-Z0-9_]{3,})$)"); + auto line = ' ' + get_line_before(); + const static std::regex regex("^.*([a-zA-Z_\\)\\]\\>\"']|[^a-zA-Z0-9_][a-zA-Z_][a-zA-Z0-9_]*)(\\.)([a-zA-Z0-9_]*)$|" // . + "^.*(::)([a-zA-Z0-9_]*)$|" // :: + "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$"); // part of symbol std::smatch sm; - if(std::regex_match(line, sm, dot_or_arrow)) { + if(std::regex_match(line, sm, regex)) { { std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[2].str(); + autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str(); } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; - } - else if(std::regex_match(line, sm, colon_colon)) { - { - std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[1].str(); - } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; - } - else if(std::regex_match(line, sm, part_of_symbol)) { - { - std::unique_lock lock(autocomplete.prefix_mutex); - autocomplete.prefix = sm[1].str(); - } - if(autocomplete.prefix.size() == 0 || autocomplete.prefix[0] < '0' || autocomplete.prefix[0] > '9') - return true; + return true; } else if(is_possible_argument()) { autocomplete_show_parameters = true;