Simplify code for building detailed_name

This commit is contained in:
Jacob Dufault 2017-04-14 22:02:03 -07:00
parent f4e16067b7
commit c946fd1b8e

View File

@ -779,13 +779,9 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
// TODO: Verify this gets called multiple times // TODO: Verify this gets called multiple times
// if (!decl->isRedeclaration) { // if (!decl->isRedeclaration) {
var_def->def.short_name = decl->entityInfo->name; var_def->def.short_name = decl->entityInfo->name;
var_def->def.detailed_name =
ns->QualifiedName(decl->semanticContainer, var_def->def.short_name);
std::string hover = clang::ToString(clang_getTypeSpelling(clang_getCursorType(decl->cursor)));
// Include type in qualified name. std::string type_name = clang::ToString(clang_getTypeSpelling(clang_getCursorType(decl->cursor)));
if (!hover.empty()) var_def->def.detailed_name = type_name + " " + ns->QualifiedName(decl->semanticContainer, var_def->def.short_name);
var_def->def.detailed_name = hover + " " + var_def->def.detailed_name;
//} //}
if (decl->isDefinition) { if (decl->isDefinition) {
@ -886,26 +882,16 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
// this may shadow. // this may shadow.
// if (!decl->isRedeclaration) { // if (!decl->isRedeclaration) {
func_def->def.short_name = decl->entityInfo->name; func_def->def.short_name = decl->entityInfo->name;
func_def->def.detailed_name = ns->QualifiedName(
decl->semanticContainer, func_def->def.short_name); // Build detailed name. The type desc looks like void (void *). We
// insert the qualified name before the first '('.
std::string qualified_name = ns->QualifiedName(decl->semanticContainer, func_def->def.short_name);
std::string type_desc = decl_cursor.get_type_description();
size_t offset = type_desc.find('(');
type_desc.insert(offset, qualified_name);
func_def->def.detailed_name = type_desc;
//} //}
// TODO: we should build this ourselves. It doesn't include parameter names for functions.
std::string hover = decl_cursor.get_type_description();
// Update qualified name to include function signature
// TODO: make this less hideous
auto it = std::find(hover.begin(), hover.end(), '(');
if (it != hover.end()) {
std::string new_qualified_name;
new_qualified_name.resize(hover.size() + func_def->def.detailed_name.size());
std::copy(hover.begin(), it, new_qualified_name.begin());
std::copy(func_def->def.detailed_name.begin(), func_def->def.detailed_name.end(), new_qualified_name.begin() + std::distance(hover.begin(), it));
std::copy(it, hover.end(), new_qualified_name.begin() + std::distance(hover.begin(), it) + func_def->def.detailed_name.size());
func_def->def.detailed_name = new_qualified_name;
}
// TODO: return type // TODO: return type
//decl_cursor.get_type_description() //decl_cursor.get_type_description()
//func_def->def.return_type = //func_def->def.return_type =