Be less aggressive about indexing potential lambdas

This commit is contained in:
Jacob Dufault 2017-12-12 09:49:52 -08:00
parent 48a7ec73eb
commit 1467526bad

View File

@ -1394,8 +1394,16 @@ 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.
// may not have a short_name yet. Note that we only process the lambda
// parameter as a definition if it is in the same file as the reference,
// as lambdas cannot be split across files.
if (var->def.short_name.empty()) {
CXFile referenced_file;
Range spelling = ResolveSpelling(referenced.cx_cursor, &referenced_file);
if (file == referenced_file) {
var->def.definition_spelling = spelling;
var->def.definition_extent = ResolveExtent(referenced.cx_cursor);
// TODO Some of the logic here duplicates CXIdxEntity_Variable branch of
// OnIndexDeclaration.
// But there `decl` is of type CXIdxDeclInfo and has more information,
@ -1405,14 +1413,13 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
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;
}