From 4c8695c8fc84d4eabcd5d788e0d3e6fea5bb0753 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 21 Dec 2017 12:21:36 +0100 Subject: [PATCH] Added menu item Source->Go to Type Declaration --- CMakeLists.txt | 2 +- libclangmm | 2 +- src/files.h | 1 + src/menu.cc | 8 ++++++++ src/source.h | 1 + src/source_clang.cc | 21 +++++++++++++++++++++ src/window.cc | 18 ++++++++++++++++++ 7 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5995753..03bf0c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.3.2.1") +set(JUCI_VERSION "1.3.2.2") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/libclangmm b/libclangmm index 8c3f78e..979a596 160000 --- a/libclangmm +++ b/libclangmm @@ -1 +1 @@ -Subproject commit 8c3f78eb20fd2a5d56791d293bcaddab35cd1ed1 +Subproject commit 979a59647aac885049682479d31fcd2a94b3cf17 diff --git a/src/files.h b/src/files.h index 6a370f8..696fb60 100644 --- a/src/files.h +++ b/src/files.h @@ -124,6 +124,7 @@ R"RAW( "source_comments_add_documentation": "slash", "source_find_documentation": "d", "source_goto_declaration": "d", + "source_goto_type_declaration": "d", "source_goto_implementation": "i", "source_goto_usage": "u", "source_goto_method": "m", diff --git a/src/menu.cc b/src/menu.cc index 61b39b6..e328676 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -32,6 +32,10 @@ const Glib::ustring menu_xml= R"RAW( _Go _to _Declaration app.source_goto_declaration + + _Go _to _Type _Declaration + app.source_goto_type_declaration + _Go _to _Implementation app.source_goto_implementation @@ -293,6 +297,10 @@ const Glib::ustring menu_xml= R"RAW( _Go to Declaration app.source_goto_declaration + + _Go to _Type _Declaration + app.source_goto_type_declaration + _Go to Implementation app.source_goto_implementation diff --git a/src/source.h b/src/source.h index 16fe8a4..f5ad575 100644 --- a/src/source.h +++ b/src/source.h @@ -70,6 +70,7 @@ namespace Source { std::function non_interactive_completion; std::function format_style; std::function get_declaration_location; + std::function get_type_declaration_location; std::function()> get_implementation_locations; std::function()> get_declaration_or_implementation_locations; std::function >()> get_usages; diff --git a/src/source_clang.cc b/src/source_clang.cc index 9858648..7873f4f 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1062,6 +1062,27 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file return offset; }; + get_type_declaration_location=[this](){ + if(!parsed) { + Info::get().print("Buffer is parsing"); + return Offset(); + } + auto identifier=get_identifier(); + if(identifier) { + auto type_cursor=identifier.cursor.get_type().get_cursor(); + if(type_cursor) { + auto source_location=type_cursor.get_source_location(); + auto path=source_location.get_path(); + if(!path.empty()) { + auto location_offset=source_location.get_offset(); + return Offset(location_offset.line-1, location_offset.index-1, path); + } + } + } + Info::get().print("No type declaration found"); + return Offset(); + }; + auto implementation_locations=[this](const Identifier &identifier) { std::vector offsets; if(identifier) { diff --git a/src/window.cc b/src/window.cc index a79ff4f..f41ec8c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -827,6 +827,23 @@ void Window::set_menu_actions() { } } }); + menu.add_action("source_goto_type_declaration", [this]() { + if(auto view=Notebook::get().get_current_view()) { + if(view->get_type_declaration_location) { + auto location=view->get_type_declaration_location(); + if(location) { + if(!boost::filesystem::is_regular_file(location.file_path)) + return; + Notebook::get().open(location.file_path); + auto view=Notebook::get().get_current_view(); + auto line=static_cast(location.line); + auto index=static_cast(location.index); + view->place_cursor_at_line_index(line, index); + view->scroll_to_cursor_delayed(view, true, false); + } + } + } + }); auto goto_selected_location=[](Source::View *view, const std::vector &locations) { if(!locations.empty()) { auto dialog_iter=view->get_iter_for_dialog(); @@ -1306,6 +1323,7 @@ void Window::activate_menu_items() { menu.actions["source_comments_add_documentation"]->set_enabled(view && view->get_documentation_template); menu.actions["source_find_documentation"]->set_enabled(view && view->get_token_data); menu.actions["source_goto_declaration"]->set_enabled(view && view->get_declaration_location); + menu.actions["source_goto_type_declaration"]->set_enabled(view && view->get_type_declaration_location); menu.actions["source_goto_implementation"]->set_enabled(view && view->get_implementation_locations); menu.actions["source_goto_declaration_or_implementation"]->set_enabled(view && view->get_declaration_or_implementation_locations); menu.actions["source_goto_usage"]->set_enabled(view && view->get_usages);