Browse Source

Improved C/C++ fixit text

pipelines/235045657
eidheim 6 years ago
parent
commit
35d96b453a
  1. 36
      src/source.cc
  2. 2
      src/source.h
  3. 2
      src/source_clang.cc

36
src/source.cc

@ -98,30 +98,18 @@ Source::FixIt::FixIt(std::string source_, std::pair<Offset, Offset> offsets_) :
} }
} }
std::string Source::FixIt::string(const Glib::RefPtr<Gtk::TextBuffer> &buffer) { std::string Source::FixIt::string(BaseView &view) {
auto iter = buffer->get_iter_at_line_index(offsets.first.line, offsets.first.index); auto pos_str = " at " + std::to_string(offsets.first.line + 1) + ":" + std::to_string(view.get_iter_at_line_index(offsets.first.line, offsets.first.index).get_line_offset() + 1);
unsigned first_line_offset = iter.get_line_offset() + 1;
iter = buffer->get_iter_at_line_index(offsets.second.line, offsets.second.index); if(type == Type::insert)
unsigned second_line_offset = iter.get_line_offset() + 1; return "Insert " + source + pos_str;
else if(type == Type::replace)
std::string text; return "Replace " + view.get_buffer()->get_text(view.get_iter_at_line_index(offsets.first.line, offsets.first.index),
if(type == Type::insert) { view.get_iter_at_line_index(offsets.second.line, offsets.second.index)) +
text += "Insert " + source + " at "; pos_str + " with " + source;
text += std::to_string(offsets.first.line + 1) + ":" + std::to_string(first_line_offset); else
} return "Erase " + view.get_buffer()->get_text(view.get_iter_at_line_index(offsets.first.line, offsets.first.index),
else if(type == Type::replace) { view.get_iter_at_line_index(offsets.second.line, offsets.second.index)) + pos_str;
text += "Replace ";
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 + 1) + ":" + std::to_string(first_line_offset) + " - ";
text += std::to_string(offsets.second.line + 1) + ":" + std::to_string(second_line_offset);
}
return text;
} }
////////////// //////////////

2
src/source.h

@ -45,7 +45,7 @@ namespace Source {
FixIt(std::string source_, std::pair<Offset, Offset> offsets_); FixIt(std::string source_, std::pair<Offset, Offset> offsets_);
std::string string(const Glib::RefPtr<Gtk::TextBuffer> &buffer); std::string string(BaseView &view);
Type type; Type type;
std::string source; std::string source;

2
src/source_clang.cc

@ -337,7 +337,7 @@ void Source::ClangViewParse::update_diagnostics() {
if(fix_its_string.size() > 0) if(fix_its_string.size() > 0)
fix_its_string += '\n'; fix_its_string += '\n';
fix_its_string += fix_its.back().string(get_buffer()); fix_its_string += fix_its.back().string(*this);
fix_its_count++; fix_its_count++;
num_fix_its++; num_fix_its++;
} }

Loading…
Cancel
Save