From 29fc893a100974f4b0a8ff1cf3da614789287e7a Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 7 Jun 2016 10:59:34 +0200 Subject: [PATCH] Offset cleanup --- src/project.cc | 8 ++++---- src/source.cc | 14 +++++++------- src/source_clang.cc | 21 ++++++++++----------- src/window.cc | 26 +++++++++++++------------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/project.cc b/src/project.cc index 647ec68..a8e898b 100644 --- a/src/project.cc +++ b/src/project.cc @@ -96,8 +96,8 @@ void Project::debug_update_stop() { for(size_t c=0;cfile_path==debug_stop.first) { - if(debug_stop.second.first-1get_buffer()->get_line_count()) { - view->get_source_buffer()->create_source_mark("debug_stop", view->get_buffer()->get_iter_at_line(debug_stop.second.first-1)); + if(debug_stop.second.firstget_buffer()->get_line_count()) { + view->get_source_buffer()->create_source_mark("debug_stop", view->get_buffer()->get_iter_at_line(debug_stop.second.first)); debug_last_stop_file_path=debug_stop.first; } break; @@ -323,8 +323,8 @@ void Project::Clang::debug_start() { }, [this](const boost::filesystem::path &file_path, int line_nr, int line_index) { dispatcher.post([this, file_path, line_nr, line_index] { Project::debug_stop.first=file_path; - Project::debug_stop.second.first=line_nr; - Project::debug_stop.second.second=line_index; + Project::debug_stop.second.first=line_nr-1; + Project::debug_stop.second.second=line_index-1; debug_update_stop(); if(auto view=Notebook::get().get_current_view()) diff --git a/src/source.cc b/src/source.cc index ae9f1ef..0a41a9a 100644 --- a/src/source.cc +++ b/src/source.cc @@ -56,26 +56,26 @@ Source::FixIt::FixIt(const std::string &source, const std::pair } std::string Source::FixIt::string(Glib::RefPtr buffer) { - auto iter=buffer->get_iter_at_line_index(offsets.first.line-1, offsets.first.index-1); + auto iter=buffer->get_iter_at_line_index(offsets.first.line, offsets.first.index); unsigned first_line_offset=iter.get_line_offset()+1; - iter=buffer->get_iter_at_line_index(offsets.second.line-1, offsets.second.index-1); + iter=buffer->get_iter_at_line_index(offsets.second.line, offsets.second.index); unsigned second_line_offset=iter.get_line_offset()+1; std::string text; if(type==Type::INSERT) { text+="Insert "+source+" at "; - text+=std::to_string(offsets.first.line)+":"+std::to_string(first_line_offset); + text+=std::to_string(offsets.first.line+1)+":"+std::to_string(first_line_offset); } else if(type==Type::REPLACE) { text+="Replace "; - text+=std::to_string(offsets.first.line)+":"+std::to_string(first_line_offset)+" - "; - text+=std::to_string(offsets.second.line)+":"+std::to_string(second_line_offset); + text+=std::to_string(offsets.first.line+1)+":"+std::to_string(first_line_offset)+" - "; + text+=std::to_string(offsets.second.line+1)+":"+std::to_string(second_line_offset); text+=" with "+source; } else { text+="Erase "; - text+=std::to_string(offsets.first.line)+":"+std::to_string(first_line_offset)+" - "; - text+=std::to_string(offsets.second.line)+":"+std::to_string(second_line_offset); + text+=std::to_string(offsets.first.line+1)+":"+std::to_string(first_line_offset)+" - "; + text+=std::to_string(offsets.second.line+1)+":"+std::to_string(second_line_offset); } return text; diff --git a/src/source_clang.cc b/src/source_clang.cc index 2482016..4cedc66 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -313,13 +313,12 @@ void Source::ClangViewParse::update_diagnostics() { std::string fix_its_string; unsigned fix_its_count=0; for(auto &fix_it: diagnostic.fix_its) { - //Convert line index to line offset for correct output: auto clang_offsets=fix_it.offsets; std::pair offsets; - offsets.first.line=clang_offsets.first.line; - offsets.first.index=clang_offsets.first.index; - offsets.second.line=clang_offsets.second.line; - offsets.second.index=clang_offsets.second.index; + offsets.first.line=clang_offsets.first.line-1; + offsets.first.index=clang_offsets.first.index-1; + offsets.second.line=clang_offsets.second.line-1; + offsets.second.index=clang_offsets.second.index-1; fix_its.emplace_back(fix_it.source, offsets); @@ -999,7 +998,7 @@ Source::ClangViewAutocomplete(file_path, language) { 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()); + return Offset(offset.line-1, offset.index-1, referenced.get_source_location().get_path()); } } } @@ -1008,7 +1007,7 @@ Source::ClangViewAutocomplete(file_path, language) { } auto offset=referenced.get_source_location().get_offset(); - return Offset(offset.line, offset.index, file_path); + return Offset(offset.line-1, offset.index-1, file_path); } } } @@ -1039,8 +1038,8 @@ Source::ClangViewAutocomplete(file_path, language) { identifier.spelling==token_it->get_spelling() && identifier.usr==referenced.get_usr()) { location.file_path=cursor.get_source_location().get_path(); auto clang_offset=cursor.get_source_location().get_offset(); - location.line=clang_offset.line; - location.index=clang_offset.index; + location.line=clang_offset.line-1; + location.index=clang_offset.index-1; return location; } } @@ -1101,7 +1100,7 @@ Source::ClangViewAutocomplete(file_path, language) { } line.insert(token_end_pos, ""); line.insert(token_start_pos, ""); - usages.emplace_back(Offset(offset.first.line, offset.first.index, clang_view->file_path), line); + usages.emplace_back(Offset(offset.first.line-1, offset.first.index-1, clang_view->file_path), line); } } } @@ -1147,7 +1146,7 @@ Source::ClangViewAutocomplete(file_path, language) { (row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0); row.insert(token_end_pos, ""); row.insert(pos+1, ""); - methods.emplace_back(Offset(method.second.line, method.second.index), row); + methods.emplace_back(Offset(method.second.line-1, method.second.index-1), row); } return methods; }; diff --git a/src/window.cc b/src/window.cc index 5e027cb..36de2d4 100644 --- a/src/window.cc +++ b/src/window.cc @@ -459,8 +459,8 @@ void Window::set_menu_actions() { return; Notebook::get().open(declaration_file); auto view=Notebook::get().get_current_view(); - auto line=static_cast(location.line)-1; - auto index=static_cast(location.index)-1; + 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); } @@ -479,8 +479,8 @@ void Window::set_menu_actions() { return; Notebook::get().open(implementation_path); auto view=Notebook::get().get_current_view(); - auto line=static_cast(location.line)-1; - auto index=static_cast(location.index)-1; + 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); return; @@ -507,13 +507,13 @@ void Window::set_menu_actions() { row=usage.first.file_path.filename().string()+":"; current_page=false; } - row+=std::to_string(usage.first.line)+": "+usage.second; + row+=std::to_string(usage.first.line+1)+": "+usage.second; (*rows)[row]=usage.first; view->selection_dialog->add_row(row); //Set dialog cursor to the last row if the textview cursor is at the same line if(current_page && - iter.get_line()==static_cast(usage.first.line-1) && iter.get_line_index()>=static_cast(usage.first.index-1)) { + iter.get_line()==static_cast(usage.first.line) && iter.get_line_index()>=static_cast(usage.first.index)) { view->selection_dialog->set_cursor_at_last_row(); } } @@ -529,7 +529,7 @@ void Window::set_menu_actions() { return; Notebook::get().open(declaration_file); auto view=Notebook::get().get_current_view(); - view->place_cursor_at_line_index(offset.line-1, offset.index-1); + view->place_cursor_at_line_index(offset.line, offset.index); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->hide_tooltips(); }; @@ -551,12 +551,12 @@ void Window::set_menu_actions() { for(auto &method: methods) { (*rows)[method.second]=method.first; view->selection_dialog->add_row(method.second); - if(iter.get_line()>=static_cast(method.first.line-1)) + if(iter.get_line()>=static_cast(method.first.line)) view->selection_dialog->set_cursor_at_last_row(); } view->selection_dialog->on_select=[view, rows](const std::string& selected, bool hide_window) { auto offset=rows->at(selected); - view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); + view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(offset.line, offset.index)); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->hide_tooltips(); }; @@ -584,8 +584,8 @@ void Window::set_menu_actions() { auto fix_its=view->get_fix_its(); std::vector, Glib::RefPtr > > fix_it_marks; for(auto &fix_it: fix_its) { - auto start_iter=buffer->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1); - auto end_iter=buffer->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1); + auto start_iter=buffer->get_iter_at_line_index(fix_it.offsets.first.line, fix_it.offsets.first.index); + auto end_iter=buffer->get_iter_at_line_index(fix_it.offsets.second.line, fix_it.offsets.second.index); fix_it_marks.emplace_back(buffer->create_mark(start_iter), buffer->create_mark(end_iter)); } size_t c=0; @@ -809,8 +809,8 @@ void Window::set_menu_actions() { if(!Project::debug_stop.first.empty()) { Notebook::get().open(Project::debug_stop.first); if(auto view=Notebook::get().get_current_view()) { - int line=Project::debug_stop.second.first-1; - int index=Project::debug_stop.second.second-1; + int line=Project::debug_stop.second.first; + int index=Project::debug_stop.second.second; view->place_cursor_at_line_index(line, index); view->scroll_to_cursor_delayed(view, true, true); }