Browse Source

Improvements in removal of internal namespaces in types shown in tooltips

pipelines/235045657
eidheim 5 years ago
parent
commit
bb3e669445
  1. 29
      src/source_clang.cpp
  2. 3
      src/source_clang.hpp

29
src/source_clang.cpp

@ -512,13 +512,10 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
type_tooltips.emplace_back(this, start, end, [this, token](Tooltip &tooltip) {
auto cursor = token.get_cursor();
auto type_description = cursor.get_type_description();
remove_internal_namespaces(type_description);
size_t pos = 0;
// Remove ::_1 from type description
while((pos = type_description.find("::__1", pos)) != std::string::npos)
type_description.erase(pos, 5);
pos = 0;
// Simplify std::basic_string types
while((pos = type_description.find("std::basic_string<char"), pos) != std::string::npos) {
while((pos = type_description.find("std::basic_string<char", pos)) != std::string::npos) {
pos += 22;
if(pos < type_description.size()) {
if(type_description[pos] == '>') {
@ -721,10 +718,8 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
debug_value.replace(iter, next_char_iter, "?");
}
tooltip.buffer->insert(tooltip.buffer->get_insert()->get_iter(), (tooltip.buffer->size() > 0 ? "\n\n" : "") + value_type + ":\n");
auto value = debug_value.substr(pos + 3, debug_value.size() - (pos + 3) - 1);
size_t pos = 0;
while((pos = value.find("::__1", pos)) != std::string::npos)
value.erase(pos, 5);
auto value = debug_value.substr(pos + 3, debug_value.size() - (pos + 3) - 1).raw();
remove_internal_namespaces(value);
tooltip.insert_code(value);
}
}
@ -740,6 +735,22 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
}
}
void Source::ClangViewParse::remove_internal_namespaces(std::string &type) {
size_t pos = 0;
while((pos = type.find("::__", pos)) != std::string::npos) {
if(starts_with(type, pos + 4, "1::"))
type.erase(pos, 5);
else if(starts_with(type, pos + 4, "cxx")) {
auto end_pos = type.find("::", pos + 7);
if(end_pos == std::string::npos)
break;
type.erase(pos, end_pos - pos);
}
else
pos += 4;
}
}
Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language)
: BaseView(file_path, language), Source::ClangViewParse(file_path, language), autocomplete(this, interactive_completion, last_keyval, true) {

3
src/source_clang.hpp

@ -52,6 +52,9 @@ namespace Source {
void update_diagnostics() REQUIRES(parse_mutex);
std::vector<clangmm::Diagnostic> clang_diagnostics GUARDED_BY(parse_mutex);
/// Removes for instance ::__1:: and ::__cxx11:: from type
void remove_internal_namespaces(std::string &type);
};
class ClangViewAutocomplete : public virtual ClangViewParse {

Loading…
Cancel
Save