diff --git a/src/files.h b/src/files.h index 629d862..67fc65d 100644 --- a/src/files.h +++ b/src/files.h @@ -64,10 +64,10 @@ const std::string configjson = " \"edit_find\": \"f\",\n" " \"source_goto_line\": \"g\",\n" " \"source_center_cursor\": \"l\",\n" -" \"source_cycle_diagnostics\": \"e\",\n" " \"source_goto_declaration\": \"d\",\n" " \"source_goto_method\": \"m\",\n" " \"source_rename\": \"r\",\n" +" \"source_goto_next_diagnostic\": \"e\",\n" " \"compile_and_run\": \"Return\",\n" " \"compile\": \"Return\",\n" " \"run_command\": \"Return\",\n" diff --git a/src/menu.cc b/src/menu.cc index e1b27da..0a66e34 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -51,6 +51,9 @@ Menu::Menu() { " \n" " \n" " \n" + " \n" + " \n" + " \n" " \n" " \n" " \n" diff --git a/src/source.cc b/src/source.cc index 05ec290..a29f8f5 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1287,6 +1287,7 @@ void Source::ClangViewParse::update_syntax() { } void Source::ClangViewParse::update_diagnostics() { + diagnostic_offsets.clear(); diagnostic_tooltips.clear(); get_buffer()->remove_tag_by_name("def:warning_underline", get_buffer()->begin(), get_buffer()->end()); get_buffer()->remove_tag_by_name("def:error_underline", get_buffer()->begin(), get_buffer()->end()); @@ -1312,6 +1313,7 @@ void Source::ClangViewParse::update_diagnostics() { end_line_index=end_line.size(); } auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, start_line_index); + diagnostic_offsets.emplace(start.get_offset()); auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, end_line_index); std::string diagnostic_tag_name; if(diagnostic.severity<=CXDiagnostic_Warning) { @@ -1975,7 +1977,6 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { (*rows)[method.first]=method.second; selection_dialog->add_row(method.first); } - //TODO see if rows gets destroyed when selection_dialog gets destroyed. selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) { auto offset=rows->at(selected); get_buffer()->place_cursor(get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); @@ -1985,6 +1986,24 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { selection_dialog->show(); } }; + + goto_next_diagnostic=[this]() { + if(source_readable) { + auto insert_offset=get_buffer()->get_insert()->get_iter().get_offset(); + for(auto offset: diagnostic_offsets) { + if(offset>insert_offset) { + get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset)); + scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); + return; + } + } + if(diagnostic_offsets.size()>0) { + auto iter=get_buffer()->get_iter_at_offset(*diagnostic_offsets.begin()); + get_buffer()->place_cursor(iter); + scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); + } + } + }; } Source::ClangViewRefactor::~ClangViewRefactor() { diff --git a/src/source.h b/src/source.h index 2cb0264..b60c3fc 100644 --- a/src/source.h +++ b/src/source.h @@ -75,6 +75,7 @@ namespace Source { std::function get_token_name; std::function &token)> tag_similar_tokens; std::function &token, const std::string &text)> rename_similar_tokens; + std::function goto_next_diagnostic; std::function on_update_status; std::function on_update_info; @@ -167,6 +168,8 @@ namespace Source { std::regex bracket_regex; std::regex no_bracket_statement_regex; std::regex no_bracket_no_para_statement_regex; + + std::set diagnostic_offsets; private: std::map get_buffer_map() const; void update_syntax(); diff --git a/src/window.cc b/src/window.cc index a4c0c4c..1ff51fe 100644 --- a/src/window.cc +++ b/src/window.cc @@ -267,6 +267,13 @@ void Window::create_menu() { menu.action_group->add(Gtk::Action::create("SourceRename", "Rename"), Gtk::AccelKey(menu.key_map["source_rename"]), [this]() { rename_token_entry(); }); + 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_view()->goto_next_diagnostic) { + notebook.get_current_view()->goto_next_diagnostic(); + } + } + }); menu.action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile and Run"), Gtk::AccelKey(menu.key_map["compile_and_run"]), [this]() { if(notebook.get_current_page()==-1 || compiling)