diff --git a/src/source.cc b/src/source.cc index 07de736..154232f 100644 --- a/src/source.cc +++ b/src/source.cc @@ -52,22 +52,27 @@ Source::FixIt::FixIt(const std::string &source, const std::pair } } -std::string Source::FixIt::string() { +std::string Source::FixIt::string(Glib::RefPtr buffer) { + auto iter=buffer->get_iter_at_line_index(offsets.first.line-1, offsets.first.index-1); + unsigned first_line_offset=iter.get_line_offset()+1; + iter=buffer->get_iter_at_line_index(offsets.second.line-1, offsets.second.index-1); + 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(offsets.first.offset); + text+=std::to_string(offsets.first.line)+":"+std::to_string(first_line_offset); } else if(type==Type::REPLACE) { text+="Replace "; - text+=std::to_string(offsets.first.line)+":"+std::to_string(offsets.first.offset)+" - "; - text+=std::to_string(offsets.second.line)+":"+std::to_string(offsets.second.offset); + 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+=" with "+source; } else { text+="Erase "; - text+=std::to_string(offsets.first.line)+":"+std::to_string(offsets.first.offset)+" - "; - text+=std::to_string(offsets.second.line)+":"+std::to_string(offsets.second.offset); + 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); } return text; diff --git a/src/source.h b/src/source.h index 340317d..2b60633 100644 --- a/src/source.h +++ b/src/source.h @@ -3,7 +3,6 @@ #include #include #include "gtkmm.h" -#include "clangmm.h" #include #include "gtksourceviewmm.h" #include "terminal.h" @@ -57,25 +56,23 @@ namespace Source { std::string usr; }; - class FixIt { + class Offset { public: - class Offset { - public: - Offset() {} - Offset(unsigned line, unsigned offset): line(line), offset(offset) {} - bool operator==(const Offset &o) {return (line==o.line && offset==o.offset);} - - unsigned line; - unsigned offset; - }; + Offset() {} + Offset(unsigned line, unsigned index): line(line), index(index) {} + bool operator==(const Offset &o) {return (line==o.line && index==o.index);} + unsigned line; + unsigned index; + }; + + class FixIt { + public: enum class Type {INSERT, REPLACE, ERASE}; - FixIt(Type type, const std::string &source, const std::pair &offsets): - type(type), source(source), offsets(offsets) {} FixIt(const std::string &source, const std::pair &offsets); - std::string string(); + std::string string(Glib::RefPtr buffer); Type type; std::string source; @@ -103,7 +100,7 @@ namespace Source { boost::filesystem::path project_path; Glib::RefPtr language; - std::function()> get_declaration_location; + std::function()> get_declaration_location; std::function goto_method; std::function get_token; std::function()> get_token_data; diff --git a/src/source_clang.cc b/src/source_clang.cc index 1b34510..f7ed260 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -303,19 +303,17 @@ void Source::ClangViewParse::update_diagnostics() { 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; + std::pair offsets; offsets.first.line=clang_offsets.first.line; + offsets.first.index=clang_offsets.first.index; offsets.second.line=clang_offsets.second.line; - auto iter=get_buffer()->get_iter_at_line_index(clang_offsets.first.line-1, clang_offsets.first.index-1); - offsets.first.offset=iter.get_line_offset()+1; - iter=get_buffer()->get_iter_at_line_index(clang_offsets.second.line-1, clang_offsets.second.index-1); - offsets.second.offset=iter.get_line_offset()+1; + offsets.second.index=clang_offsets.second.index; fix_its.emplace_back(fix_it.source, offsets); if(fix_its_string.size()>0) fix_its_string+='\n'; - fix_its_string+=fix_its.back().string(); + fix_its_string+=fix_its.back().string(get_buffer()); fix_its_count++; num_fix_its++; } @@ -986,7 +984,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { }); get_declaration_location=[this](){ - std::pair location; + std::pair location; if(source_readable) { auto iter=get_buffer()->get_insert()->get_iter(); auto line=(unsigned)iter.get_line(); @@ -998,7 +996,9 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { auto referenced=cursor.get_referenced(); if(referenced) { location.first=referenced.get_source_location().get_path(); - location.second=referenced.get_source_location().get_offset(); + auto clang_offset=referenced.get_source_location().get_offset(); + location.second.line=clang_offset.line; + location.second.index=clang_offset.index; break; } } @@ -1166,8 +1166,8 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { std::vector, Glib::RefPtr > > fix_it_marks; if(source_readable) { for(auto &fix_it: fix_its) { - auto start_iter=get_buffer()->get_iter_at_line_offset(fix_it.offsets.first.line-1, fix_it.offsets.first.offset-1); - auto end_iter=get_buffer()->get_iter_at_line_offset(fix_it.offsets.second.line-1, fix_it.offsets.second.offset-1); + auto start_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1); + auto end_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1); fix_it_marks.emplace_back(get_buffer()->create_mark(start_iter), get_buffer()->create_mark(end_iter)); } size_t c=0; diff --git a/src/source_clang.h b/src/source_clang.h index 4cfe02a..e029a58 100644 --- a/src/source_clang.h +++ b/src/source_clang.h @@ -6,6 +6,7 @@ #include #include #include +#include "clangmm.h" #include "source.h" namespace Source {