Strip scope qualifiers of detailed_name in $cquery/memberHierarchy{Initial,Expand}

This commit is contained in:
Fangrui Song 2018-02-25 17:03:24 -08:00
parent bfcab88090
commit dc18f04759
3 changed files with 16 additions and 5 deletions

View File

@ -516,7 +516,7 @@ void SetTypeName(IndexType* type,
// type->def.detailed_name = param->PrettyPrintCursor(cursor.cx_cursor);
type->def.detailed_name =
param->ns.QualifiedName(container ? container : &parent, name);
auto idx = type->def.detailed_name.find(name);
auto idx = type->def.detailed_name.rfind(name);
assert(idx != std::string::npos);
type->def.short_name_offset = idx;
type->def.short_name_size = strlen(name);
@ -631,7 +631,8 @@ void SetVarDetail(IndexVar* var,
#endif
}
// FIXME QualifiedName should return index
auto idx = def.detailed_name.find(short_name.begin(), 0, short_name.size());
auto idx = def.detailed_name.rfind(short_name.begin(), std::string::npos,
short_name.size());
assert(idx != std::string::npos);
def.short_name_offset = idx;
def.short_name_size = short_name.size();

View File

@ -19,6 +19,7 @@
#include <optional.h>
#include <string_view.h>
#include <ctype.h>
#include <algorithm>
#include <cassert>
#include <cstdint>
@ -375,6 +376,15 @@ struct VarDefDefinitionData {
return std::string_view(detailed_name.c_str() + short_name_offset,
short_name_size);
}
std::string DetailedName(bool qualified) const {
if (qualified)
return detailed_name;
int i = short_name_offset;
while (i && (isalnum(detailed_name[i - 1]) || detailed_name[i - 1] == '_' ||
detailed_name[i - 1] == ':'))
i--;
return detailed_name.substr(0, i) + detailed_name.substr(short_name_offset);
}
};
template <typename TVisitor, typename Family>

View File

@ -42,7 +42,7 @@ struct Out_CqueryMemberHierarchy
struct Entry {
QueryTypeId id;
std::string_view name;
std::string_view fieldName;
std::string fieldName;
lsLocation location;
// For unexpanded nodes, this is an upper bound because some entities may be
// undefined. If it is 0, there are no members.
@ -116,9 +116,9 @@ void Expand(MessageHandler* m,
Out_CqueryMemberHierarchy::Entry entry1;
entry1.id = def1->type ? *def1->type : QueryTypeId();
if (detailed_name)
entry1.fieldName = def1->detailed_name;
entry1.fieldName = def1->DetailedName(false);
else
entry1.fieldName = def1->ShortName();
entry1.fieldName = std::string(def1->ShortName());
Expand(m, &entry1, detailed_name, levels - 1);
entry->children.push_back(std::move(entry1));
});