Browse Source

Ongoing work: Find Documentation.

merge-requests/365/head
eidheim 10 years ago
parent
commit
0307801336
  1. 9
      src/config.cc
  2. 13
      src/files.h
  3. 2
      src/menu.cc
  4. 83
      src/source.cc
  5. 9
      src/source.h
  6. 37
      src/window.cc

9
src/config.cc

@ -134,6 +134,15 @@ void MainConfig::GenerateSource() {
for (auto &i : source_json.get_child("clang_types")) for (auto &i : source_json.get_child("clang_types"))
source_cfg->clang_types[i.first] = i.second.get_value<std::string>(); source_cfg->clang_types[i.first] = i.second.get_value<std::string>();
auto pt_doc_search=cfg.get_child("documentation_searches");
for(auto &pt_doc_search_lang: pt_doc_search) {
source_cfg->documentation_searches[pt_doc_search_lang.first].separator=pt_doc_search_lang.second.get<std::string>("separator");
auto &queries=source_cfg->documentation_searches.find(pt_doc_search_lang.first)->second.queries;
for(auto &i: pt_doc_search_lang.second.get_child("queries")) {
queries[i.first]=i.second.get_value<std::string>();
}
}
} }
void MainConfig::GenerateDirectoryFilter() { void MainConfig::GenerateDirectoryFilter() {

13
src/files.h

@ -73,6 +73,7 @@ const std::string configjson =
" \"source_goto_declaration\": \"<primary>d\",\n" " \"source_goto_declaration\": \"<primary>d\",\n"
" \"source_goto_method\": \"<primary>m\",\n" " \"source_goto_method\": \"<primary>m\",\n"
" \"source_rename\": \"<primary>r\",\n" " \"source_rename\": \"<primary>r\",\n"
" \"source_find_documentation\": \"<primary><shift>d\",\n"
" \"source_goto_next_diagnostic\": \"<primary>e\",\n" " \"source_goto_next_diagnostic\": \"<primary>e\",\n"
" \"source_apply_fix_its\": \"<control>space\",\n" " \"source_apply_fix_its\": \"<control>space\",\n"
" \"compile_and_run\": \"<primary>Return\",\n" " \"compile_and_run\": \"<primary>Return\",\n"
@ -92,6 +93,18 @@ const std::string configjson =
#endif #endif
" \"make_command\": \"make\"\n" " \"make_command\": \"make\"\n"
" },\n" " },\n"
" \"documentation_searches\": {\n"
" \"clang\": {\n"
" \"separator\": \"::\",\n"
" \"queries\": {\n"
" \"@empty\": \"https://www.google.com/search?btnI&q=site:http://www.cplusplus.com/reference/+\",\n"
" \"std\": \"https://www.google.com/search?btnI&q=site:http://www.cplusplus.com/reference/+\",\n"
" \"boost\": \"https://www.google.com/search?btnI&q=site:http://www.boost.org/doc/libs/1_59_0/+\",\n"
" \"Gtk\": \"https://www.google.com/search?btnI&q=site:https://developer.gnome.org/gtkmm/stable/+\",\n"
" \"@any\": \"https://www.google.com/search?btnI&q=\"\n"
" }\n"
" }\n"
" },\n"
" \"directoryfilter\": {\n" " \"directoryfilter\": {\n"
" \"ignore\": [\n" " \"ignore\": [\n"
" ],\n" " ],\n"

2
src/menu.cc

@ -54,6 +54,8 @@ Menu::Menu() {
" <menuitem action=\"SourceGotoLine\"/>\n" " <menuitem action=\"SourceGotoLine\"/>\n"
" <menuitem action=\"SourceCenterCursor\"/>\n" " <menuitem action=\"SourceCenterCursor\"/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action=\"SourceFindDocumentation\"/>\n"
" <separator/>\n"
" <menuitem action=\"SourceGotoDeclaration\"/>\n" " <menuitem action=\"SourceGotoDeclaration\"/>\n"
" <menuitem action=\"SourceGotoMethod\"/>\n" " <menuitem action=\"SourceGotoMethod\"/>\n"
" <menuitem action=\"SourceRename\"/>\n" " <menuitem action=\"SourceRename\"/>\n"

83
src/source.cc

@ -2345,6 +2345,89 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
} }
}; };
get_token_data=[this]() {
const auto find_non_word_char=[](const std::string &str, size_t start_pos) {
for(size_t c=start_pos;c<str.size();c++) {
if(!((str[c]>='a' && str[c]<='z') ||
(str[c]>='A' && str[c]<='Z') ||
(str[c]>='0' && str[c]<='9') ||
str[c]=='_'))
return c;
}
return std::string::npos;
};
std::vector<std::string> data;
if(source_readable) {
auto iter=get_buffer()->get_insert()->get_iter();
auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) {
auto cursor=token.get_cursor();
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto referenced=cursor.get_referenced();
if(referenced) {
auto usr=referenced.get_usr();
data.emplace_back("clang");
//namespace - not working
size_t pos1=usr.find("@N@");
size_t pos2;
std::string first_namespace;
while(pos1!=std::string::npos) {
pos1+=3;
pos2=find_non_word_char(usr, pos1);
if(pos1!=std::string::npos && pos2!=std::string::npos) {
auto ns=usr.substr(pos1, pos2-pos1);
if(first_namespace.size()==0)
first_namespace=ns;
else if(ns==first_namespace || ns=="std")
break;
data.emplace_back(ns);
pos1=usr.find("@N@", pos2);
}
else
pos1=std::string::npos;
}
//type
pos1=usr.find("@T@");
if(pos1==std::string::npos)
pos1=usr.find("@S@");
if(pos1!=std::string::npos) {
pos1+=3;
pos2=find_non_word_char(usr, pos1);
}
if(pos1!=std::string::npos) {
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else
data.emplace_back(usr.substr(pos1));
}
//function
pos1=usr.find("@F@");
if(pos1!=std::string::npos) {
pos1+=3;
pos2=find_non_word_char(usr, pos1);
}
if(pos1!=std::string::npos) {
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else
data.emplace_back(usr.substr(pos1));
}
break;
}
}
}
}
}
return data;
};
goto_next_diagnostic=[this]() { goto_next_diagnostic=[this]() {
if(source_readable) { if(source_readable) {
auto insert_offset=get_buffer()->get_insert()->get_iter().get_offset(); auto insert_offset=get_buffer()->get_insert()->get_iter().get_offset();

9
src/source.h

@ -23,6 +23,12 @@ namespace Source {
class Config { class Config {
public: public:
class DocumentationSearch {
public:
std::string separator;
std::unordered_map<std::string, std::string> queries;
};
std::string style; std::string style;
std::string font; std::string font;
std::string spellcheck_language; std::string spellcheck_language;
@ -37,6 +43,8 @@ namespace Source {
bool highlight_current_line; bool highlight_current_line;
bool show_line_numbers; bool show_line_numbers;
std::unordered_map<std::string, std::string> clang_types; std::unordered_map<std::string, std::string> clang_types;
std::unordered_map<std::string, DocumentationSearch> documentation_searches;
}; };
class Token { class Token {
@ -104,6 +112,7 @@ namespace Source {
std::function<std::pair<std::string, clang::Offset>()> get_declaration_location; std::function<std::pair<std::string, clang::Offset>()> get_declaration_location;
std::function<void()> goto_method; std::function<void()> goto_method;
std::function<Token()> get_token; std::function<Token()> get_token;
std::function<std::vector<std::string>()> get_token_data;
std::function<size_t(const Token &token, const std::string &text)> rename_similar_tokens; std::function<size_t(const Token &token, const std::string &text)> rename_similar_tokens;
std::function<void()> goto_next_diagnostic; std::function<void()> goto_next_diagnostic;
std::function<void()> apply_fix_its; std::function<void()> apply_fix_its;

37
src/window.cc

@ -117,7 +117,10 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
menu_item->set_sensitive((bool)notebook.get_current_view()->goto_next_diagnostic); menu_item->set_sensitive((bool)notebook.get_current_view()->goto_next_diagnostic);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceApplyFixIts"))) if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceApplyFixIts")))
menu_item->set_sensitive((bool)notebook.get_current_view()->apply_fix_its); menu_item->set_sensitive((bool)notebook.get_current_view()->apply_fix_its);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceFindDocumentation")))
menu_item->set_sensitive((bool)notebook.get_current_view()->get_token_data);
directories.select(notebook.get_current_view()->file_path); directories.select(notebook.get_current_view()->file_path);
@ -296,6 +299,38 @@ void Window::create_menu() {
menu.action_group->add(Gtk::Action::create("SourceRename", "Rename"), Gtk::AccelKey(menu.key_map["source_rename"]), [this]() { menu.action_group->add(Gtk::Action::create("SourceRename", "Rename"), Gtk::AccelKey(menu.key_map["source_rename"]), [this]() {
rename_token_entry(); rename_token_entry();
}); });
menu.action_group->add(Gtk::Action::create("SourceFindDocumentation", "Find Documentation"), Gtk::AccelKey(menu.key_map["source_find_documentation"]), [this]() {
if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_token_data) {
auto data=notebook.get_current_view()->get_token_data();
if(data.size()>0) {
auto documentation_search=Singleton::Config::source()->documentation_searches.find(data[0]);
if(documentation_search!=Singleton::Config::source()->documentation_searches.end()) {
std::string token_query;
for(size_t c=1;c<data.size();c++) {
if(data[c].size()>0) {
if(token_query.size()>0)
token_query+=documentation_search->second.separator;
token_query+=data[c];
}
}
if(token_query.size()>0) {
std::unordered_map<std::string, std::string>::iterator query;
if(data[1].size()>0)
query=documentation_search->second.queries.find(data[1]);
else
query=documentation_search->second.queries.find("@empty");
if(query==documentation_search->second.queries.end())
query=documentation_search->second.queries.find("@any");
if(query!=documentation_search->second.queries.end())
Singleton::terminal()->execute("open \""+query->second+token_query+"\"");
}
}
}
}
}
});
menu.action_group->add(Gtk::Action::create("SourceGotoNextDiagnostic", "Go to next Diagnostic"), Gtk::AccelKey(menu.key_map["source_goto_next_diagnostic"]), [this]() { menu.action_group->add(Gtk::Action::create("SourceGotoNextDiagnostic", "Go to next Diagnostic"), Gtk::AccelKey(menu.key_map["source_goto_next_diagnostic"]), [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_next_diagnostic) { if(notebook.get_current_view()->goto_next_diagnostic) {

Loading…
Cancel
Save