diff --git a/src/ctags.cc b/src/ctags.cc index f0b4fc0..c251b0d 100644 --- a/src/ctags.cc +++ b/src/ctags.cc @@ -7,6 +7,7 @@ #include #include #include +#include std::pair > Ctags::get_result(const boost::filesystem::path &path) { auto build=Project::Build::create(path); @@ -103,64 +104,108 @@ Ctags::Location Ctags::get_location(const std::string &line, bool markup) { return location; } -std::vector Ctags::get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type) { - //insert name into type - size_t c=0; - size_t bracket_count=0; - for(;c') - --bracket_count; - else if(bracket_count==0 && type[c]=='(') - break; - } - auto full_type=type; - full_type.insert(c, name); - - //Split up full_type +///Split up a type into its various significant parts +std::vector Ctags::get_type_parts(const std::string type) { std::vector parts; size_t text_start=-1; - for(size_t c=0;c='0' && chr<='9') || (chr>='a' && chr<='z') || (chr>='A' && chr<='Z') || chr=='_' || chr=='~') { if(text_start==static_cast(-1)) text_start=c; } else { - if(text_start!=static_cast(-1)) - parts.emplace_back(full_type.substr(text_start, c-text_start)); - text_start=-1; + if(text_start!=static_cast(-1)) { + parts.emplace_back(type.substr(text_start, c-text_start)); + text_start=-1; + } if(chr=='*' || chr=='&') parts.emplace_back(std::string()+chr); } } - + return parts; +} + +std::vector Ctags::get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type) { auto result=get_result(path); result.second->seekg(0, std::ios::end); if(result.second->tellg()==0) return std::vector(); result.second->seekg(0, std::ios::beg); + //insert name into type + size_t c=0; + size_t bracket_count=0; + for(;c') + --bracket_count; + else if(bracket_count==0 && type[c]=='(') + break; + } + auto full_type=type; + full_type.insert(c, name); + + auto parts=get_type_parts(full_type); + + //Get short name + std::string short_name; + auto pos=name.rfind(':'); + if(pos!=std::string::npos && pos+1 best_locations; while(std::getline(*result.second, line)) { - if(line.find(name)==std::string::npos) + //Find function name + auto pos=line.find('\t'); + if(pos==std::string::npos) + continue; + auto line_function_name=line.substr(0, pos); + + if(line_function_name!=short_name || line.find(name)==std::string::npos) continue; + auto location=Ctags::get_location(line, false); location.file_path=result.first/location.file_path; + auto source_parts=get_type_parts(location.source); + //Find match score - size_t score=0; - size_t pos=0; + long score=0; + size_t source_index=0; for(auto &part: parts) { - auto find_pos=location.source.find(part, pos); - if(find_pos!=std::string::npos) { - pos=find_pos+1; - ++score; + bool found=false; + for(auto c=source_index;cbest_score) { best_score=score; best_locations.clear(); diff --git a/src/ctags.h b/src/ctags.h index c3c821f..1ffce61 100644 --- a/src/ctags.h +++ b/src/ctags.h @@ -21,6 +21,8 @@ public: static Location get_location(const std::string &line, bool markup); static std::vector get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type); +private: + static std::vector get_type_parts(const std::string type); }; #endif //JUCI_CTAGS_H_