Browse Source

Can now find warnings and errors through menu item: Go to next Diagnostic.

merge-requests/365/head
eidheim 10 years ago
parent
commit
1e903e5954
  1. 2
      src/files.h
  2. 3
      src/menu.cc
  3. 21
      src/source.cc
  4. 3
      src/source.h
  5. 7
      src/window.cc

2
src/files.h

@ -64,10 +64,10 @@ const std::string configjson =
" \"edit_find\": \"<primary>f\",\n"
" \"source_goto_line\": \"<primary>g\",\n"
" \"source_center_cursor\": \"<primary>l\",\n"
" \"source_cycle_diagnostics\": \"<primary>e\",\n"
" \"source_goto_declaration\": \"<primary>d\",\n"
" \"source_goto_method\": \"<primary>m\",\n"
" \"source_rename\": \"<primary>r\",\n"
" \"source_goto_next_diagnostic\": \"<primary>e\",\n"
" \"compile_and_run\": \"<primary>Return\",\n"
" \"compile\": \"<primary><shift>Return\",\n"
" \"run_command\": \"<alt>Return\",\n"

3
src/menu.cc

@ -51,6 +51,9 @@ Menu::Menu() {
" <menuitem action=\"SourceGotoDeclaration\"/>\n"
" <menuitem action=\"SourceGotoMethod\"/>\n"
" <menuitem action=\"SourceRename\"/>\n"
" <separator/>\n"
" <menuitem action=\"SourceGotoNextDiagnostic\"/>\n"
" <separator/>\n"
" </menu>\n"
" <menu action=\"ProjectMenu\">\n"
" <menuitem action=\"ProjectCompileAndRun\"/>\n"

21
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() {

3
src/source.h

@ -75,6 +75,7 @@ namespace Source {
std::function<std::string()> get_token_name;
std::function<void(const std::pair<std::string, int> &token)> tag_similar_tokens;
std::function<size_t(const std::pair<std::string, int> &token, const std::string &text)> rename_similar_tokens;
std::function<void()> goto_next_diagnostic;
std::function<void(View* view, const std::string &status)> on_update_status;
std::function<void(View* view, const std::string &info)> 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<int> diagnostic_offsets;
private:
std::map<std::string, std::string> get_buffer_map() const;
void update_syntax();

7
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)

Loading…
Cancel
Save