Add missing definition and reference info to lambda paramaters. fix #120

This commit is contained in:
Fangrui Song 2017-12-10 22:36:32 -08:00 committed by Jacob Dufault
parent c6135f5de0
commit fb902a29b7

View File

@ -1388,6 +1388,26 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
IndexVarId var_id = db->ToVarId(referenced.get_usr());
IndexVar* var = db->Resolve(var_id);
// Lambda paramaters are not processed by OnIndexDeclaration and
// may not have a short_name yet.
if (var->def.short_name.empty()) {
// TODO Some of the logic here duplicates CXIdxEntity_Variable branch of
// OnIndexDeclaration.
// But there `decl` is of type CXIdxDeclInfo and has more information,
// thus not easy to reuse the code.
var->def.short_name = referenced.get_spelling();
std::string type_name =
ToString(clang_getTypeSpelling(clang_getCursorType(referenced.cx_cursor)));
var->def.detailed_name = type_name + " " + var->def.short_name;
var->def.is_local = false;
var->def.definition_spelling = ResolveSpelling(referenced.cx_cursor);
var->def.definition_extent = ResolveSpelling(referenced.cx_cursor);
UniqueAdd(var->uses, ResolveSpelling(referenced.cx_cursor));
AddDeclInitializerUsages(db, referenced.cx_cursor);
// TODO Use proper semantic_container and lexical_container.
AddDeclTypeUsages(db, referenced.cx_cursor, nullptr, nullptr);
// TODO Other logic in OnIndexDeclaration may need to be adapted.
}
UniqueAdd(var->uses, loc_spelling);
break;
}