Browse Source

Improved goto declaration

merge-requests/365/head
eidheim 10 years ago
parent
commit
0d2b93b1e1
  1. 2
      src/source.h
  2. 44
      src/source_clang.cc
  3. 2
      src/window.cc

2
src/source.h

@ -73,7 +73,7 @@ namespace Source {
Glib::RefPtr<Gsv::Language> language;
std::function<void()> auto_indent;
std::function<Offset()> get_declaration_location;
std::function<Offset(const std::vector<Source::View*> &views)> get_declaration_location;
std::function<Offset(const std::vector<Source::View*> &views)> get_implementation_location;
std::function<std::vector<std::pair<Offset, std::string> >(const std::vector<Source::View*> &views)> get_usages;
std::function<void()> goto_method;

44
src/source_clang.cc

@ -965,11 +965,10 @@ Source::ClangViewAutocomplete(file_path, language) {
}
});
get_declaration_location=[this](){
Offset location;
get_declaration_location=[this](const std::vector<Source::View*> &views){
if(!parsed) {
Info::get().print("Buffer is parsing");
return location;
return Offset();
}
auto iter=get_buffer()->get_insert()->get_iter();
auto line=static_cast<unsigned>(iter.get_line());
@ -980,16 +979,43 @@ Source::ClangViewAutocomplete(file_path, language) {
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) {
location.file_path=referenced.get_source_location().get_path();
auto clang_offset=referenced.get_source_location().get_offset();
location.line=clang_offset.line;
location.index=clang_offset.index;
break;
auto file_path=referenced.get_source_location().get_path();
//if declaration is implementation instead, attempt to find declaration
if(file_path==this->file_path && this->language && this->language->get_id()!="chdr" && this->language->get_id()!="cpphdr") {
auto identifier=Identifier(referenced.get_kind(), token.get_spelling(), referenced.get_usr());
std::vector<Source::View*> search_views;
for(auto &view: views) {
if(view->language && (view->language->get_id()=="chdr" || view->language->get_id()=="cpphdr"))
search_views.emplace_back(view);
}
search_views.emplace_back(this);
wait_parsing(search_views);
for(auto &view: search_views) {
if(auto clang_view=dynamic_cast<Source::ClangView*>(view)) {
for(auto &token: *clang_view->clang_tokens) {
auto cursor=token.get_cursor();
if(token.get_kind()==clang::TokenKind::Token_Identifier && cursor.has_type()) {
auto referenced=cursor.get_referenced();
if(referenced && identifier.kind==referenced.get_kind() &&
identifier.spelling==token.get_spelling() && identifier.usr==referenced.get_usr()) {
auto offset=referenced.get_source_location().get_offset();
return Offset(offset.line, offset.index, referenced.get_source_location().get_path());
}
}
}
}
}
}
auto offset=referenced.get_source_location().get_offset();
return Offset(offset.line, offset.index, file_path);
}
}
}
}
return location;
return Offset();
};
get_implementation_location=[this](const std::vector<Source::View*> &views){

2
src/window.cc

@ -435,7 +435,7 @@ void Window::set_menu_actions() {
menu.add_action("source_goto_declaration", [this]() {
if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_declaration_location) {
auto location=notebook.get_current_view()->get_declaration_location();
auto location=notebook.get_current_view()->get_declaration_location(notebook.source_views);
if(location) {
boost::filesystem::path declaration_file;
boost::system::error_code ec;

Loading…
Cancel
Save